From e1cec6aa3ec3e276acc268e1745857004d88c1e3 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Tue, 3 Oct 2023 15:31:30 +0200 Subject: [PATCH] Make alert routing discovery output easier to review (#184) Sorts and deduplicates the namespaces. --- component/alert-routing-discovery.libsonnet | 13 ++++++++----- .../10_alertmanager_config.yaml | 4 ++-- .../99_discovery_debug_cm.yaml | 10 +++++----- tests/team-routing.yml | 1 + 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/component/alert-routing-discovery.libsonnet b/component/alert-routing-discovery.libsonnet index a45a8479..188d92c4 100644 --- a/component/alert-routing-discovery.libsonnet +++ b/component/alert-routing-discovery.libsonnet @@ -40,11 +40,14 @@ local ownerOrFallbackTeam = params.openshift4_monitoring.fallback_team; // teamToNS is a map from a team to namespaces. -local teamToNS = std.foldl( - function(prev, app) - prev { [prom.teamForApplication(app)]+: [ discoverNS(app) ] }, - inv.applications, - {} +local teamToNS = std.mapWithKey( + function(_, a) std.uniq(std.sort(std.prune(a))), + std.foldl( + function(prev, app) + prev { [prom.teamForApplication(app)]+: [ discoverNS(app) ] }, + inv.applications, + {} + ) ); // teamBasedRouting contains discovered routes for teams. diff --git a/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/10_alertmanager_config.yaml b/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/10_alertmanager_config.yaml index 45ddc410..c011ad8a 100644 --- a/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/10_alertmanager_config.yaml +++ b/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/10_alertmanager_config.yaml @@ -43,7 +43,7 @@ stringData: - "continue": true "matchers": - "syn_team = \"\"" - - "namespace =~ \"ns-string|same-ns\"" + - "namespace =~ \"ns-string\"" "receiver": "team_default_clumsy-donkeys" - "continue": true "matchers": @@ -53,7 +53,7 @@ stringData: - "continue": false "matchers": - "syn_team = \"\"" - - "namespace =~ \"base|overridden|ns-string|same-ns|ns-object|same-ns\"" + - "namespace =~ \"base|overridden|ns-string|ns-object|same-ns\"" "receiver": "__component_openshift4_monitoring_null" - "matchers": - "other = \"true\"" diff --git a/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/99_discovery_debug_cm.yaml b/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/99_discovery_debug_cm.yaml index 3cd8f160..8a94f1bc 100644 --- a/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/99_discovery_debug_cm.yaml +++ b/tests/golden/team-routing/openshift4-monitoring/openshift4-monitoring/99_discovery_debug_cm.yaml @@ -35,7 +35,7 @@ data: - "continue": true "matchers": - "syn_team = \"\"" - - "namespace =~ \"ns-string|same-ns\"" + - "namespace =~ \"ns-string\"" "receiver": "team_default_clumsy-donkeys" - "continue": true "matchers": @@ -45,7 +45,7 @@ data: - "continue": false "matchers": - "syn_team = \"\"" - - "namespace =~ \"base|overridden|ns-string|same-ns|ns-object|same-ns\"" + - "namespace =~ \"base|overridden|ns-string|ns-object|same-ns\"" "receiver": "__component_openshift4_monitoring_null" - "matchers": - "other = \"true\"" @@ -75,7 +75,7 @@ data: "non-existing as still-non-existing": "clumsy-donkeys" "ns-object": "lovable-lizards" "ns-string": "clumsy-donkeys" - "same-ns-1": "clumsy-donkeys" + "same-ns-1": "lovable-lizards" "same-ns-2": "lovable-lizards" proposed_routes: |- - "continue": true @@ -86,7 +86,7 @@ data: - "continue": true "matchers": - "syn_team = \"\"" - - "namespace =~ \"ns-string|same-ns\"" + - "namespace =~ \"ns-string\"" "receiver": "team_default_clumsy-donkeys" - "continue": true "matchers": @@ -96,7 +96,7 @@ data: - "continue": false "matchers": - "syn_team = \"\"" - - "namespace =~ \"base|overridden|ns-string|same-ns|ns-object|same-ns\"" + - "namespace =~ \"base|overridden|ns-string|ns-object|same-ns\"" "receiver": "__component_openshift4_monitoring_null" kind: ConfigMap metadata: diff --git a/tests/team-routing.yml b/tests/team-routing.yml index 4d07d7d3..39cf0a9b 100644 --- a/tests/team-routing.yml +++ b/tests/team-routing.yml @@ -31,6 +31,7 @@ parameters: lovable-lizards: instances: - ns-object + - same-ns-1 - same-ns-2 - ns-in-base - ~ns-in-base