From 61f524718bc1d665fa01fc26eecc482bcaaa1b87 Mon Sep 17 00:00:00 2001 From: Leo Q Date: Sun, 18 Feb 2024 17:11:56 +0800 Subject: [PATCH] support auto reload for config and scrape config (#61) * support auto reload for config and scrape config * f --- charts/tencentcloud-exporter/Chart.yaml | 4 ++-- .../templates/deployment.yaml | 7 +++--- .../templates/scrapeconfig.yaml | 23 +++++++++++++++++++ charts/tencentcloud-exporter/values.yaml | 16 +++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 charts/tencentcloud-exporter/templates/scrapeconfig.yaml diff --git a/charts/tencentcloud-exporter/Chart.yaml b/charts/tencentcloud-exporter/Chart.yaml index 1d1fc48..5fe42fb 100644 --- a/charts/tencentcloud-exporter/Chart.yaml +++ b/charts/tencentcloud-exporter/Chart.yaml @@ -15,13 +15,13 @@ 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.1.0 +version: 0.2.0 # 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 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "v2.8.0" -home: https://github.com/tencentyun/tencentcloud-exporter +home: https://github.com/douban/tencentcloud-exporter maintainers: - name: LeoQuote diff --git a/charts/tencentcloud-exporter/templates/deployment.yaml b/charts/tencentcloud-exporter/templates/deployment.yaml index d2573a1..da3efb6 100644 --- a/charts/tencentcloud-exporter/templates/deployment.yaml +++ b/charts/tencentcloud-exporter/templates/deployment.yaml @@ -13,10 +13,11 @@ spec: {{- include "tencentcloud-exporter.selectorLabels" . | nindent 6 }} template: metadata: - {{- with .Values.podAnnotations }} annotations: - {{- toYaml . | nindent 8 }} - {{- end }} + checksum/config: {{ .Values.extraConfigs | toString| sha256sum }} + {{- if .Values.podAnnotations -}} + {{ toYaml .Values.podAnnotations | nindent 8 }} + {{- end }} labels: {{- include "tencentcloud-exporter.selectorLabels" . | nindent 8 }} spec: diff --git a/charts/tencentcloud-exporter/templates/scrapeconfig.yaml b/charts/tencentcloud-exporter/templates/scrapeconfig.yaml new file mode 100644 index 0000000..b3332e4 --- /dev/null +++ b/charts/tencentcloud-exporter/templates/scrapeconfig.yaml @@ -0,0 +1,23 @@ +{{- if .Values.scrapeConfig.enabled }} +apiVersion: monitoring.coreos.com/v1alpha1 +kind: ScrapeConfig +metadata: + labels: +{{ include "tencentcloud-exporter.labels" . | indent 4 }} + name: {{ template "tencentcloud-exporter.fullname" . }} +spec: + staticConfigs: + - targets: + - {{ include "tencentcloud-exporter.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.service.port }} + metricsPath: {{ .Values.scrapeConfig.telemetryPath }} +{{- if .Values.scrapeConfig.relabelings }} + relabelings: +{{ toYaml .Values.scrapeConfig.relabelings | indent 4 }} +{{- end }} +{{- if .Values.scrapeConfig.metricRelabelings }} + metricRelabelings: +{{ toYaml .Values.scrapeConfig.metricRelabelings | indent 4 }} +{{- end }} + scrapeInterval: {{ .Values.scrapeConfig.interval }} + scrapeTimeout: {{ .Values.scrapeConfig.timeout }} +{{- end }} diff --git a/charts/tencentcloud-exporter/values.yaml b/charts/tencentcloud-exporter/values.yaml index 606bce1..409b643 100644 --- a/charts/tencentcloud-exporter/values.yaml +++ b/charts/tencentcloud-exporter/values.yaml @@ -114,6 +114,22 @@ serviceMonitor: # targetLabels: [] # metricRelabelings: [] +scrapeConfig: + # Use https://prometheus-operator.dev/docs/user-guides/scrapeconfig/ to congfigure scrapeConfig + # It is advbised to use scrapeConfig instead of servicemonitor, as it is more flexible + # ServiceMonitor and scrapeConfig can be enabled at the same time, but it is not recommended + # When set true then use a ScrapeConfig to configure scraping + enabled: false + timeout: 10s + interval: 1m + telemetryPath: /metrics + relabelings: + - regex: 'container|endpoint|pod|service|instance' + action: "labeldrop" + metricRelabelings: + - regex: 'instance' + action: "labeldrop" + ## Custom PrometheusRules to be defined ## The value is evaluated as a template, so, for example, the value can depend on .Release or .Chart ## ref: https://github.com/coreos/prometheus-operator#customresourcedefinitions