Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters to customize keep_firing_for Prometheus rule #23

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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