From a4aee7c3593c2bdde0230892dedc9e1ef7ed9268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20de=20Saint=20Martin?= Date: Fri, 22 Nov 2019 11:01:29 +0100 Subject: [PATCH] [stable/postgresql] Add optional PrometheusRule for metrics. (#19050) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédric de Saint Martin --- stable/postgresql/Chart.yaml | 2 +- stable/postgresql/README.md | 4 ++++ .../postgresql/templates/prometheusrule.yaml | 23 +++++++++++++++++++ stable/postgresql/values-production.yaml | 18 +++++++++++++++ stable/postgresql/values.yaml | 18 +++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 stable/postgresql/templates/prometheusrule.yaml diff --git a/stable/postgresql/Chart.yaml b/stable/postgresql/Chart.yaml index 7839ebaaf5bf..0c0e9c81d5b1 100644 --- a/stable/postgresql/Chart.yaml +++ b/stable/postgresql/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: postgresql -version: 7.5.0 +version: 7.6.0 appVersion: 11.6.0 description: Chart for PostgreSQL, an object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance. keywords: diff --git a/stable/postgresql/README.md b/stable/postgresql/README.md index d70a13251c3b..a071d6915b58 100644 --- a/stable/postgresql/README.md +++ b/stable/postgresql/README.md @@ -176,6 +176,10 @@ The following tables lists the configurable parameters of the PostgreSQL chart a | `metrics.serviceMonitor.namespace` | Optional namespace in which to create ServiceMonitor | `nil` | | `metrics.serviceMonitor.interval` | Scrape interval. If not set, the Prometheus default scrape interval is used | `nil` | | `metrics.serviceMonitor.scrapeTimeout` | Scrape timeout. If not set, the Prometheus default scrape timeout is used | `nil` | +| `metrics.prometheusRule.enabled` | Set this to true to create prometheusRules for Prometheus operator | `false` | +| `metrics.prometheusRule.additionalLabels` | Additional labels that can be used so prometheusRules will be discovered by Prometheus | `{}` | +| `metrics.prometheusRule.namespace` | namespace where prometheusRules resource should be created | the same namespace as postgresql | +| `metrics.prometheusRule.rules` | [rules](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/) to be created, check values for an example. | `[]` | | `metrics.image.registry` | PostgreSQL Image registry | `docker.io` | | `metrics.image.repository` | PostgreSQL Image name | `bitnami/postgres-exporter` | | `metrics.image.tag` | PostgreSQL Image tag | `{TAG_NAME}` | diff --git a/stable/postgresql/templates/prometheusrule.yaml b/stable/postgresql/templates/prometheusrule.yaml new file mode 100644 index 000000000000..44f1242dddb5 --- /dev/null +++ b/stable/postgresql/templates/prometheusrule.yaml @@ -0,0 +1,23 @@ +{{- if and .Values.metrics.enabled .Values.metrics.prometheusRule.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: {{ template "postgresql.fullname" . }} +{{- with .Values.metrics.prometheusRule.namespace }} + namespace: {{ . }} +{{- end }} + labels: + app: {{ template "postgresql.name" . }} + chart: {{ template "postgresql.chart" . }} + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} +{{- with .Values.metrics.prometheusRule.additionalLabels }} +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- with .Values.metrics.prometheusRule.rules }} + groups: + - name: {{ template "postgresql.name" $ }} + rules: {{ tpl (toYaml .) $ | nindent 8 }} +{{- end }} +{{- end }} diff --git a/stable/postgresql/values-production.yaml b/stable/postgresql/values-production.yaml index d18ed84826b5..e09d2c199bd8 100644 --- a/stable/postgresql/values-production.yaml +++ b/stable/postgresql/values-production.yaml @@ -386,6 +386,24 @@ metrics: # namespace: monitoring # interval: 30s # scrapeTimeout: 10s + ## Custom PrometheusRule 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 + prometheusRule: + enabled: false + additionalLabels: {} + namespace: "" + rules: [] + ## These are just examples rules, please adapt them to your needs. + ## Make sure to constraint the rules to the current postgresql service. + # - alert: HugeReplicationLag + # expr: pg_replication_lag{service="{{ template "postgresql.fullname" . }}-metrics"} / 3600 > 1 + # for: 1m + # labels: + # severity: critical + # annotations: + # description: replication for {{ template "postgresql.fullname" . }} PostgreSQL is lagging by {{ "{{ $value }}" }} hour(s). + # summary: PostgreSQL replication is lagging by {{ "{{ $value }}" }} hour(s). image: registry: docker.io repository: bitnami/postgres-exporter diff --git a/stable/postgresql/values.yaml b/stable/postgresql/values.yaml index c39c64d7ab60..77fe0d5f3933 100644 --- a/stable/postgresql/values.yaml +++ b/stable/postgresql/values.yaml @@ -394,6 +394,24 @@ metrics: # namespace: monitoring # interval: 30s # scrapeTimeout: 10s + ## Custom PrometheusRule 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 + prometheusRule: + enabled: false + additionalLabels: {} + namespace: "" + rules: [] + ## These are just examples rules, please adapt them to your needs. + ## Make sure to constraint the rules to the current postgresql service. + # - alert: HugeReplicationLag + # expr: pg_replication_lag{service="{{ template "postgresql.fullname" . }}-metrics"} / 3600 > 1 + # for: 1m + # labels: + # severity: critical + # annotations: + # description: replication for {{ template "postgresql.fullname" . }} PostgreSQL is lagging by {{ "{{ $value }}" }} hour(s). + # summary: PostgreSQL replication is lagging by {{ "{{ $value }}" }} hour(s). image: registry: docker.io repository: bitnami/postgres-exporter