From 4adf2c702c74d0e37e9673624eee53c4bf66830a Mon Sep 17 00:00:00 2001 From: Vincent Mercier Date: Thu, 4 Jan 2024 11:57:11 +0100 Subject: [PATCH] feat(helm): Add defaultKeepFiringFor and keepFiringFor parameters to configure keep_firing_for attribute --- charts/_source/templates/_helpers.tpl | 4 ++++ .../templates/prometheusConfiguration.yaml | 1 + charts/_source/templates/prometheusRules.yaml | 1 + .../_source/tests/prometheusRules_test.yaml | 20 ++++++++++++++++ .../tests/values/with_keepFiringFor.yaml | 24 +++++++++++++++++++ charts/_source/values.yaml | 2 ++ .../prometheus-postgresql-alerts/values.yaml | 2 ++ charts/prometheus-rds-alerts/values.yaml | 2 ++ 8 files changed, 56 insertions(+) create mode 100644 charts/_source/tests/values/with_keepFiringFor.yaml diff --git a/charts/_source/templates/_helpers.tpl b/charts/_source/templates/_helpers.tpl index f33e9de..e8edf86 100644 --- a/charts/_source/templates/_helpers.tpl +++ b/charts/_source/templates/_helpers.tpl @@ -71,6 +71,7 @@ Render Prometheus rule {{- $name := .name -}} {{- $pintComments := default dict .pintComments -}} {{- $for := .for -}} +{{- $keepFiringFor := default .defaultKeepFiringFor .keepFiringFor -}} {{- $ruleLabels := .labels -}} {{- $record := .record -}} {{- $annotations := default dict .annotations -}} @@ -112,6 +113,9 @@ Render Prometheus rule {{- if $for }} for: {{ $for }} {{- end }} + {{- if $keepFiringFor }} + keep_firing_for: {{ $keepFiringFor }} + {{- end }} {{- if $labels }} labels: {{ $labels | toYaml | indent 4 }} diff --git a/charts/_source/templates/prometheusConfiguration.yaml b/charts/_source/templates/prometheusConfiguration.yaml index c32efdb..b9a0197 100644 --- a/charts/_source/templates/prometheusConfiguration.yaml +++ b/charts/_source/templates/prometheusConfiguration.yaml @@ -7,6 +7,7 @@ groups: {{- $_ := set . "globalAdditionalExprLabels" $.Values.global.additionalExprLabels }} {{- $_ := set . "globalAdditionalRuleLabels" $.Values.global.additionalRuleLabels }} {{- $_ := set . "defaultRunbookUrl" $.Values.defaultRunbookUrl }} +{{- $_ := set . "defaultKeepFiringFor" $.Values.defaultKeepFiringFor }} {{- $_ := set . "chartVersion" $.Chart.Version }} {{- include "chart.renderPrometheusRule" . | indent 8 -}} diff --git a/charts/_source/templates/prometheusRules.yaml b/charts/_source/templates/prometheusRules.yaml index 891e8c3..9a49cc2 100644 --- a/charts/_source/templates/prometheusRules.yaml +++ b/charts/_source/templates/prometheusRules.yaml @@ -19,6 +19,7 @@ spec: {{- $_ := set . "globalAdditionalExprLabels" $.Values.global.additionalExprLabels }} {{- $_ := set . "globalAdditionalRuleLabels" $.Values.global.additionalRuleLabels }} {{- $_ := set . "defaultRunbookUrl" $.Values.defaultRunbookUrl }} +{{- $_ := set . "defaultKeepFiringFor" $.Values.defaultKeepFiringFor }} {{- $_ := set . "chartVersion" $.Chart.Version }} {{- include "chart.renderPrometheusRule" . | indent 8 -}} diff --git a/charts/_source/tests/prometheusRules_test.yaml b/charts/_source/tests/prometheusRules_test.yaml index f9873ae..d3c7dab 100644 --- a/charts/_source/tests/prometheusRules_test.yaml +++ b/charts/_source/tests/prometheusRules_test.yaml @@ -109,3 +109,23 @@ tests: - equal: path: metadata.labels.prometheus value: main + - it: render with additional additionalPrometheusRuleLabels + templates: + - prometheusRules.yaml + values: + - ./values/with_keepFiringFor.yaml + asserts: + - equal: + path: spec.groups[0].rules[0].expr + value: | + metric2{} > 100 + - equal: + path: spec.groups[0].rules[0].keep_firing_for + value: 2s + - equal: + path: spec.groups[0].rules[1].expr + value: | + metric1{} > 42 + - equal: + path: spec.groups[0].rules[1].keep_firing_for + value: 1s diff --git a/charts/_source/tests/values/with_keepFiringFor.yaml b/charts/_source/tests/values/with_keepFiringFor.yaml new file mode 100644 index 0000000..0b68625 --- /dev/null +++ b/charts/_source/tests/values/with_keepFiringFor.yaml @@ -0,0 +1,24 @@ +defaultKeepFiringFor: 1s + +rulesGroupName: unittest + +rules: + + RuleWithDefaultKeepFiringFor: + expr: metric1{} > 42 + for: 10m + labels: + priority: P1 + annotations: + summary: "Metric 1 is over 42" + description: "Metric1 is {{ $value }}" + + RuleWithCustomKeepFiringFor: + expr: metric2{} > 100 + for: 10m + keepFiringFor: 2s + labels: + priority: P1 + annotations: + summary: "Metric 1 is over 100" + description: "Metric2 is {{ $value }}" diff --git a/charts/_source/values.yaml b/charts/_source/values.yaml index 13e161c..1f03163 100644 --- a/charts/_source/values.yaml +++ b/charts/_source/values.yaml @@ -2,6 +2,8 @@ global: additionalExprLabels: [] additionalRuleLabels: {} +defaultKeepFiringFor: "" + format: PrometheusRuleCRD rulesGroupName: default diff --git a/charts/prometheus-postgresql-alerts/values.yaml b/charts/prometheus-postgresql-alerts/values.yaml index f7ea61b..4a6b367 100644 --- a/charts/prometheus-postgresql-alerts/values.yaml +++ b/charts/prometheus-postgresql-alerts/values.yaml @@ -3,7 +3,9 @@ global: format: PrometheusRuleCRD +defaultKeepFiringFor: "" defaultRunbookUrl: https://qonto.github.io/database-monitoring-framework/{{chartVersion}}/runbooks/postgresql/{{alertName}} + rulesGroupName: postgresql.rules rules: diff --git a/charts/prometheus-rds-alerts/values.yaml b/charts/prometheus-rds-alerts/values.yaml index 5d599d8..22adfae 100644 --- a/charts/prometheus-rds-alerts/values.yaml +++ b/charts/prometheus-rds-alerts/values.yaml @@ -3,7 +3,9 @@ global: format: PrometheusRuleCRD +defaultKeepFiringFor: "" defaultRunbookUrl: https://qonto.github.io/database-monitoring-framework/{{chartVersion}}/runbooks/rds/{{alertName}} + rulesGroupName: rds.rules additionalPrometheusRuleLabels: {}