diff --git a/charts/cluster/README.md b/charts/cluster/README.md index 06a0c30e29..0ad9c0e6bf 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -178,6 +178,7 @@ Kubernetes: `>=1.29.0-0` | cluster.monitoring.podMonitor.labels | object | `{}` | Additional labels to set on the generated PodMonitor resource. Add labels your monitoring stack requires (for example `team-name`). | | cluster.monitoring.podMonitor.metricRelabelings | list | `[]` | The list of metric relabelings for the PodMonitor. Applied to samples before ingestion. | | cluster.monitoring.podMonitor.relabelings | list | `[]` | The list of relabelings for the PodMonitor. Applied to samples before scraping. | +| cluster.monitoring.prometheusRule.addAlertExtraLabels | object | `{}` | Additional labels to add to all alerts generated by the PrometheusRule. | | cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts | | cluster.monitoring.prometheusRule.excludeRules | list | `[]` | Exclude specified rules | | cluster.podSecurityContext | object | `{}` | Configure the Pod Security Context. See: https://cloudnative-pg.io/documentation/preview/security/ | diff --git a/charts/cluster/prometheus_rules/cluster-ha-critical.yaml b/charts/cluster/prometheus_rules/cluster-ha-critical.yaml index 246a5af6b0..9672bab809 100644 --- a/charts/cluster/prometheus_rules/cluster-ha-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-ha-critical.yaml @@ -23,4 +23,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-ha-warning.yaml b/charts/cluster/prometheus_rules/cluster-ha-warning.yaml index 736ddf393d..2604bf45ee 100644 --- a/charts/cluster/prometheus_rules/cluster-ha-warning.yaml +++ b/charts/cluster/prometheus_rules/cluster-ha-warning.yaml @@ -21,4 +21,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-high_connection-critical.yaml b/charts/cluster/prometheus_rules/cluster-high_connection-critical.yaml index df13ce3b37..f64d0948cb 100644 --- a/charts/cluster/prometheus_rules/cluster-high_connection-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-high_connection-critical.yaml @@ -14,4 +14,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-high_connection-warning.yaml b/charts/cluster/prometheus_rules/cluster-high_connection-warning.yaml index 73cc783925..7a8b477f67 100644 --- a/charts/cluster/prometheus_rules/cluster-high_connection-warning.yaml +++ b/charts/cluster/prometheus_rules/cluster-high_connection-warning.yaml @@ -14,4 +14,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-high_replication_lag.yaml b/charts/cluster/prometheus_rules/cluster-high_replication_lag.yaml index 795d571be2..ff5e9e1be4 100644 --- a/charts/cluster/prometheus_rules/cluster-high_replication_lag.yaml +++ b/charts/cluster/prometheus_rules/cluster-high_replication_lag.yaml @@ -16,4 +16,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-instances_on_same_node.yaml b/charts/cluster/prometheus_rules/cluster-instances_on_same_node.yaml index aafcfab1e2..c75e97115e 100644 --- a/charts/cluster/prometheus_rules/cluster-instances_on_same_node.yaml +++ b/charts/cluster/prometheus_rules/cluster-instances_on_same_node.yaml @@ -16,4 +16,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-logical_replication_errors-critical.yaml b/charts/cluster/prometheus_rules/cluster-logical_replication_errors-critical.yaml index 8c33caa8e0..ceb45b67ed 100644 --- a/charts/cluster/prometheus_rules/cluster-logical_replication_errors-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-logical_replication_errors-critical.yaml @@ -15,4 +15,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-logical_replication_errors.yaml b/charts/cluster/prometheus_rules/cluster-logical_replication_errors.yaml index cb39de7be6..995548532b 100644 --- a/charts/cluster/prometheus_rules/cluster-logical_replication_errors.yaml +++ b/charts/cluster/prometheus_rules/cluster-logical_replication_errors.yaml @@ -15,4 +15,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-logical_replication_lagging-critical.yaml b/charts/cluster/prometheus_rules/cluster-logical_replication_lagging-critical.yaml index d80c82627c..e4fb641693 100644 --- a/charts/cluster/prometheus_rules/cluster-logical_replication_lagging-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-logical_replication_lagging-critical.yaml @@ -29,4 +29,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-logical_replication_lagging.yaml b/charts/cluster/prometheus_rules/cluster-logical_replication_lagging.yaml index 6994837cde..3f041a2691 100644 --- a/charts/cluster/prometheus_rules/cluster-logical_replication_lagging.yaml +++ b/charts/cluster/prometheus_rules/cluster-logical_replication_lagging.yaml @@ -29,4 +29,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-logical_replication_stopped-critical.yaml b/charts/cluster/prometheus_rules/cluster-logical_replication_stopped-critical.yaml index 77233c9434..6181f9cfac 100644 --- a/charts/cluster/prometheus_rules/cluster-logical_replication_stopped-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-logical_replication_stopped-critical.yaml @@ -26,4 +26,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-logical_replication_stopped.yaml b/charts/cluster/prometheus_rules/cluster-logical_replication_stopped.yaml index e56e0f4e5d..8cc0e69c84 100644 --- a/charts/cluster/prometheus_rules/cluster-logical_replication_stopped.yaml +++ b/charts/cluster/prometheus_rules/cluster-logical_replication_stopped.yaml @@ -25,4 +25,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-low_disk_space-critical.yaml b/charts/cluster/prometheus_rules/cluster-low_disk_space-critical.yaml index ea1c383458..2e3c0d0735 100644 --- a/charts/cluster/prometheus_rules/cluster-low_disk_space-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-low_disk_space-critical.yaml @@ -21,4 +21,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-low_disk_space-warning.yaml b/charts/cluster/prometheus_rules/cluster-low_disk_space-warning.yaml index 4b7e3eaa2e..132661d8fa 100644 --- a/charts/cluster/prometheus_rules/cluster-low_disk_space-warning.yaml +++ b/charts/cluster/prometheus_rules/cluster-low_disk_space-warning.yaml @@ -21,4 +21,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-offline.yaml b/charts/cluster/prometheus_rules/cluster-offline.yaml index 4206c02f3c..e8d3a9eacc 100644 --- a/charts/cluster/prometheus_rules/cluster-offline.yaml +++ b/charts/cluster/prometheus_rules/cluster-offline.yaml @@ -16,4 +16,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-physical_replication_lag-critical.yaml b/charts/cluster/prometheus_rules/cluster-physical_replication_lag-critical.yaml index 4bcb58a6f5..de7e1d921d 100644 --- a/charts/cluster/prometheus_rules/cluster-physical_replication_lag-critical.yaml +++ b/charts/cluster/prometheus_rules/cluster-physical_replication_lag-critical.yaml @@ -15,4 +15,7 @@ labels: severity: critical namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-physical_replication_lag-warning.yaml b/charts/cluster/prometheus_rules/cluster-physical_replication_lag-warning.yaml index a6ee90bd35..0de881edd5 100644 --- a/charts/cluster/prometheus_rules/cluster-physical_replication_lag-warning.yaml +++ b/charts/cluster/prometheus_rules/cluster-physical_replication_lag-warning.yaml @@ -15,4 +15,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/prometheus_rules/cluster-zone_spread-warning.yaml b/charts/cluster/prometheus_rules/cluster-zone_spread-warning.yaml index 41fa4002ae..5b265e1040 100644 --- a/charts/cluster/prometheus_rules/cluster-zone_spread-warning.yaml +++ b/charts/cluster/prometheus_rules/cluster-zone_spread-warning.yaml @@ -15,4 +15,7 @@ labels: severity: warning namespace: {{ .namespace }} cnpg_cluster: {{ .cluster }} +{{- range $key, $val := .addAlertExtraLabels }} + {{ $key }}: {{ $val | toString }} +{{- end }} {{- end -}} diff --git a/charts/cluster/templates/prometheus-rule.yaml b/charts/cluster/templates/prometheus-rule.yaml index 360b4798de..58746ea5d3 100644 --- a/charts/cluster/templates/prometheus-rule.yaml +++ b/charts/cluster/templates/prometheus-rule.yaml @@ -14,6 +14,7 @@ spec: - name: cloudnative-pg/{{ include "cluster.fullname" . }} rules: {{- $dict := dict "excludeRules" .Values.cluster.monitoring.prometheusRule.excludeRules -}} + {{- $_ := set $dict "addAlertExtraLabels" .Values.cluster.monitoring.prometheusRule.addAlertExtraLabels -}} {{- $_ := set $dict "value" "{{ $value }}" -}} {{- $_ := set $dict "namespace" .Release.Namespace -}} {{- $_ := set $dict "cluster" (include "cluster.fullname" .) -}} diff --git a/charts/cluster/values.schema.json b/charts/cluster/values.schema.json index 85645a49a7..e8b28dd715 100644 --- a/charts/cluster/values.schema.json +++ b/charts/cluster/values.schema.json @@ -276,6 +276,9 @@ }, "excludeRules": { "type": "array" + }, + "addAlertExtraLabels": { + "type": "object" } } } diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index 2c7e8b5c15..989a6a1370 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -324,6 +324,10 @@ cluster: # -- Exclude specified rules excludeRules: [] # - CNPGClusterZoneSpreadWarning + # -- Additional labels to add to all alerts generated by the PrometheusRule. + addAlertExtraLabels: {} + # alert_email: "true" + # environment: staging # Additional instrumentation via custom metrics instrumentation: # -- Enable logical replication metrics