From 0e014b859a32dbac944c3a173ecf29262b32ffed Mon Sep 17 00:00:00 2001 From: Stefan Kaes Date: Sat, 9 Dec 2023 10:03:08 +0100 Subject: [PATCH] prometheus-exporter: fixed a race condition --- go/Makefile | 2 +- go/prometheusexporter/collector/collector.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go/Makefile b/go/Makefile index 1fa7058..79b02a0 100644 --- a/go/Makefile +++ b/go/Makefile @@ -60,7 +60,7 @@ http-client-test: go test ./http-client promcollector-test: - go test ./prometheusexporter/... + go test -race ./prometheusexporter/... livestream-test: logjam-livestream go test ./livestream-server diff --git a/go/prometheusexporter/collector/collector.go b/go/prometheusexporter/collector/collector.go index 8f26dfa..ff30922 100644 --- a/go/prometheusexporter/collector/collector.go +++ b/go/prometheusexporter/collector/collector.go @@ -728,11 +728,6 @@ func (c *Collector) deleteLabels(name string, labels prometheus.Labels) bool { } func (c *Collector) copyWithoutActionLabel(a string) bool { - if c.opts.Verbose { - log.Info("removing action: %s", a) - } - delete(c.knownActions, a) - atomic.StoreInt32(&c.knownActionsSize, int32(len(c.knownActions))) mfs, err := c.registry.Gather() if err != nil { log.Error("could not gather metric families for deletion: %s", err) @@ -771,6 +766,11 @@ func (c *Collector) actionRegistryHandler() { threshold := time.Now().Add(-1 * time.Duration(c.opts.CleanAfter) * time.Minute) for a, v := range c.knownActions { if v.Before(threshold) { + if c.opts.Verbose { + log.Info("removing action: %s", a) + } + delete(c.knownActions, a) + atomic.StoreInt32(&c.knownActionsSize, int32(len(c.knownActions))) c.copyWithoutActionLabel(a) } }