From 9f6a62a2b53edb74c53d64a754daf54b6ae91275 Mon Sep 17 00:00:00 2001 From: Gustavo Ciria Date: Wed, 11 Sep 2024 13:59:37 -0300 Subject: [PATCH] feat(helm): Add ServiceMonitor (#695) # Description Adding support for `ServiceMonitor`. ## Checklist - [x] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [x] I have tested the changes locally. - [x] I have followed the project's style guidelines. - [x] I have updated the documentation, if necessary. ## Screenshots (if applicable) or Testing Completed ![image (2)](https://github.com/user-attachments/assets/f377b3b0-c41f-48ce-8e1f-0eef562ecd73) ![image (1)](https://github.com/user-attachments/assets/c11a6aa0-e897-43a3-b29c-2c2625554fb0) --- .../helm/retina/templates/podmonitor.yaml | 2 +- .../helm/retina/templates/servicemonitor.yaml | 45 +++++++++++++++++++ .../controller/helm/retina/values.yaml | 36 ++++++++++++++- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 deploy/legacy/manifests/controller/helm/retina/templates/servicemonitor.yaml diff --git a/deploy/legacy/manifests/controller/helm/retina/templates/podmonitor.yaml b/deploy/legacy/manifests/controller/helm/retina/templates/podmonitor.yaml index eb5992febe..f84a576e15 100644 --- a/deploy/legacy/manifests/controller/helm/retina/templates/podmonitor.yaml +++ b/deploy/legacy/manifests/controller/helm/retina/templates/podmonitor.yaml @@ -1,4 +1,4 @@ -{{- if .Values.metrics.podMonitor.enabled }} +{{- if and (not .Values.metrics.serviceMonitor.enabled) .Values.metrics.podMonitor.enabled }} apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: diff --git a/deploy/legacy/manifests/controller/helm/retina/templates/servicemonitor.yaml b/deploy/legacy/manifests/controller/helm/retina/templates/servicemonitor.yaml new file mode 100644 index 0000000000..18545802b7 --- /dev/null +++ b/deploy/legacy/manifests/controller/helm/retina/templates/servicemonitor.yaml @@ -0,0 +1,45 @@ +{{- if and (not .Values.metrics.podMonitor.enabled) .Values.metrics.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "retina.fullname" . }} + namespace: {{ ternary .Values.metrics.serviceMonitor.namespace .Values.namespace (not (empty .Values.metrics.serviceMonitor.namespace)) }} + labels: + k8s-app: {{ include "retina.name" . }} + {{- include "retina.labels" . | nindent 4 }} + app.kubernetes.io/component: metrics + {{- if .Values.metrics.serviceMonitor.additionalLabels }} + {{- toYaml .Values.metrics.serviceMonitor.additionalLabels | nindent 4 }} + {{- end }} +spec: + endpoints: + - targetPort: retina + path: /metrics + {{- if .Values.metrics.serviceMonitor.interval }} + interval: {{ .Values.metrics.serviceMonitor.interval }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.scheme }} + scheme: {{ .Values.metrics.serviceMonitor.scheme }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.tlsConfig }} + tlsConfig: {{- .Values.metrics.serviceMonitor.tlsConfig | nindent 8 }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.relabelings }} + relabelings: + {{- toYaml .Values.metrics.serviceMonitor.relabelings | nindent 8 }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml .Values.metrics.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Values.namespace }} + selector: + matchLabels: + {{- include "retina.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: networking +{{- end }} diff --git a/deploy/legacy/manifests/controller/helm/retina/values.yaml b/deploy/legacy/manifests/controller/helm/retina/values.yaml index 4dd1c1734b..a03ada6a73 100644 --- a/deploy/legacy/manifests/controller/helm/retina/values.yaml +++ b/deploy/legacy/manifests/controller/helm/retina/values.yaml @@ -191,4 +191,38 @@ metrics: ## @param metrics.podMonitor.relabelings [array] Prometheus relabeling rules ## relabelings: [] - + serviceMonitor: + ## @param metrics.serviceMonitor.enabled Create serviceMonitor Resource for scraping metrics using PrometheusOperator + ## + enabled: false + ## @param metrics.serviceMonitor.namespace Namespace in which the serviceMonitor should be created + ## + namespace: ~ + ## @param metrics.serviceMonitor.interval Specify the interval at which metrics should be scraped + ## + interval: 30s + ## @param metrics.serviceMonitor.scrapeTimeout Specify the timeout after which the scrape is ended + ## + scrapeTimeout: 30s + ## @param metrics.serviceMonitor.additionalLabels [object] Additional labels that can be used so serviceMonitor will be discovered by Prometheus + ## ref: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#prometheusspec + ## + additionalLabels: {} + ## @param metrics.serviceMonitor.scheme Scheme to use for scraping + ## + scheme: http + ## @param metrics.serviceMonitor.tlsConfig [object] TLS configuration used for scrape endpoints used by Prometheus + ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#tlsconfig + ## e.g: + ## tlsConfig: + ## ca: + ## secret: + ## name: existingSecretName + ## + tlsConfig: {} + ## @param metrics.serviceMonitor.relabelings [array] Prometheus relabeling rules to apply to samples before scraping + ## + relabelings: [] + ## @param metrics.serviceMonitor.metricRelabelings [array] Prometheus relabeling rules to apply to samples before ingestion + ## + metricRelabelings: [] \ No newline at end of file