Skip to content

Commit

Permalink
Prune fields with null values in user-provided Alertmanager config
Browse files Browse the repository at this point in the history
This allows us to gradually roll out Alertmanager configs with new
fields set (e.g. `opsgenie_configs.source` in a receiver config) even
though the receiver config is formatted as a list which isn't easily
editable in the hierarchy.
  • Loading branch information
simu committed Jan 3, 2024
1 parent 8bf4b7f commit e13c156
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion component/alert-routing-discovery.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ local teamBasedRouting = std.map(

local alertmanagerConfig =
local routes = std.get(params.openshift4_monitoring.alertManagerConfig.route, 'routes', []);
params.openshift4_monitoring.alertManagerConfig {
std.prune(params.openshift4_monitoring.alertManagerConfig) {
receivers+: [ { name: nullReceiver } ],
route+: {
routes: adParams.prepend_routes + teamBasedRouting + adParams.append_routes + routes + if ownerOrFallbackTeam != null then [ {
Expand Down
2 changes: 2 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ A dictionary holding the configuration for the AlertManager.

See the https://docs.openshift.com/container-platform/latest/monitoring/managing-alerts.html#applying-custom-alertmanager-configuration_managing-alerts[OpenShift docs] for available parameters.

The component will silently drop any fields in the provided config which are empty.
The component treats `null` as empty for scalar fields.

== `alertManagerAutoDiscovery`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ stringData:
"target_match_re":
"severity": "info"
"receivers":
- "name": "foo"
- "name": "__component_openshift4_monitoring_null"
"route":
"group_interval": "5s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data:
"target_match_re":
"severity": "info"
"receivers":
- "name": "foo"
- "name": "__component_openshift4_monitoring_null"
"route":
"group_interval": "5s"
Expand Down
4 changes: 4 additions & 0 deletions tests/team-routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ parameters:

openshift4_monitoring:
alertManagerConfig:
receivers:
- name: foo
opsgenie_configs:
- source: null
route:
routes:
- receiver: other
Expand Down

0 comments on commit e13c156

Please sign in to comment.