From c1195f9aabc0043cde6857e6f23b283e836e9f5f Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Sat, 27 Jan 2024 17:28:15 +0100 Subject: [PATCH] chore: dont rely on slice labels (#184) Signed-off-by: Michael Hoffmann --- injectproxy/rules.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/injectproxy/rules.go b/injectproxy/rules.go index 30ac5148..4d11570f 100644 --- a/injectproxy/rules.go +++ b/injectproxy/rules.go @@ -207,11 +207,8 @@ func (r *routes) filterRules(lvalues []string, resp *apiResponse) (interface{}, for _, rg := range rgs.RuleGroups { var rules []rule for _, rule := range rg.Rules { - for _, lbl := range rule.Labels() { - if lbl.Name == r.label && slices.Contains(lvalues, lbl.Value) { - rules = append(rules, rule) - break - } + if lval := rule.Labels().Get(r.label); lval != "" && slices.Contains(lvalues, lval) { + rules = append(rules, rule) } } if len(rules) > 0 { @@ -231,11 +228,8 @@ func (r *routes) filterAlerts(lvalues []string, resp *apiResponse) (interface{}, filtered := []*alert{} for _, alert := range data.Alerts { - for _, lbl := range alert.Labels { - if lbl.Name == r.label && slices.Contains(lvalues, lbl.Value) { - filtered = append(filtered, alert) - break - } + if lval := alert.Labels.Get(r.label); lval != "" && slices.Contains(lvalues, lval) { + filtered = append(filtered, alert) } }