From 5dae4b1fe96b94a1c9d26411087ee1920ca9a7ac Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Sun, 3 Nov 2024 14:16:35 +0200 Subject: [PATCH] helm: allow autodiscovery by prometheus. Allow autodiscovery of prometheus metrics by annotation. IOW, annotate our plugins' pods according to the Helm `config.instrumentation.{prometheusExport,httpEndpoint}` values. Since we're adding annotations to our plugins' pods, add support for injecting custom annotations using the Helm `plugin.annotations` value. Signed-off-by: Krisztian Litkey --- deployment/helm/balloons/README.md | 1 + deployment/helm/balloons/templates/daemonset.yaml | 8 ++++++++ deployment/helm/balloons/values.yaml | 5 +++++ deployment/helm/template/README.md | 1 + deployment/helm/template/templates/daemonset.yaml | 8 ++++++++ deployment/helm/template/values.yaml | 5 +++++ deployment/helm/topology-aware/README.md | 1 + deployment/helm/topology-aware/templates/daemonset.yaml | 8 ++++++++ deployment/helm/topology-aware/values.yaml | 5 +++++ 9 files changed, 42 insertions(+) diff --git a/deployment/helm/balloons/README.md b/deployment/helm/balloons/README.md index bd23ca88e..95fb5b1e2 100644 --- a/deployment/helm/balloons/README.md +++ b/deployment/helm/balloons/README.md @@ -106,6 +106,7 @@ customize with their own values, along with the default values. | `nri.runtime.config.pluginRequestTimeout` | "" | set NRI plugin request timeout in NRI config of containerd or CRI-O | | `nri.runtime.patchConfig` | false | patch NRI configuration in containerd or CRI-O | | `nri.plugin.index` | 90 | NRI plugin index to register with +| `nri.plugin.annotations` | {} | extra annotations for the plugin's pod | | `initImage.name` | [ghcr.io/containers/nri-plugins/config-manager](https://ghcr.io/containers/nri-plugins/config-manager) | init container image name | | `initImage.tag` | unstable | init container image tag | | `initImage.pullPolicy` | Always | init container image pull policy | diff --git a/deployment/helm/balloons/templates/daemonset.yaml b/deployment/helm/balloons/templates/daemonset.yaml index 567aac344..fb4fdff34 100644 --- a/deployment/helm/balloons/templates/daemonset.yaml +++ b/deployment/helm/balloons/templates/daemonset.yaml @@ -13,6 +13,14 @@ spec: metadata: labels: {{- include "nri-plugin.labels" . | nindent 8 }} + annotations: + prometheus.io/scrape: "true" + {{- if (ne .Values.config.instrumentation.httpEndpoint "") }} + prometheus.io/port: "{{ regexReplaceAll "[^:]*:([0-9][0-9]*)" .Values.config.instrumentation.httpEndpoint "${1}" }}" + {{- end }} + {{- range $name, $value := .Values.nri.plugin.annotations }} + {{ $name }}: "{{ $value }}" + {{- end }} spec: {{- with .Values.tolerations }} tolerations: diff --git a/deployment/helm/balloons/values.yaml b/deployment/helm/balloons/values.yaml index 1d74dd2bf..54465b3f8 100644 --- a/deployment/helm/balloons/values.yaml +++ b/deployment/helm/balloons/values.yaml @@ -41,6 +41,8 @@ config: log: source: true instrumentation: + httpEndpoint: ":8891" + prometheusExport: false reportPeriod: 60s samplingRatePerMillion: 0 @@ -63,6 +65,9 @@ resources: nri: plugin: index: 90 + annotations: +# key1: value1 +# key2: value2 runtime: patchConfig: false # config: diff --git a/deployment/helm/template/README.md b/deployment/helm/template/README.md index 8f46b1088..a70ab04ac 100644 --- a/deployment/helm/template/README.md +++ b/deployment/helm/template/README.md @@ -106,6 +106,7 @@ customize with their own values, along with the default values. | `nri.runtime.config.pluginRequestTimeout` | "" | set NRI plugin request timeout in NRI config of containerd or CRI-O | | `nri.runtime.patchConfig` | false | patch NRI configuration in containerd or CRI-O | | `nri.plugin.index` | 90 | NRI plugin index to register with +| `nri.plugin.annotations` | {} | extra annotations for the plugin's pod | | `initImage.name` | [ghcr.io/containers/nri-plugins/config-manager](https://ghcr.io/containers/nri-plugins/config-manager) | init container image name | | `initImage.tag` | unstable | init container image tag | | `initImage.pullPolicy` | Always | init container image pull policy | diff --git a/deployment/helm/template/templates/daemonset.yaml b/deployment/helm/template/templates/daemonset.yaml index c7338ec06..3d8a6d628 100644 --- a/deployment/helm/template/templates/daemonset.yaml +++ b/deployment/helm/template/templates/daemonset.yaml @@ -13,6 +13,14 @@ spec: metadata: labels: {{- include "nri-plugin.labels" . | nindent 8 }} + annotations: + prometheus.io/scrape: "true" + {{- if (ne .Values.config.instrumentation.httpEndpoint "") }} + prometheus.io/port: "{{ regexReplaceAll "[^:]*:([0-9][0-9]*)" .Values.config.instrumentation.httpEndpoint "${1}" }}" + {{- end }} + {{- range $name, $value := .Values.nri.plugin.annotations }} + {{ $name }}: "{{ $value }}" + {{- end }} spec: {{- with .Values.tolerations }} tolerations: diff --git a/deployment/helm/template/values.yaml b/deployment/helm/template/values.yaml index 57326312b..321d46a5e 100644 --- a/deployment/helm/template/values.yaml +++ b/deployment/helm/template/values.yaml @@ -16,6 +16,8 @@ config: klog: skip_headers: true instrumentation: + httpEndpoint: ":8891" + prometheusExport: false reportPeriod: 60s samplingRatePerMillion: 0 @@ -38,6 +40,9 @@ resources: nri: plugin: index: 90 + annotations: +# key1: value1 +# key2: value2 runtime: patchConfig: false # config: diff --git a/deployment/helm/topology-aware/README.md b/deployment/helm/topology-aware/README.md index 6999188fa..41df43705 100644 --- a/deployment/helm/topology-aware/README.md +++ b/deployment/helm/topology-aware/README.md @@ -107,6 +107,7 @@ customize with their own values, along with the default values. | `nri.runtime.config.pluginRequestTimeout` | "" | set NRI plugin request timeout in NRI config of containerd or CRI-O | | `nri.runtime.patchConfig` | false | patch NRI configuration in containerd or CRI-O | | `nri.plugin.index` | 90 | NRI plugin index to register with | +| `nri.plugin.annotations` | {} | extra annotations for the plugin's pod | | `initImage.name` | [ghcr.io/containers/nri-plugins/config-manager](https://ghcr.io/containers/nri-plugins/config-manager) | init container image name | | `initImage.tag` | unstable | init container image tag | | `initImage.pullPolicy` | Always | init container image pull policy | diff --git a/deployment/helm/topology-aware/templates/daemonset.yaml b/deployment/helm/topology-aware/templates/daemonset.yaml index 480587d97..b012026b8 100644 --- a/deployment/helm/topology-aware/templates/daemonset.yaml +++ b/deployment/helm/topology-aware/templates/daemonset.yaml @@ -13,6 +13,14 @@ spec: metadata: labels: {{- include "nri-plugin.labels" . | nindent 8 }} + annotations: + prometheus.io/scrape: "true" + {{- if (ne .Values.config.instrumentation.httpEndpoint "") }} + prometheus.io/port: "{{ regexReplaceAll "[^:]*:([0-9][0-9]*)" .Values.config.instrumentation.httpEndpoint "${1}" }}" + {{- end }} + {{- range $name, $value := .Values.nri.plugin.annotations }} + {{ $name }}: "{{ $value }}" + {{- end }} spec: {{- with .Values.tolerations }} tolerations: diff --git a/deployment/helm/topology-aware/values.yaml b/deployment/helm/topology-aware/values.yaml index 1df3d8775..751d28698 100644 --- a/deployment/helm/topology-aware/values.yaml +++ b/deployment/helm/topology-aware/values.yaml @@ -16,6 +16,8 @@ config: klog: skip_headers: true instrumentation: + httpEndpoint: ":8891" + prometheusExport: false reportPeriod: 60s samplingRatePerMillion: 0 @@ -38,6 +40,9 @@ resources: nri: plugin: index: 90 + annotations: +# key1: value1 +# key2: value2 runtime: patchConfig: false # config: