Skip to content

Commit

Permalink
prometheus-exporter: fixed a race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
skaes committed Dec 9, 2023
1 parent 4527e70 commit 0e014b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions go/prometheusexporter/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 0e014b8

Please sign in to comment.