From 1701980affc75e4fb3770f64ce56263b1b719f72 Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Mon, 9 Oct 2023 12:52:42 +0100 Subject: [PATCH] fix(monitoring): add and fix definitions for service monitors --- charts/deep-distributed/Chart.yaml | 2 +- charts/deep-distributed/templates/NOTES.txt | 2 +- .../deep-distributed/templates/_helpers.tpl | 7 ++ .../templates/lib/service-monitor.yaml | 4 +- charts/deep-distributed/values.yaml | 7 +- charts/deep/Chart.yaml | 2 +- charts/deep/templates/_helpers.tpl | 8 +++ charts/deep/templates/serviceMonitor.yaml | 64 +++++++++++++++++++ charts/deep/values.yaml | 30 +++++++++ 9 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 charts/deep/templates/serviceMonitor.yaml diff --git a/charts/deep-distributed/Chart.yaml b/charts/deep-distributed/Chart.yaml index 5d13236..a24f65b 100644 --- a/charts/deep-distributed/Chart.yaml +++ b/charts/deep-distributed/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.12 +version: 0.0.13 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/deep-distributed/templates/NOTES.txt b/charts/deep-distributed/templates/NOTES.txt index 28a6f08..878bf38 100644 --- a/charts/deep-distributed/templates/NOTES.txt +++ b/charts/deep-distributed/templates/NOTES.txt @@ -13,5 +13,5 @@ Installed components: * query-frontend ({{.Values.queryFrontend.replicas}}) * compactor ({{.Values.compactor.replicas}}) {{- if .Values.gateway.enabled}} -* gateway -{{- if .Values.gateway.traefik.enabled}} {{- .Values.gateway.traefik.host}} {{- end}} {{- if .Values.gateway.ingress.enabled}}{{- with (index .Values.gateway.ingress.hosts 0)}}{{ .host}}{{- end}}{{- end}} ({{.Values.gateway.replicas}}) +* gateway {{- if .Values.gateway.traefik.enabled}} {{- .Values.gateway.traefik.host}} {{- end}} {{- if .Values.gateway.ingress.enabled}}{{- with (index .Values.gateway.ingress.hosts 0)}}{{ .host}}{{- end}}{{- end}} ({{.Values.gateway.replicas}}) {{- end}} \ No newline at end of file diff --git a/charts/deep-distributed/templates/_helpers.tpl b/charts/deep-distributed/templates/_helpers.tpl index dbf7be2..2fabfd3 100644 --- a/charts/deep-distributed/templates/_helpers.tpl +++ b/charts/deep-distributed/templates/_helpers.tpl @@ -203,3 +203,10 @@ Return the appropriate apiVersion for PodDisruptionBudget. {{- print "policy/v1beta1" -}} {{- end -}} {{- end -}} + +{{/* +Cluster name that shows up in dashboard metrics +*/}} +{{- define "deep.clusterName" -}} +{{ (include "deep.calculatedConfig" . | fromYaml).cluster_name | default .Release.Name }} +{{- end -}} \ No newline at end of file diff --git a/charts/deep-distributed/templates/lib/service-monitor.yaml b/charts/deep-distributed/templates/lib/service-monitor.yaml index 6c96d3d..f92aebe 100644 --- a/charts/deep-distributed/templates/lib/service-monitor.yaml +++ b/charts/deep-distributed/templates/lib/service-monitor.yaml @@ -6,8 +6,8 @@ Params: memberlist = true/false, whether component is part of memberlist */}} {{- define "deep.lib.serviceMonitor" -}} -{{- with .ctx.Values.metaMonitoring.serviceMonitor }} -{{- if .enabled }} +{{- if .ctx.Values.monitoring.enabled }} +{{- with .ctx.Values.monitoring.serviceMonitor }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: diff --git a/charts/deep-distributed/values.yaml b/charts/deep-distributed/values.yaml index 12e8001..57f1926 100644 --- a/charts/deep-distributed/values.yaml +++ b/charts/deep-distributed/values.yaml @@ -961,11 +961,12 @@ serviceAccount: # -- Annotations for the service account annotations: {} -metaMonitoring: +## This config controls the deployment of Pod/Service Monitors to connect Deep to Prometheus for metric gathering +monitoring: + # Is monitoring active, set to true to deploy the service monitor + enabled: false # ServiceMonitor configuration serviceMonitor: - # -- If enabled, ServiceMonitor resources for Prometheus Operator are created - enabled: false # -- Alternative namespace for ServiceMonitor resources namespace: null # -- Namespace selector for ServiceMonitor resources diff --git a/charts/deep/Chart.yaml b/charts/deep/Chart.yaml index 670fee1..8cac7bf 100644 --- a/charts/deep/Chart.yaml +++ b/charts/deep/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.0.1 +version: 1.0.2 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/deep/templates/_helpers.tpl b/charts/deep/templates/_helpers.tpl index 0793f4a..5503711 100644 --- a/charts/deep/templates/_helpers.tpl +++ b/charts/deep/templates/_helpers.tpl @@ -147,3 +147,11 @@ Return if ingress supports pathType. {{- define "deep.ingress.supportsPathType" -}} {{- or (eq (include "deep.ingress.isStable" .) "true") (and (eq (include "deep.ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18-0" .Capabilities.KubeVersion.Version)) }} {{- end }} + + +{{/* +Cluster name that shows up in dashboard metrics +*/}} +{{- define "deep.clusterName" -}} +{{ (include "deep.calculatedConfig" . | fromYaml).cluster_name | default .Release.Name }} +{{- end -}} \ No newline at end of file diff --git a/charts/deep/templates/serviceMonitor.yaml b/charts/deep/templates/serviceMonitor.yaml new file mode 100644 index 0000000..609e4cb --- /dev/null +++ b/charts/deep/templates/serviceMonitor.yaml @@ -0,0 +1,64 @@ +{{- if .Values.monitoring.enabled }} +{{- with .Values.monitoring.serviceMonitor }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "deep.fullname" $ }} + namespace: {{ .namespace | default $.Release.Namespace | quote }} + labels: + {{- include "deep.labels" (dict "ctx" $) | nindent 4 }} + {{- with .labels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + namespaceSelector: + {{- if .namespaceSelector }} + {{- toYaml .namespaceSelector | nindent 4 }} + {{- else }} + matchNames: + - {{ $.Release.Namespace }} + {{- end }} + selector: + matchLabels: + {{- include "deep.selectorLabels" (dict "ctx" $) | nindent 6 }} + matchExpressions: + - key: prometheus.io/service-monitor + operator: NotIn + values: + - "false" + endpoints: + - port: api + {{- with .interval }} + interval: {{ . }} + {{- end }} + {{- with .scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + relabelings: + - sourceLabels: [job] + replacement: "{{ include "deep.fullname" $ }}" + targetLabel: job + {{- if kindIs "string" .clusterLabel }} + - replacement: "{{ .clusterLabel | default (include "deep.clusterName" $) }}" + targetLabel: cluster + {{- end }} + {{- with .relabelings }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .scheme }} + scheme: {{ . }} + {{- end }} + {{- with .tlsConfig }} + tlsConfig: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end -}} +{{- end -}} diff --git a/charts/deep/values.yaml b/charts/deep/values.yaml index b51b028..01381b5 100644 --- a/charts/deep/values.yaml +++ b/charts/deep/values.yaml @@ -404,3 +404,33 @@ serviceAccount: # -- Labels for the service account labels: {} automountServiceAccountToken: true + + +## This config controls the deployment of Pod/Service Monitors to connect Deep to Prometheus for metric gathering +monitoring: + # Is monitoring active, set to true to deploy the service monitor + enabled: false + # The config for the service monitor + serviceMonitor: + # the name space to deploy the service monitor in + namespace: null + # additional labels to add to the service monitor + labels: {} + # additional annotations to add to the service monitor + annotations: {} + # the name space selector to use in the service monitor + namespaceSelector: {} + # the scape timeout + scrapeTimeout: null + # the scape interval + interval: null + # -- ServiceMonitor relabel configs to apply to samples before scraping + # https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#relabelconfig + relabelings: [] + # -- ServiceMonitor metric relabel configs to apply to samples before ingestion + # https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#endpoint + metricRelabelings: [] + # -- ServiceMonitor will use http by default, but you can pick https as well + scheme: http + # -- ServiceMonitor will use these tlsConfig settings to make the health check requests + tlsConfig: null