From 77ea1ad3a2d97efe7e3790f401834ae23c48aba7 Mon Sep 17 00:00:00 2001 From: Ilia Lazebnik Date: Tue, 20 Feb 2024 23:14:26 +0200 Subject: [PATCH] [prometheus-elasticsearch-exporter] add support for podmonitor (#4264) * [prometheus-elasticsearch-exporter] Add PodMonitor support Signed-off-by: ShlomiTubul * [prometheus-elasticsearch-exporter] revert deafult values,bump version Signed-off-by: ShlomiTubul * add support for podmomitor Signed-off-by: drfaust92 * add support for podmomitor Signed-off-by: drfaust92 * add support for podmomitor Signed-off-by: drfaust92 * Update charts/prometheus-elasticsearch-exporter/templates/podmonitor.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Ilia Lazebnik * Update charts/prometheus-elasticsearch-exporter/values.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Ilia Lazebnik * Update charts/prometheus-elasticsearch-exporter/templates/podmonitor.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Ilia Lazebnik * Update charts/prometheus-elasticsearch-exporter/values.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Ilia Lazebnik * Update charts/prometheus-elasticsearch-exporter/values.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Ilia Lazebnik * CR comments Signed-off-by: drfaust92 * remove job label Signed-off-by: drfaust92 * Update charts/prometheus-elasticsearch-exporter/values.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Ilia Lazebnik --------- Signed-off-by: ShlomiTubul Signed-off-by: drfaust92 Signed-off-by: Ilia Lazebnik Co-authored-by: ShlomiTubul Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> --- .../Chart.yaml | 2 +- .../templates/podmonitor.yaml | 50 +++++++++++++++++++ .../templates/service.yaml | 2 + .../values.yaml | 17 +++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 charts/prometheus-elasticsearch-exporter/templates/podmonitor.yaml diff --git a/charts/prometheus-elasticsearch-exporter/Chart.yaml b/charts/prometheus-elasticsearch-exporter/Chart.yaml index ab28150b3b9a..daf6a25fb784 100644 --- a/charts/prometheus-elasticsearch-exporter/Chart.yaml +++ b/charts/prometheus-elasticsearch-exporter/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: Elasticsearch stats exporter for Prometheus name: prometheus-elasticsearch-exporter -version: 5.5.0 +version: 5.6.0 kubeVersion: ">=1.10.0-0" appVersion: "v1.7.0" home: https://github.com/prometheus-community/elasticsearch_exporter diff --git a/charts/prometheus-elasticsearch-exporter/templates/podmonitor.yaml b/charts/prometheus-elasticsearch-exporter/templates/podmonitor.yaml new file mode 100644 index 000000000000..fe4fb30cc615 --- /dev/null +++ b/charts/prometheus-elasticsearch-exporter/templates/podmonitor.yaml @@ -0,0 +1,50 @@ +{{- if and .Values.podMonitor.enabled .Values.serviceMonitor.enabled }} +{{- fail "Either .Values.podMonitor.enabled or .Values.serviceMonitor.enabled can be enabled at a time, but not both." }} +{{- else if .Values.podMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ template "elasticsearch-exporter.fullname" . }} + {{- if .Values.podMonitor.namespace }} + namespace: {{ .Values.podMonitor.namespace }} + {{- end }} + labels: + chart: {{ template "elasticsearch-exporter.chart" . }} + app: {{ template "elasticsearch-exporter.name" . }} + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + {{- if .Values.podMonitor.labels }} + {{- toYaml .Values.podMonitor.labels | nindent 4 }} + {{- end }} +spec: + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + podMetricsEndpoints: + - path: {{ .Values.web.path }} + port: {{ .Values.deployment.metricsPort.name }} + {{- if .Values.podMonitor.scheme }} + scheme: {{ .Values.podMonitor.scheme }} + {{- end }} + {{- if .Values.podMonitor.interval }} + interval: {{ .Values.podMonitor.interval }} + {{- end }} + {{- if .Values.podMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.podMonitor.scrapeTimeout }} + {{- end }} + {{- if .Values.podMonitor.honorLabels }} + honorLabels: true + {{- end }} + {{- if .Values.podMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml .Values.podMonitor.metricRelabelings | nindent 6 }} + {{- end }} + {{- if .Values.podMonitor.relabelings }} + relabelings: + {{- toYaml .Values.podMonitor.relabelings | nindent 6 }} + {{- end }} + selector: + matchLabels: + app: {{ template "elasticsearch-exporter.name" . }} + release: "{{ .Release.Name }}" +{{- end }} diff --git a/charts/prometheus-elasticsearch-exporter/templates/service.yaml b/charts/prometheus-elasticsearch-exporter/templates/service.yaml index d268ca5748d9..a3420a999392 100644 --- a/charts/prometheus-elasticsearch-exporter/templates/service.yaml +++ b/charts/prometheus-elasticsearch-exporter/templates/service.yaml @@ -1,3 +1,4 @@ +{{- if .Values.service.enabled }} kind: Service apiVersion: v1 metadata: @@ -23,3 +24,4 @@ spec: selector: app: {{ template "elasticsearch-exporter.name" . }} release: "{{ .Release.Name }}" +{{- end }} diff --git a/charts/prometheus-elasticsearch-exporter/values.yaml b/charts/prometheus-elasticsearch-exporter/values.yaml index f70dd9079180..456731379f4e 100644 --- a/charts/prometheus-elasticsearch-exporter/values.yaml +++ b/charts/prometheus-elasticsearch-exporter/values.yaml @@ -71,6 +71,7 @@ affinity: {} initContainers: [] service: + enabled: true type: ClusterIP httpPort: 9108 metricsPort: @@ -81,6 +82,8 @@ service: deployment: annotations: {} labels: {} + metricsPort: + name: http ## Extra environment variables that will be passed into the exporter pod ## example: @@ -250,6 +253,20 @@ serviceMonitor: metricRelabelings: [] sampleLimit: 0 +podMonitor: + ## If true, a PodMonitor CRD is created for a Prometheus Operator + ## https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.PodMonitor + ## + enabled: false + namespace: "" + labels: {} + interval: 60s + scrapeTimeout: 10s + honorLabels: true + scheme: http + relabelings: [] + metricRelabelings: [] + prometheusRule: ## If true, a PrometheusRule CRD is created for a prometheus operator ## https://github.com/coreos/prometheus-operator