Skip to content

Commit 2420147

Browse files
committed
(fleet/prometheus-alerts) set up gitops for alert deployment
This allows for prometheus rules to be automagically applied through rancher fleet. Simply adding some rules to the fleet directory will deploy them into the cluster, ready for the prometheus operator to pick them up and deploy.
1 parent 9500d0b commit 2420147

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
appVersion: 0.0.0
3+
description: Prometheus LSST rules GitOps
4+
name: prometheus-alerts
5+
version: 0.0.0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Prometheus rules GitOps
2+
3+
Any Prometheus rules file defined in the `/rules` directory will be deployed to
4+
the cluster. It's possible to define a default namespace in the `values.yaml`
5+
file with the `rules.namespace` key.
6+
7+
## Adding Prometheus rules
8+
9+
1. Write the Prometheus rules in a yaml file according to the [prometheus
10+
specification](https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/).
11+
1. Add the YAML file to the `/rules` directory
12+
1. Commit
13+
14+
## Prometheus rule AURA standards
15+
16+
* `summary` annotation: The `summary` annotation is used to be able to describe a
17+
group of alerts incomming. This annotation DOES NOT contain any templated
18+
variables and provides a simple single sentence summary of what the alert is
19+
about. For example "Disk space full in 24h". When a cluster triggers several
20+
alerts, it can be hany to group these alerts into a single notification, this
21+
is when the `summary` can be used.
22+
* `discription` annotation: This provides a detailed overview of the alert
23+
specifically to this instance of the alert. It MAY contain templated variables
24+
to enrich the message.
25+
* `receiver` label: The receiver label is used by alertmanager to decide on the
26+
routing of the notification for the alert. It exists out of `,` seperated list
27+
of receivers, pre- and suffixed with `,` to make regex matching easier in the
28+
alertmanager. For example: `,slack,squadcast,email,` The receivers are defined
29+
in the alertmanager configuration.
30+
Currently (20240503) the following receivers are configured:
31+
* `slack-test`
32+
* `squadcast-test`
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
defaultNamespace: &name prometheus-alerts
3+
labels:
4+
bundle: *name
5+
namespaceLabels:
6+
lsst.io/discover: "true"
7+
helm:
8+
releaseName: *name
9+
takeOwnership: true
10+
waitForJobs: true
11+
dependsOn:
12+
- selector:
13+
matchLabels:
14+
bundle: prometheus-operator-crds
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# yamllint disable-file
2+
{{- if .Values.rules.enabled }}
3+
{{- $files := .Files.Glob "rules/**.yaml" }}
4+
{{- range $rawpath, $content := $files }}
5+
{{- $path := ($rawpath | lower | replace " " "-") }}
6+
{{- $ruleDir := dir $path }}
7+
{{- $ruleFile := base $path }}
8+
{{- $namespaceSplit := regexSplit "\\/+" $ruleDir -1 }}
9+
{{- $namespace := $.Values.rules.namespace | default $.Release.Namespace }}
10+
{{- if (eq (len $namespaceSplit) 2) }}
11+
{{- $namespace = (index $namespaceSplit 1) }}
12+
{{- end }}
13+
{{- $alertName := lower (index (regexSplit "\\.yaml" $ruleFile -1) 0) }}
14+
---
15+
apiVersion: monitoring.coreos.com/v1
16+
kind: PrometheusRule
17+
metadata:
18+
name: {{ printf "%s-%s" "alert" $alertName | trunc 63 | trimSuffix "-" }}
19+
namespace: {{ $namespace }}
20+
labels:
21+
lsst.io/component: "prometheus-rules"
22+
lsst.io/dir: {{ $ruleDir | quote }}
23+
lsst.io/file: {{ $ruleFile | quote }}
24+
{{- with $.Values.rules.additionalLabels }}
25+
{{- toYaml . | nindent 4 }}
26+
{{- end }}
27+
{{- with $.Values.rules.additionalAnnotations }}
28+
annotations:
29+
{{- toYaml . | nindent 4 }}
30+
{{- end }}
31+
spec:
32+
{{ $content | toString }}
33+
{{ end }}
34+
{{ end }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
rules:
3+
enabled: true
4+
namespace: ~
5+
additionalAnnotations: {}
6+
additionalLabels:
7+
lsst.io/rule: "true"

0 commit comments

Comments
 (0)