You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Fix race in the lastvalue aggregation where 0 could be observed (#8056)
This initializes the value of the gauge with the correct value before it is stored in the map. We end up storing the same thing twice on the first call, but that isn't a big deal performance-wise. Discovered during https://github.com/open-telemetry/opentelemetry-go/pull/8021
This commit is contained in:
@@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
- Return spec-compliant `TraceIdRatioBased` description. This is a breaking behavioral change, but it is necessary to
|
- Return spec-compliant `TraceIdRatioBased` description. This is a breaking behavioral change, but it is necessary to
|
||||||
make the implementation [spec-compliant](https://opentelemetry.io/docs/specs/otel/trace/sdk/#traceidratiobased). (#8027)
|
make the implementation [spec-compliant](https://opentelemetry.io/docs/specs/otel/trace/sdk/#traceidratiobased). (#8027)
|
||||||
|
- Fix a race condition in `go.opentelemetry.io/otel/sdk/metric` where the lastvalue aggregation could collect the value 0 even when no zero-value measurements were recorded. (#8056)
|
||||||
|
|
||||||
<!-- Released section -->
|
<!-- Released section -->
|
||||||
<!-- Don't change this section unless doing release -->
|
<!-- Don't change this section unless doing release -->
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ func (s *lastValueMap[N]) measure(
|
|||||||
droppedAttr []attribute.KeyValue,
|
droppedAttr []attribute.KeyValue,
|
||||||
) {
|
) {
|
||||||
lv := s.values.LoadOrStoreAttr(fltrAttr, func(attr attribute.Set) any {
|
lv := s.values.LoadOrStoreAttr(fltrAttr, func(attr attribute.Set) any {
|
||||||
return &lastValuePoint[N]{
|
p := &lastValuePoint[N]{
|
||||||
res: s.newRes(attr),
|
res: s.newRes(attr),
|
||||||
attrs: attr,
|
attrs: attr,
|
||||||
}
|
}
|
||||||
|
p.value.Store(value)
|
||||||
|
return p
|
||||||
}).(*lastValuePoint[N])
|
}).(*lastValuePoint[N])
|
||||||
|
|
||||||
lv.value.Store(value)
|
lv.value.Store(value)
|
||||||
|
|||||||
@@ -490,9 +490,6 @@ func validateGauge[N int64 | float64](t *testing.T, aggs []metricdata.Aggregatio
|
|||||||
for _, v := range getConcurrentVals[N]() {
|
for _, v := range getConcurrentVals[N]() {
|
||||||
valid[v] = true
|
valid[v] = true
|
||||||
}
|
}
|
||||||
// TODO(dashpole): Fix a concurrency bug where a gauge can be collected with
|
|
||||||
// the value zero even when no zero-value measurements have been recorded.
|
|
||||||
valid[0] = true
|
|
||||||
|
|
||||||
for _, agg := range aggs {
|
for _, agg := range aggs {
|
||||||
s, ok := agg.(metricdata.Gauge[N])
|
s, ok := agg.(metricdata.Gauge[N])
|
||||||
|
|||||||
Reference in New Issue
Block a user