From 2f9c03f065ca75e04a4fe49a88ad17c4292a4631 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Tue, 5 Jan 2021 14:00:49 +0100 Subject: [PATCH] Minor refactoring: Use func params instead of global state --- config/struct_namespace.go | 2 -- main.go | 9 +++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config/struct_namespace.go b/config/struct_namespace.go index 754e463..da76224 100644 --- a/config/struct_namespace.go +++ b/config/struct_namespace.go @@ -28,8 +28,6 @@ type NamespaceConfig struct { OrderedLabelNames []string OrderedLabelValues []string - - HasCounterOnlyLabels bool } type SourceData struct { diff --git a/main.go b/main.go index 78f1408..4e46239 100644 --- a/main.go +++ b/main.go @@ -334,20 +334,21 @@ func processNamespace(nsCfg config.NamespaceConfig, metrics *Metrics) { } // determine once if there are any relabeling configurations for only the response counter + hasCounterOnlyLabels := false for _, r := range nsCfg.RelabelConfigs { if r.OnlyCounter { - nsCfg.HasCounterOnlyLabels = true + hasCounterOnlyLabels = true break } } for _, f := range followers { - go processSource(nsCfg, f, parser, metrics) + go processSource(nsCfg, f, parser, metrics, hasCounterOnlyLabels) } } -func processSource(nsCfg config.NamespaceConfig, t tail.Follower, parser *gonx.Parser, metrics *Metrics) { +func processSource(nsCfg config.NamespaceConfig, t tail.Follower, parser *gonx.Parser, metrics *Metrics, hasCounterOnlyLabels bool) { relabelings := relabeling.NewRelabelings(nsCfg.RelabelConfigs) relabelings = append(relabelings, relabeling.DefaultRelabelings...) relabelings = relabeling.UniqueRelabelings(relabelings) @@ -386,7 +387,7 @@ func processSource(nsCfg config.NamespaceConfig, t tail.Follower, parser *gonx.P } var notCounterValues []string - if nsCfg.HasCounterOnlyLabels { + if hasCounterOnlyLabels { notCounterValues = relabeling.StripOnlyCounterValues(labelValues, relabelings) } else { notCounterValues = labelValues