From bd381e9c81f48278cee6f9188ba14df4f220a8dc Mon Sep 17 00:00:00 2001 From: Nicolas Trangosi Date: Tue, 25 Apr 2023 15:42:35 +0200 Subject: [PATCH 1/4] feat: Add extra labels on serviceMonitor + allow toleration configuration on helm chart Signed-off-by: Nicolas Trangosi --- docs_src/tutorials/kubernetes.md | 16 +++++++++++----- helm/scaphandre/Chart.yaml | 2 +- helm/scaphandre/templates/daemonset.yaml | 5 +++-- helm/scaphandre/templates/servicemonitor.yaml | 5 ++++- helm/scaphandre/values.yaml | 7 +++++++ 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docs_src/tutorials/kubernetes.md b/docs_src/tutorials/kubernetes.md index e82524ee..d8f68cce 100644 --- a/docs_src/tutorials/kubernetes.md +++ b/docs_src/tutorials/kubernetes.md @@ -15,11 +15,17 @@ to be installed from the source code. ### Parameters #### Service monitor parameters -| Name | Description | Value | -| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------- | ------------------------- | -| `serviceMonitor.enabled` | Create ServiceMonitor Resource for scraping metrics using PrometheusOperator | `false` | -| `serviceMonitor.namespace` | The namespace in which the ServiceMonitor will be created (if not set, default to namespace on which this chart is installed) | `""` | -| `serviceMonitor.interval` | The interval at which metrics should be scraped | `1m` | +| Name | Description | Value | +| ------------------------- | ----------------------------------------------------------------------------------------------| ------------------------- | +| `serviceMonitor.enabled` | Create ServiceMonitor Resource for scraping metrics using PrometheusOperator | `false` | +| `serviceMonitor.namespace`| The namespace in which the ServiceMonitor will be created (if not set, default to namespace on which this chart is installed) | `""` | +| `serviceMonitor.interval` | The interval at which metrics should be scraped | `1m` | +| `serviceMonitor.labels` | Extra labels for the ServiceMonitor | `{}` | + +#### Other parameters +| Name | Description | Value | +| ------------------------------------------ | ----------------------------------------------------------------------------| ------------------------- | +| `tolerations` | Tolerations for pod assignment. Evaluated as a template. | `- operator: "Exists"` | ## Install Prometheus diff --git a/helm/scaphandre/Chart.yaml b/helm/scaphandre/Chart.yaml index f2d60316..9792e237 100644 --- a/helm/scaphandre/Chart.yaml +++ b/helm/scaphandre/Chart.yaml @@ -3,4 +3,4 @@ appVersion: 0.1.1 description: A Helm chart for Scaphandre electrical power consumption agent home: https://github.com/hubblo-org/scaphandre name: scaphandre -version: 0.1.0 +version: 0.1.1 diff --git a/helm/scaphandre/templates/daemonset.yaml b/helm/scaphandre/templates/daemonset.yaml index f51767f4..64839f6e 100644 --- a/helm/scaphandre/templates/daemonset.yaml +++ b/helm/scaphandre/templates/daemonset.yaml @@ -56,9 +56,10 @@ spec: runAsUser: {{ .Values.userID }} runAsGroup: {{ .Values.userGroup }} serviceAccountName: {{ template "scaphandre.name" . }} + {{- with .Values.tolerations }} tolerations: - # Tolerate all taints for observability - - operator: "Exists" + {{- toYaml . | nindent 8 }} + {{- end }} volumes: - hostPath: path: /proc diff --git a/helm/scaphandre/templates/servicemonitor.yaml b/helm/scaphandre/templates/servicemonitor.yaml index 3d343f71..5aae3d11 100644 --- a/helm/scaphandre/templates/servicemonitor.yaml +++ b/helm/scaphandre/templates/servicemonitor.yaml @@ -9,7 +9,10 @@ metadata: namespace: {{ .Release.Namespace }} {{- end }} labels: - app.kubernetes.io/name: {{ template "scaphandre.name" . }} + {{- include "labels.common" . | nindent 4 }} + {{- if .Values.serviceMonitor.labels }} + {{- toYaml .Values.serviceMonitor.labels | nindent 4 }} + {{- end }} spec: endpoints: - path: /metrics diff --git a/helm/scaphandre/values.yaml b/helm/scaphandre/values.yaml index 60f47c80..e89d08bf 100644 --- a/helm/scaphandre/values.yaml +++ b/helm/scaphandre/values.yaml @@ -28,3 +28,10 @@ serviceMonitor: interval: 1m # Specifies namespace, where ServiceMonitor should be installed # namespace: monitoring + + # Extra labels for the ServiceMonitor + labels: {} + +tolerations: + # Tolerate all taints for observability + - operator: "Exists" \ No newline at end of file From d8703b942e54f6200ca785118c5acf6d3fead712 Mon Sep 17 00:00:00 2001 From: Nicolas Trangosi Date: Wed, 26 Apr 2023 10:51:59 +0200 Subject: [PATCH 2/4] Allow configuration of scrapeTimeout in serviceMonitor --- docs_src/tutorials/kubernetes.md | 13 +++++++------ helm/scaphandre/templates/servicemonitor.yaml | 2 +- helm/scaphandre/values.yaml | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs_src/tutorials/kubernetes.md b/docs_src/tutorials/kubernetes.md index d8f68cce..f41a57eb 100644 --- a/docs_src/tutorials/kubernetes.md +++ b/docs_src/tutorials/kubernetes.md @@ -15,12 +15,13 @@ to be installed from the source code. ### Parameters #### Service monitor parameters -| Name | Description | Value | -| ------------------------- | ----------------------------------------------------------------------------------------------| ------------------------- | -| `serviceMonitor.enabled` | Create ServiceMonitor Resource for scraping metrics using PrometheusOperator | `false` | -| `serviceMonitor.namespace`| The namespace in which the ServiceMonitor will be created (if not set, default to namespace on which this chart is installed) | `""` | -| `serviceMonitor.interval` | The interval at which metrics should be scraped | `1m` | -| `serviceMonitor.labels` | Extra labels for the ServiceMonitor | `{}` | +| Name | Description | Value | +| ------------------------- -----| ----------------------------------------------------------------------------------------------| ------------------------- | +| `serviceMonitor.enabled` | Create ServiceMonitor Resource for scraping metrics using PrometheusOperator | `false` | +| `serviceMonitor.namespace` | The namespace in which the ServiceMonitor will be created (if not set, default to namespace on which this chart is installed) | `""` | +| `serviceMonitor.interval` | The interval at which metrics should be scraped | `1m` | +| `serviceMonitor.labels` | Extra labels for the ServiceMonitor | `{}` | +| `serviceMonitor.scrapeTimeout` | Specify the timeout after which the scrape is ended | `30s` | #### Other parameters | Name | Description | Value | diff --git a/helm/scaphandre/templates/servicemonitor.yaml b/helm/scaphandre/templates/servicemonitor.yaml index 5aae3d11..b36ceea4 100644 --- a/helm/scaphandre/templates/servicemonitor.yaml +++ b/helm/scaphandre/templates/servicemonitor.yaml @@ -21,7 +21,7 @@ spec: {{- if .Values.serviceMonitor.interval }} interval: {{ .Values.serviceMonitor.interval }} {{- end }} - scrapeTimeout: 30s + scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }} namespaceSelector: matchNames: - {{ .Release.Namespace }} diff --git a/helm/scaphandre/values.yaml b/helm/scaphandre/values.yaml index e89d08bf..e03556c0 100644 --- a/helm/scaphandre/values.yaml +++ b/helm/scaphandre/values.yaml @@ -32,6 +32,9 @@ serviceMonitor: # Extra labels for the ServiceMonitor labels: {} + # Specify the timeout after which the scrape is ended + scrapeTimeout: 30s + tolerations: # Tolerate all taints for observability - operator: "Exists" \ No newline at end of file From 7e035236f5ce7f1183e5d41aefc0e02f582c44db Mon Sep 17 00:00:00 2001 From: Nicolas Trangosi Date: Thu, 8 Jun 2023 11:24:38 +0200 Subject: [PATCH 3/4] Allow to configure relabelings on serviceMonitor --- docs_src/tutorials/kubernetes.md | 1 + helm/scaphandre/values.yaml | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs_src/tutorials/kubernetes.md b/docs_src/tutorials/kubernetes.md index f41a57eb..6842fb63 100644 --- a/docs_src/tutorials/kubernetes.md +++ b/docs_src/tutorials/kubernetes.md @@ -22,6 +22,7 @@ to be installed from the source code. | `serviceMonitor.interval` | The interval at which metrics should be scraped | `1m` | | `serviceMonitor.labels` | Extra labels for the ServiceMonitor | `{}` | | `serviceMonitor.scrapeTimeout` | Specify the timeout after which the scrape is ended | `30s` | +| `serviceMonitor.relabelings` | Allow to add extra labels to metrics | Add node metrics | #### Other parameters | Name | Description | Value | diff --git a/helm/scaphandre/values.yaml b/helm/scaphandre/values.yaml index e03556c0..4d1cb089 100644 --- a/helm/scaphandre/values.yaml +++ b/helm/scaphandre/values.yaml @@ -15,7 +15,7 @@ scaphandre: command: prometheus args: {} extraArgs: - containers: + containers: null # rustBacktrace: '1' # Run as root user to get proper permissions @@ -35,6 +35,12 @@ serviceMonitor: # Specify the timeout after which the scrape is ended scrapeTimeout: 30s + relabelings: + - action: replace + sourceLabels: + - __meta_kubernetes_pod_node_name + targetLabel: node + tolerations: # Tolerate all taints for observability - operator: "Exists" \ No newline at end of file From a264c224b68d6b07015f9191b4ed0dc06b2eae0c Mon Sep 17 00:00:00 2001 From: Nicolas Trangosi Date: Mon, 13 Nov 2023 16:40:05 +0100 Subject: [PATCH 4/4] Add support to custom affinity --- docs_src/tutorials/kubernetes.md | 7 ++++--- helm/scaphandre/templates/daemonset.yaml | 4 ++++ helm/scaphandre/templates/servicemonitor.yaml | 4 ++++ helm/scaphandre/values.yaml | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs_src/tutorials/kubernetes.md b/docs_src/tutorials/kubernetes.md index 6842fb63..4046fa79 100644 --- a/docs_src/tutorials/kubernetes.md +++ b/docs_src/tutorials/kubernetes.md @@ -25,9 +25,10 @@ to be installed from the source code. | `serviceMonitor.relabelings` | Allow to add extra labels to metrics | Add node metrics | #### Other parameters -| Name | Description | Value | -| ------------------------------------------ | ----------------------------------------------------------------------------| ------------------------- | -| `tolerations` | Tolerations for pod assignment. Evaluated as a template. | `- operator: "Exists"` | +| Name | Description | Value | +| ------------------------------------------ | ------------------------------------------------------------------------------------------------| ------------------------- | +| `affinity` | Pod scheduling preference. Can be used for instance when some node does not support scaphandre. | `{}` | +| `tolerations` | Tolerations for pod assignment. Evaluated as a template. | `- operator: "Exists"` | ## Install Prometheus diff --git a/helm/scaphandre/templates/daemonset.yaml b/helm/scaphandre/templates/daemonset.yaml index 64839f6e..f7cc860a 100644 --- a/helm/scaphandre/templates/daemonset.yaml +++ b/helm/scaphandre/templates/daemonset.yaml @@ -56,6 +56,10 @@ spec: runAsUser: {{ .Values.userID }} runAsGroup: {{ .Values.userGroup }} serviceAccountName: {{ template "scaphandre.name" . }} + affinity: + {{- with .Values.affinity }} + {{- toYaml . | nindent 8 }} + {{- end }} {{- with .Values.tolerations }} tolerations: {{- toYaml . | nindent 8 }} diff --git a/helm/scaphandre/templates/servicemonitor.yaml b/helm/scaphandre/templates/servicemonitor.yaml index b36ceea4..5b3132fe 100644 --- a/helm/scaphandre/templates/servicemonitor.yaml +++ b/helm/scaphandre/templates/servicemonitor.yaml @@ -22,6 +22,10 @@ spec: interval: {{ .Values.serviceMonitor.interval }} {{- end }} scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }} + {{- if .Values.serviceMonitor.relabelings }} + relabelings: + {{ toYaml .Values.serviceMonitor.relabelings | nindent 8 }} + {{- end }} namespaceSelector: matchNames: - {{ .Release.Namespace }} diff --git a/helm/scaphandre/values.yaml b/helm/scaphandre/values.yaml index 4d1cb089..309ab501 100644 --- a/helm/scaphandre/values.yaml +++ b/helm/scaphandre/values.yaml @@ -41,6 +41,8 @@ serviceMonitor: - __meta_kubernetes_pod_node_name targetLabel: node +affinity: {} + tolerations: # Tolerate all taints for observability - operator: "Exists" \ No newline at end of file