From 0451731d9ec0e4a8f31b58241b97fc3dfbfd4768 Mon Sep 17 00:00:00 2001 From: sophon Date: Tue, 3 Sep 2024 21:07:21 +0800 Subject: [PATCH] chore: support prometheus stack --- .../templates/prometheus/monitor.yaml | 20 ++++++++++++++++ addons-cluster/redis/templates/_helpers.tpl | 24 +++++++++++++++++++ addons-cluster/redis/values.yaml | 3 +++ 3 files changed, 47 insertions(+) create mode 100644 addons-cluster/redis-cluster/templates/prometheus/monitor.yaml diff --git a/addons-cluster/redis-cluster/templates/prometheus/monitor.yaml b/addons-cluster/redis-cluster/templates/prometheus/monitor.yaml new file mode 100644 index 000000000..10b32dd97 --- /dev/null +++ b/addons-cluster/redis-cluster/templates/prometheus/monitor.yaml @@ -0,0 +1,20 @@ +{{- if and (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1/ServiceMonitor") .Values.prometheus.enabled }} +# Prometheus Monitor Service (Metrics) +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ include "kblib.clusterName" . }}-metrics-monitor + labels: + {{- include "kblib.clusterLabels" . | nindent 4 }} +spec: + podMetricsEndpoints: + - path: /metrics + port: http-metrics + scheme: http + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "redis-cluster.selectorLabels" . | nindent 6 }} +{{- end }} \ No newline at end of file diff --git a/addons-cluster/redis/templates/_helpers.tpl b/addons-cluster/redis/templates/_helpers.tpl index 40660b2d1..8933c5a1b 100644 --- a/addons-cluster/redis/templates/_helpers.tpl +++ b/addons-cluster/redis/templates/_helpers.tpl @@ -8,6 +8,7 @@ Define redis cluster shardingSpec with ComponentDefinition. name: redis componentDef: redis-cluster-7 replicas: {{ .Values.replicas }} + {{- include "redis-cluster.exporter" . | indent 4 }} {{- if .Values.nodePortEnabled }} services: - name: redis-advertised @@ -45,6 +46,7 @@ Define redis ComponentSpec with ComponentDefinition. {{- define "redis-cluster.componentSpec" }} - name: redis {{- include "redis-cluster.replicaCount" . | indent 2 }} + {{- include "redis-cluster.exporter" . | indent 2 }} {{- if .Values.nodePortEnabled }} services: - name: redis-advertised @@ -125,3 +127,25 @@ Define redis cluster sharding count. {{- define "redis-cluster.shards" }} shards: {{ max .Values.redisCluster.shardCount 3 }} {{- end }} + + +{{/* +Define redis cluster prometheus exporter. +*/}} +{{- define "redis-cluster.exporter" }} +{{- if or .Values.prometheus.enabled ( not .Values.extra.disableExporter ) }} +disableExporter: false +{{- else }} +disableExporter: true +{{- end }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "redis-cluster.selectorLabels" -}} +{{- /*app.kubernetes.io/name: {{ include "kblib.clusterName" . | quote }}*/ -}} +app.kubernetes.io/instance: {{ include "kblib.clusterName" . | quote }} +app.kubernetes.io/managed-by: "kubeblocks" +apps.kubeblocks.io/component-name: "redis" +{{- end }} \ No newline at end of file diff --git a/addons-cluster/redis/values.yaml b/addons-cluster/redis/values.yaml index 379e24a46..6e01476ab 100644 --- a/addons-cluster/redis/values.yaml +++ b/addons-cluster/redis/values.yaml @@ -70,3 +70,6 @@ redisCluster: extra: rbacEnabled: true + +prometheus: + enabled: false