Skip to content

Commit

Permalink
metrics: add mutex to the metric writer
Browse files Browse the repository at this point in the history
It was possible for multiple status messages to be written at the same
time which caused some of the metric writer code to have a race
condition.

This code should be fast enough that it doesn't interrupt the display,
but some further work might be needed here.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
  • Loading branch information
jsternberg committed Aug 14, 2024
1 parent 0e64eb4 commit 6c5279d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions util/progress/metricwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var re = sync.OnceValue(func() *rePatterns {
type metricWriter struct {
recorders []metricRecorder
attrs attribute.Set
mu sync.Mutex
}

func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
Expand All @@ -63,6 +64,9 @@ func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
}

func (mw *metricWriter) Write(ss *client.SolveStatus) {
mw.mu.Lock()
defer mw.mu.Unlock()

for _, recorder := range mw.recorders {
recorder.Record(ss)
}
Expand Down

0 comments on commit 6c5279d

Please sign in to comment.