Skip to content

Commit 4adf2c7

Browse files
committed
feat(helm): Add defaultKeepFiringFor and keepFiringFor parameters to configure keep_firing_for attribute
1 parent a631f4f commit 4adf2c7

File tree

8 files changed

+56
-0
lines changed

8 files changed

+56
-0
lines changed

charts/_source/templates/_helpers.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Render Prometheus rule
7171
{{- $name := .name -}}
7272
{{- $pintComments := default dict .pintComments -}}
7373
{{- $for := .for -}}
74+
{{- $keepFiringFor := default .defaultKeepFiringFor .keepFiringFor -}}
7475
{{- $ruleLabels := .labels -}}
7576
{{- $record := .record -}}
7677
{{- $annotations := default dict .annotations -}}
@@ -112,6 +113,9 @@ Render Prometheus rule
112113
{{- if $for }}
113114
for: {{ $for }}
114115
{{- end }}
116+
{{- if $keepFiringFor }}
117+
keep_firing_for: {{ $keepFiringFor }}
118+
{{- end }}
115119
{{- if $labels }}
116120
labels:
117121
{{ $labels | toYaml | indent 4 }}

charts/_source/templates/prometheusConfiguration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ groups:
77
{{- $_ := set . "globalAdditionalExprLabels" $.Values.global.additionalExprLabels }}
88
{{- $_ := set . "globalAdditionalRuleLabels" $.Values.global.additionalRuleLabels }}
99
{{- $_ := set . "defaultRunbookUrl" $.Values.defaultRunbookUrl }}
10+
{{- $_ := set . "defaultKeepFiringFor" $.Values.defaultKeepFiringFor }}
1011
{{- $_ := set . "chartVersion" $.Chart.Version }}
1112

1213
{{- include "chart.renderPrometheusRule" . | indent 8 -}}

charts/_source/templates/prometheusRules.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ spec:
1919
{{- $_ := set . "globalAdditionalExprLabels" $.Values.global.additionalExprLabels }}
2020
{{- $_ := set . "globalAdditionalRuleLabels" $.Values.global.additionalRuleLabels }}
2121
{{- $_ := set . "defaultRunbookUrl" $.Values.defaultRunbookUrl }}
22+
{{- $_ := set . "defaultKeepFiringFor" $.Values.defaultKeepFiringFor }}
2223
{{- $_ := set . "chartVersion" $.Chart.Version }}
2324

2425
{{- include "chart.renderPrometheusRule" . | indent 8 -}}

charts/_source/tests/prometheusRules_test.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,23 @@ tests:
109109
- equal:
110110
path: metadata.labels.prometheus
111111
value: main
112+
- it: render with additional additionalPrometheusRuleLabels
113+
templates:
114+
- prometheusRules.yaml
115+
values:
116+
- ./values/with_keepFiringFor.yaml
117+
asserts:
118+
- equal:
119+
path: spec.groups[0].rules[0].expr
120+
value: |
121+
metric2{} > 100
122+
- equal:
123+
path: spec.groups[0].rules[0].keep_firing_for
124+
value: 2s
125+
- equal:
126+
path: spec.groups[0].rules[1].expr
127+
value: |
128+
metric1{} > 42
129+
- equal:
130+
path: spec.groups[0].rules[1].keep_firing_for
131+
value: 1s
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
defaultKeepFiringFor: 1s
2+
3+
rulesGroupName: unittest
4+
5+
rules:
6+
7+
RuleWithDefaultKeepFiringFor:
8+
expr: metric1{} > 42
9+
for: 10m
10+
labels:
11+
priority: P1
12+
annotations:
13+
summary: "Metric 1 is over 42"
14+
description: "Metric1 is {{ $value }}"
15+
16+
RuleWithCustomKeepFiringFor:
17+
expr: metric2{} > 100
18+
for: 10m
19+
keepFiringFor: 2s
20+
labels:
21+
priority: P1
22+
annotations:
23+
summary: "Metric 1 is over 100"
24+
description: "Metric2 is {{ $value }}"

charts/_source/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ global:
22
additionalExprLabels: []
33
additionalRuleLabels: {}
44

5+
defaultKeepFiringFor: ""
6+
57
format: PrometheusRuleCRD
68

79
rulesGroupName: default

charts/prometheus-postgresql-alerts/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ global:
33

44
format: PrometheusRuleCRD
55

6+
defaultKeepFiringFor: ""
67
defaultRunbookUrl: https://qonto.github.io/database-monitoring-framework/{{chartVersion}}/runbooks/postgresql/{{alertName}}
8+
79
rulesGroupName: postgresql.rules
810

911
rules:

charts/prometheus-rds-alerts/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ global:
33

44
format: PrometheusRuleCRD
55

6+
defaultKeepFiringFor: ""
67
defaultRunbookUrl: https://qonto.github.io/database-monitoring-framework/{{chartVersion}}/runbooks/rds/{{alertName}}
8+
79
rulesGroupName: rds.rules
810

911
additionalPrometheusRuleLabels: {}

0 commit comments

Comments
 (0)