From 65dffbc95e5a4ae5ccb83f660edcde2ab9d66df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20J=2E=20Salmer=C3=B3n-Garc=C3=ADa?= Date: Thu, 8 Nov 2018 13:47:58 +0100 Subject: [PATCH] [stable/nats] Add prometheus exporter (#8382) * [stable/nats] Add prometheus exporter Signed-off-by: Javier J. Salmeron Garcia * Fix podannotation Signed-off-by: Javier J. Salmeron Garcia * Bump chart again Signed-off-by: Javier J. Salmeron Garcia --- stable/nats/Chart.yaml | 2 +- stable/nats/README.md | 9 ++++++++ stable/nats/templates/_helpers.tpl | 10 ++++++++ stable/nats/templates/statefulset.yaml | 32 ++++++++++++++++++++++++-- stable/nats/values-production.yaml | 24 +++++++++++++++++++ stable/nats/values.yaml | 24 +++++++++++++++++++ 6 files changed, 98 insertions(+), 3 deletions(-) diff --git a/stable/nats/Chart.yaml b/stable/nats/Chart.yaml index 1abbb2ddab..906f96d13f 100644 --- a/stable/nats/Chart.yaml +++ b/stable/nats/Chart.yaml @@ -1,5 +1,5 @@ name: nats -version: 1.1.2 +version: 1.2.0 appVersion: 1.3.0 description: An open-source, cloud-native messaging system keywords: diff --git a/stable/nats/README.md b/stable/nats/README.md index cdfadead1b..37f57ec30c 100644 --- a/stable/nats/README.md +++ b/stable/nats/README.md @@ -118,6 +118,15 @@ The following table lists the configurable parameters of the NATS chart and thei | `networkPolicy.enabled` | Enable NetworkPolicy | `false` | | `networkPolicy.allowExternal` | Allow external connections | `true` | | `sidecars` | Attach additional containers to the pod. | `nil` | +| `metrics.enabled` | Start a side-car prometheus exporter | `false` | +| `metrics.image.registry` | MongoDB exporter image registry | `docker.io` | +| `metrics.image.repository` | MongoDB exporter image name | `appcelerator/prometheus-nats-exporter` | +| `metrics.image.tag` | MongoDB exporter image tag | `0.17.0` | +| `metrics.image.pullPolicy` | Image pull policy | `IfNotPresent` | +| `metrics.image.pullSecrets` | Specify docker-registry secret names as an array | `nil` | +| `metrics.podAnnotations` | Additional annotations for Metrics exporter pod | {} | +| `metrics.resources` | Exporter resource requests/limit | Memory: `256Mi`, CPU: `100m` | + Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, diff --git a/stable/nats/templates/_helpers.tpl b/stable/nats/templates/_helpers.tpl index 26300acf19..ef93757d98 100644 --- a/stable/nats/templates/_helpers.tpl +++ b/stable/nats/templates/_helpers.tpl @@ -61,3 +61,13 @@ Return the appropriate apiVersion for networkpolicy. {{- print "networking.k8s.io/v1" -}} {{- end -}} {{- end -}} + +{{/* +Return the proper image name (for the metrics image) +*/}} +{{- define "metrics.image" -}} +{{- $registryName := .Values.metrics.image.registry -}} +{{- $repositoryName := .Values.metrics.image.repository -}} +{{- $tag := .Values.metrics.image.tag | toString -}} +{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} +{{- end -}} diff --git a/stable/nats/templates/statefulset.yaml b/stable/nats/templates/statefulset.yaml index cb0811e71e..503aec47ad 100644 --- a/stable/nats/templates/statefulset.yaml +++ b/stable/nats/templates/statefulset.yaml @@ -29,10 +29,15 @@ spec: {{- if .Values.podLabels }} {{ toYaml .Values.podLabels | indent 8 }} {{- end }} - {{- if .Values.podAnnotations }} +{{- if or .Values.podAnnotations .Values.metrics.enabled }} annotations: +{{- if .Values.podAnnotations }} {{ toYaml .Values.podAnnotations | indent 8 }} - {{- end }} +{{- end }} +{{- if .Values.metrics.podAnnotations }} +{{ toYaml .Values.metrics.podAnnotations | indent 8 }} +{{- end }} +{{- end }} spec: {{- if .Values.image.pullSecrets }} imagePullSecrets: @@ -122,6 +127,29 @@ spec: {{- if .Values.sidecars }} {{ toYaml .Values.sidecars | indent 6 }} {{- end }} +{{- if .Values.metrics.enabled }} + - name: metrics + image: {{ template "metrics.image" . }} + imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }} + command: [ '/prometheus-nats-exporter', '-varz', 'http://localhost:{{ .Values.monitoringService.port }}' ] + ports: + - name: metrics + containerPort: 7777 + livenessProbe: + httpGet: + path: /metrics + port: metrics + initialDelaySeconds: 15 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /metrics + port: metrics + initialDelaySeconds: 5 + timeoutSeconds: 1 + resources: + {{ toYaml .Values.metrics.resources | indent 10 }} +{{- end }} volumes: - name: config configMap: diff --git a/stable/nats/values-production.yaml b/stable/nats/values-production.yaml index 3d13b0f31f..3952144f4a 100644 --- a/stable/nats/values-production.yaml +++ b/stable/nats/values-production.yaml @@ -255,3 +255,27 @@ sidecars: # ports: # - name: portname # containerPort: 1234 + +## Prometheus Exporter / Metrics +## +metrics: + enabled: true + image: + registry: docker.io + repository: appcelerator/prometheus-nats-exporter + tag: 0.17.0 + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets. + ## Secrets must be manually created in the namespace. + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistrKeySecretName + ## Metrics exporter resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + # resources: {} + ## Metrics exporter pod Annotation + podAnnotations: + prometheus.io/scrape: "true" + prometheus.io/port: "7777" diff --git a/stable/nats/values.yaml b/stable/nats/values.yaml index 6d0bf31c44..cd7ec5ac06 100644 --- a/stable/nats/values.yaml +++ b/stable/nats/values.yaml @@ -259,3 +259,27 @@ sidecars: # ports: # - name: portname # containerPort: 1234 + +## Prometheus Exporter / Metrics +## +metrics: + enabled: false + image: + registry: docker.io + repository: appcelerator/prometheus-nats-exporter + tag: 0.17.0 + pullPolicy: IfNotPresent + ## Optionally specify an array of imagePullSecrets. + ## Secrets must be manually created in the namespace. + ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ + ## + # pullSecrets: + # - myRegistrKeySecretName + ## Metrics exporter resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + # resources: {} + ## Metrics exporter pod Annotation + podAnnotations: + prometheus.io/scrape: "true" + prometheus.io/port: "7777"