Skip to content

Commit

Permalink
Adjust alertmanager silence partial to be more flexible
Browse files Browse the repository at this point in the history
This change allows us to reuse the job partial to create a silence for
all alerts with `syn=true` if the `argo_app` macro is unset or empty.
  • Loading branch information
simu committed Oct 16, 2023
1 parent 174ec30 commit 7c4ecf8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions docs/modules/ROOT/partials/alertmanager-silence-job.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[source,bash,subs="attributes+"]
----
if [[ "$OSTYPE" == "darwin"* ]]; then alias date=gdate; fi
job_name=$(printf "{http-method}-silence-{argo_app}-alerts-$(date +%s)" | tr '[:upper:]' '[:lower:]')
job_name=$(printf "{http-method}-silence-{silence-target}-alerts-$(date +%s)" | tr '[:upper:]' '[:lower:]')
ifeval::["{http-method}" == "POST"]
silence_duration='{duration}' <1>
endif::[]
Expand All @@ -11,7 +11,7 @@ kind: Job
metadata:
name: ${job_name}
labels:
app: silence-{argo_app}-alerts
app: silence-{silence-target}-alerts
spec:
backoffLimit: 0
template:
Expand All @@ -29,16 +29,25 @@ ifeval::["{http-method}" == "POST"]
read -d "" body << EOF
{
"matchers": [
ifeval::["{argo_app}" != ""]
{
"name": "syn_component",
"value": "{argo_app}",
"isRegex": false
}
endif::[]
ifeval::["{argo_app}" == ""]
{
"name": "syn",
"value": "true",
"isRegex": false
}
endif::[]
],
"startsAt": "$(date -u +'%Y-%m-%dT%H:%M:%S')",
"endsAt": "$(date -u +'%Y-%m-%dT%H:%M:%S' --date "${silence_duration}")",
"createdBy": "$(kubectl config current-context | cut -d/ -f3)",
"comment": "Silence all {argo_app} alerts"
"comment": "Silence {silence-target} alerts"
}
EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the list flow.
:http-method: POST
:alertmanager-endpoint: /api/v2/silences
:silence-target: {argo_app}

. Set a silence in Alertmanager for all {argo_app} alerts
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the list flow.
:http-method: DELETE
:alertmanager-endpoint: /api/v2/silence/${silence_id}
:silence-target: {argo_app}

. Remove silence in Alertmanager
+
Expand Down

0 comments on commit 7c4ecf8

Please sign in to comment.