From de5429201be6920d8f7fdda0b0a9029ffab7bac1 Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:02:54 +0100 Subject: [PATCH] Use slices to exclude metrics --- collectors/cpustatMetric.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/collectors/cpustatMetric.go b/collectors/cpustatMetric.go index 50c322a..d66f957 100644 --- a/collectors/cpustatMetric.go +++ b/collectors/cpustatMetric.go @@ -12,6 +12,7 @@ import ( "encoding/json" "fmt" "os" + "slices" "strconv" "strings" "time" @@ -43,8 +44,13 @@ func (m *CpustatCollector) Init(config json.RawMessage) error { return fmt.Errorf("%s Init(): setup() call failed: %w", m.name, err) } m.parallel = true - m.meta = map[string]string{"source": m.name, "group": "CPU"} - m.nodetags = map[string]string{"type": "node"} + m.meta = map[string]string{ + "source": m.name, + "group": "CPU", + } + m.nodetags = map[string]string{ + "type": "node", + } if len(config) > 0 { err := json.Unmarshal(config, &m.config) if err != nil { @@ -66,14 +72,7 @@ func (m *CpustatCollector) Init(config json.RawMessage) error { m.matches = make(map[string]int) for match, index := range matches { - doExclude := false - for _, exclude := range m.config.ExcludeMetrics { - if match == exclude { - doExclude = true - break - } - } - if !doExclude { + if !slices.Contains(m.config.ExcludeMetrics, match) { m.matches[match] = index } }