From 7477b33cba5961bea54eaf63eded687b64877fd3 Mon Sep 17 00:00:00 2001 From: Marco Kilchhofer Date: Fri, 17 Sep 2021 19:47:11 +0200 Subject: [PATCH] feat(argo-cd): Add ability to scrape redis metrics (#892) * feat(argo-cd): Add ability to scrape redis metrics Signed-off-by: Marco Kilchhofer * Bump chart version Signed-off-by: Marco Kilchhofer --- charts/argo-cd/Chart.yaml | 4 +- charts/argo-cd/README.md | 19 +++++++++ .../argo-cd/templates/redis/deployment.yaml | 18 +++++++++ .../templates/redis/metrics-service.yaml | 28 +++++++++++++ .../templates/redis/networkpolicy.yaml | 7 ++++ .../templates/redis/servicemonitor.yaml | 39 +++++++++++++++++++ charts/argo-cd/values.yaml | 31 +++++++++++++++ 7 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 charts/argo-cd/templates/redis/metrics-service.yaml create mode 100644 charts/argo-cd/templates/redis/servicemonitor.yaml diff --git a/charts/argo-cd/Chart.yaml b/charts/argo-cd/Chart.yaml index 30488923..9976c962 100644 --- a/charts/argo-cd/Chart.yaml +++ b/charts/argo-cd/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: 2.1.2 description: A Helm chart for ArgoCD, a declarative, GitOps continuous delivery tool for Kubernetes. name: argo-cd -version: 3.19.0 +version: 3.20.0 home: https://github.com/argoproj/argo-helm icon: https://argoproj.github.io/argo-cd/assets/logo.png keywords: @@ -21,4 +21,4 @@ dependencies: condition: redis-ha.enabled annotations: artifacthub.io/changes: | - - "[Added]: Add support for topologySpreadConstraints" + - "[Added]: Ability to scrape redis metrics" diff --git a/charts/argo-cd/README.md b/charts/argo-cd/README.md index 5e1459a2..d9834553 100644 --- a/charts/argo-cd/README.md +++ b/charts/argo-cd/README.md @@ -469,6 +469,25 @@ through `xxx.extraArgs` | redis.securityContext | Redis Pod Security Context | See [values.yaml](values.yaml) | | redis.servicePort | Redis service port | `6379` | | redis.tolerations | [Tolerations for use with node taints](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) | `[]` | +| redis.metrics.enabled | Deploy metrics service and redis-exporter sidecar | `false` | +| redis.metrics.image.repository | redis-exporter image repository | `quay.io/bitnami/redis-exporter` | +| redis.metrics.image.tag | redis-exporter image tag | `1.26.0-debian-10-r2` | +| redis.metrics.image.imagePullPolicy | redis-exporter image PullPolicy | `IfNotPresent` | +| redis.metrics.containerPort | Port to use for redis-exporter sidecar | `9121` | +| redis.metrics.resources | Resource limits and requests for redis-exporter sidecar | `{}` | +| redis.metrics.service.type | Metrics service type | `ClusterIP` | +| redis.metrics.service.clusterIP | Metrics service clusterIP. `None` makes a "headless service" (no virtual IP) | `None` | +| redis.metrics.service.annotations | Metrics service annotations | `{}` | +| redis.metrics.service.labels | Metrics service labels | `{}` | +| redis.metrics.service.servicePort | Metrics service port | `9121` | +| redis.metrics.service.portName | Metrics service port name | `http-metrics` | +| redis.metrics.serviceMonitor.enabled | Enable a prometheus ServiceMonitor | `false` | +| redis.metrics.serviceMonitor.interval | Interval at which metrics should be scraped | `30s` | +| redis.metrics.serviceMonitor.relabelings | Prometheus [RelabelConfigs](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config) to apply to samples before scraping | `[]` | +| redis.metrics.serviceMonitor.metricRelabelings | Prometheus [MetricRelabelConfigs](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs) to apply to samples before ingestion | `[]` | +| redis.metrics.serviceMonitor.selector | Prometheus ServiceMonitor selector labels | `{}` | +| redis.metrics.serviceMonitor.namespace | Prometheus ServiceMonitor namespace | `` | +| redis.metrics.serviceMonitor.additionalLabels | Additional labels to add to the Prometheus ServiceMonitor | `{}` | | redis-ha | Configures [Redis HA subchart](https://github.com/DandyDeveloper/charts/tree/master/charts/redis-ha) The properties below have been changed from the subchart defaults | | | redis-ha.enabled | Enables the Redis HA subchart and disables the custom Redis single node deployment| `false` | | redis-ha.exporter.enabled | If `true`, the prometheus exporter sidecar is enabled | `true` | diff --git a/charts/argo-cd/templates/redis/deployment.yaml b/charts/argo-cd/templates/redis/deployment.yaml index f5003466..fa01c7b4 100755 --- a/charts/argo-cd/templates/redis/deployment.yaml +++ b/charts/argo-cd/templates/redis/deployment.yaml @@ -64,6 +64,24 @@ spec: {{- end }} resources: {{- toYaml .Values.redis.resources | nindent 10 }} + {{- if .Values.redis.metrics.enabled }} + - name: metrics + env: + - name: REDIS_ADDR + value: {{ printf "redis://localhost:%v" .Values.redis.containerPort }} + - name: REDIS_EXPORTER_WEB_LISTEN_ADDRESS + value: {{ printf "0.0.0.0:%v" .Values.redis.metrics.containerPort }} + image: {{ .Values.redis.metrics.image.repository }}:{{ .Values.redis.metrics.image.tag }} + imagePullPolicy: {{ .Values.redis.metrics.image.imagePullPolicy}} + ports: + - containerPort: {{ .Values.redis.metrics.containerPort }} + name: metrics + protocol: TCP + resources: {{- toYaml .Values.redis.metrics.resources | nindent 10 }} + {{- with .Values.redis.containerSecurityContext }} + securityContext: {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} {{- with .Values.redis.extraContainers }} {{- toYaml . | nindent 6 }} {{- end }} diff --git a/charts/argo-cd/templates/redis/metrics-service.yaml b/charts/argo-cd/templates/redis/metrics-service.yaml new file mode 100644 index 00000000..e799b5ea --- /dev/null +++ b/charts/argo-cd/templates/redis/metrics-service.yaml @@ -0,0 +1,28 @@ +{{- $redisHa := (index .Values "redis-ha") -}} +{{- if and .Values.redis.enabled (not $redisHa.enabled) .Values.redis.metrics.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "argo-cd.redis.fullname" . }}-metrics + {{- with .Values.redis.metrics.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + {{- include "argo-cd.labels" (dict "context" . "component" .Values.redis.name "name" .Values.redis.name) | nindent 4 }} + {{- with .Values.redis.metrics.service.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.redis.metrics.service.clusterIP }} + clusterIP: {{ . }} + {{- end }} + ports: + - name: {{ .Values.redis.metrics.service.portName }} + protocol: TCP + port: {{ .Values.redis.metrics.service.servicePort }} + targetPort: metrics + selector: + {{- include "argo-cd.selectorLabels" (dict "context" . "component" .Values.redis.name "name" .Values.redis.name) | nindent 4 }} + type: {{ .Values.redis.metrics.service.type }} +{{- end }} diff --git a/charts/argo-cd/templates/redis/networkpolicy.yaml b/charts/argo-cd/templates/redis/networkpolicy.yaml index 881e257c..8b564add 100644 --- a/charts/argo-cd/templates/redis/networkpolicy.yaml +++ b/charts/argo-cd/templates/redis/networkpolicy.yaml @@ -21,6 +21,13 @@ spec: ports: - port: redis protocol: TCP + {{- if .Values.redis.metrics.enabled }} + - from: + - namespaceSelector: {} + ports: + - port: metrics + protocol: TCP + {{- end }} podSelector: matchLabels: {{- include "argo-cd.selectorLabels" (dict "context" . "name" .Values.redis.name) | nindent 6 }} diff --git a/charts/argo-cd/templates/redis/servicemonitor.yaml b/charts/argo-cd/templates/redis/servicemonitor.yaml new file mode 100644 index 00000000..b7029b74 --- /dev/null +++ b/charts/argo-cd/templates/redis/servicemonitor.yaml @@ -0,0 +1,39 @@ +{{- $redisHa := (index .Values "redis-ha") -}} +{{- if and .Values.redis.enabled (not $redisHa.enabled) .Values.redis.metrics.enabled .Values.redis.metrics.serviceMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "argo-cd.redis.fullname" . }} + {{- with .Values.redis.metrics.serviceMonitor.namespace }} + namespace: {{ . }} + {{- end }} + labels: + {{- include "argo-cd.labels" (dict "context" . "component" .Values.redis.name "name" .Values.redis.name) | nindent 4 }} + {{- with .Values.redis.metrics.serviceMonitor.selector }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.redis.metrics.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + endpoints: + - port: {{ .Values.redis.metrics.service.portName }} + {{- with .Values.redis.metrics.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + path: /metrics + {{- with .Values.redis.metrics.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.redis.metrics.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + {{- include "argo-cd.selectorLabels" (dict "context" . "component" .Values.redis.name "name" .Values.redis.name) | nindent 6 }} +{{- end }} diff --git a/charts/argo-cd/values.yaml b/charts/argo-cd/values.yaml index 526660ab..9f828c8e 100755 --- a/charts/argo-cd/values.yaml +++ b/charts/argo-cd/values.yaml @@ -451,6 +451,37 @@ redis: ## Additional containers to be added to the redis pod. extraContainers: [] + metrics: + enabled: false + image: + repository: quay.io/bitnami/redis-exporter + tag: 1.26.0-debian-10-r2 + imagePullPolicy: IfNotPresent + containerPort: 9121 + resources: {} + # limits: + # cpu: 50m + # memory: 64Mi + # requests: + # cpu: 10m + # memory: 32Mi + service: + type: ClusterIP + clusterIP: None + annotations: {} + labels: {} + servicePort: 9121 + portName: http-metrics + serviceMonitor: + enabled: false + interval: 30s + relabelings: [] + metricRelabelings: [] + selector: {} + # prometheus: kube-prometheus + # namespace: monitoring + additionalLabels: {} + # This key configures Redis-HA subchart and when enabled (redis-ha.enabled=true) # the custom redis deployment is omitted redis-ha: