mirror of https://github.com/docker/buildx.git
metrics: add mutex to the metric writer
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 <jonathan.sternberg@docker.com>
This commit is contained in:
parent
0e64eb4f8b
commit
6c5279da54
|
@ -45,6 +45,7 @@ var re = sync.OnceValue(func() *rePatterns {
|
||||||
type metricWriter struct {
|
type metricWriter struct {
|
||||||
recorders []metricRecorder
|
recorders []metricRecorder
|
||||||
attrs attribute.Set
|
attrs attribute.Set
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
|
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) {
|
func (mw *metricWriter) Write(ss *client.SolveStatus) {
|
||||||
|
mw.mu.Lock()
|
||||||
|
defer mw.mu.Unlock()
|
||||||
|
|
||||||
for _, recorder := range mw.recorders {
|
for _, recorder := range mw.recorders {
|
||||||
recorder.Record(ss)
|
recorder.Record(ss)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue