Skip to content

Commit

Permalink
feat(helm): Add defaultKeepFiringFor and keepFiringFor parameters to …
Browse files Browse the repository at this point in the history
…configure keep_firing_for attribute
  • Loading branch information
vmercierfr committed Jan 5, 2024
1 parent a631f4f commit 4adf2c7
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions charts/_source/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions charts/_source/templates/prometheusConfiguration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
1 change: 1 addition & 0 deletions charts/_source/templates/prometheusRules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
20 changes: 20 additions & 0 deletions charts/_source/tests/prometheusRules_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions charts/_source/tests/values/with_keepFiringFor.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 2 additions & 0 deletions charts/_source/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ global:
additionalExprLabels: []
additionalRuleLabels: {}

defaultKeepFiringFor: ""

format: PrometheusRuleCRD

rulesGroupName: default
Expand Down
2 changes: 2 additions & 0 deletions charts/prometheus-postgresql-alerts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ global:

format: PrometheusRuleCRD

defaultKeepFiringFor: ""
defaultRunbookUrl: https://qonto.github.io/database-monitoring-framework/{{chartVersion}}/runbooks/postgresql/{{alertName}}

rulesGroupName: postgresql.rules

rules:
Expand Down
2 changes: 2 additions & 0 deletions charts/prometheus-rds-alerts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ global:

format: PrometheusRuleCRD

defaultKeepFiringFor: ""
defaultRunbookUrl: https://qonto.github.io/database-monitoring-framework/{{chartVersion}}/runbooks/rds/{{alertName}}

rulesGroupName: rds.rules

additionalPrometheusRuleLabels: {}
Expand Down

0 comments on commit 4adf2c7

Please sign in to comment.