Skip to content

Commit

Permalink
Minor refactoring: Use func params instead of global state
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich committed Jan 5, 2021
1 parent f88faa0 commit 2f9c03f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions config/struct_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type NamespaceConfig struct {

OrderedLabelNames []string
OrderedLabelValues []string

HasCounterOnlyLabels bool
}

type SourceData struct {
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f9c03f

Please sign in to comment.