Skip to content

Commit

Permalink
Fix output exponential histogram negative buckets (#4956)
Browse files Browse the repository at this point in the history
* Fix output exponential histogram buckets

* Update CHANGELOG
  • Loading branch information
ericayin authored Feb 22, 2024
1 parent 8df89f6 commit 27e495d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The next release will require at least [Go 1.21].
### Fixed

- Fix registration of multiple callbacks when using the global meter provider from `go.opentelemetry.io/otel`. (#4945)
- Fix negative buckets in output of exponential histograms. (#4956)

## [1.23.1] 2024-02-07

Expand Down
2 changes: 2 additions & 0 deletions sdk/metric/internal/aggregate/exponential_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func (e *expoHistogram[N]) delta(dest *metricdata.Aggregation) int {

hDPts[i].NegativeBucket.Offset = int32(b.negBuckets.startBin)
hDPts[i].NegativeBucket.Counts = reset(hDPts[i].NegativeBucket.Counts, len(b.negBuckets.counts), len(b.negBuckets.counts))
copy(hDPts[i].NegativeBucket.Counts, b.negBuckets.counts)

if !e.noSum {
hDPts[i].Sum = b.sum
Expand Down Expand Up @@ -425,6 +426,7 @@ func (e *expoHistogram[N]) cumulative(dest *metricdata.Aggregation) int {

hDPts[i].NegativeBucket.Offset = int32(b.negBuckets.startBin)
hDPts[i].NegativeBucket.Counts = reset(hDPts[i].NegativeBucket.Counts, len(b.negBuckets.counts), len(b.negBuckets.counts))
copy(hDPts[i].NegativeBucket.Counts, b.negBuckets.counts)

if !e.noSum {
hDPts[i].Sum = b.sum
Expand Down
63 changes: 45 additions & 18 deletions sdk/metric/internal/aggregate/exponential_histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
{ctx, 2, alice},
{ctx, 16, alice},
{ctx, 1, alice},
{ctx, -1, alice},
},
expect: output{
n: 1,
Expand All @@ -781,15 +782,19 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Count: 6,
Min: metricdata.NewExtrema[N](1),
Count: 7,
Min: metricdata.NewExtrema[N](-1),
Max: metricdata.NewExtrema[N](16),
Sum: 31,
Sum: 30,
Scale: -1,
PositiveBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1, 4, 1},
},
NegativeBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1},
},
},
},
},
Expand Down Expand Up @@ -821,6 +826,7 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
{ctx, 2, carol},
{ctx, 16, carol},
{ctx, 1, dave},
{ctx, -1, alice},
},
expect: output{
n: 2,
Expand All @@ -831,15 +837,19 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Count: 6,
Min: metricdata.NewExtrema[N](1),
Count: 7,
Min: metricdata.NewExtrema[N](-1),
Max: metricdata.NewExtrema[N](16),
Sum: 31,
Sum: 30,
Scale: -1,
PositiveBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1, 4, 1},
},
NegativeBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1},
},
},
{
Attributes: overflowSet,
Expand Down Expand Up @@ -888,6 +898,7 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
{ctx, 2, alice},
{ctx, 16, alice},
{ctx, 1, alice},
{ctx, -1, alice},
},
expect: output{
n: 1,
Expand All @@ -898,15 +909,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Count: 6,
Min: metricdata.NewExtrema[N](1),
Count: 7,
Min: metricdata.NewExtrema[N](-1),
Max: metricdata.NewExtrema[N](16),
Sum: 31,
Sum: 30,
Scale: -1,
PositiveBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1, 4, 1},
},
NegativeBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1},
},
},
},
},
Expand All @@ -927,15 +942,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Count: 9,
Min: metricdata.NewExtrema[N](1),
Count: 10,
Min: metricdata.NewExtrema[N](-1),
Max: metricdata.NewExtrema[N](16),
Sum: 44,
Sum: 43,
Scale: -1,
PositiveBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1, 6, 2},
},
NegativeBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1},
},
},
},
},
Expand All @@ -952,15 +971,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Count: 9,
Min: metricdata.NewExtrema[N](1),
Count: 10,
Min: metricdata.NewExtrema[N](-1),
Max: metricdata.NewExtrema[N](16),
Sum: 44,
Sum: 43,
Scale: -1,
PositiveBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1, 6, 2},
},
NegativeBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1},
},
},
},
},
Expand All @@ -985,15 +1008,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
Attributes: fltrAlice,
StartTime: staticTime,
Time: staticTime,
Count: 9,
Min: metricdata.NewExtrema[N](1),
Count: 10,
Min: metricdata.NewExtrema[N](-1),
Max: metricdata.NewExtrema[N](16),
Sum: 44,
Sum: 43,
Scale: -1,
PositiveBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1, 6, 2},
},
NegativeBucket: metricdata.ExponentialBucket{
Offset: -1,
Counts: []uint64{1},
},
},
{
Attributes: overflowSet,
Expand Down

0 comments on commit 27e495d

Please sign in to comment.