Merge pull request #2657 from jsternberg/metricwriter-race-condition

metrics: add mutex to the metric writer
This commit is contained in:
Tõnis Tiigi 2024-08-14 19:23:51 +03:00 committed by GitHub
commit 8411a763d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 0 deletions

View File

@ -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 {
@ -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)
}