Skip to content

Commit 27e495d

Browse files
authored
Fix output exponential histogram negative buckets (#4956)
* Fix output exponential histogram buckets * Update CHANGELOG
1 parent 8df89f6 commit 27e495d

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The next release will require at least [Go 1.21].
2020
### Fixed
2121

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

2425
## [1.23.1] 2024-02-07
2526

sdk/metric/internal/aggregate/exponential_histogram.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ func (e *expoHistogram[N]) delta(dest *metricdata.Aggregation) int {
375375

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

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

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

429431
if !e.noSum {
430432
hDPts[i].Sum = b.sum

sdk/metric/internal/aggregate/exponential_histogram_test.go

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
771771
{ctx, 2, alice},
772772
{ctx, 16, alice},
773773
{ctx, 1, alice},
774+
{ctx, -1, alice},
774775
},
775776
expect: output{
776777
n: 1,
@@ -781,15 +782,19 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
781782
Attributes: fltrAlice,
782783
StartTime: staticTime,
783784
Time: staticTime,
784-
Count: 6,
785-
Min: metricdata.NewExtrema[N](1),
785+
Count: 7,
786+
Min: metricdata.NewExtrema[N](-1),
786787
Max: metricdata.NewExtrema[N](16),
787-
Sum: 31,
788+
Sum: 30,
788789
Scale: -1,
789790
PositiveBucket: metricdata.ExponentialBucket{
790791
Offset: -1,
791792
Counts: []uint64{1, 4, 1},
792793
},
794+
NegativeBucket: metricdata.ExponentialBucket{
795+
Offset: -1,
796+
Counts: []uint64{1},
797+
},
793798
},
794799
},
795800
},
@@ -821,6 +826,7 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
821826
{ctx, 2, carol},
822827
{ctx, 16, carol},
823828
{ctx, 1, dave},
829+
{ctx, -1, alice},
824830
},
825831
expect: output{
826832
n: 2,
@@ -831,15 +837,19 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) {
831837
Attributes: fltrAlice,
832838
StartTime: staticTime,
833839
Time: staticTime,
834-
Count: 6,
835-
Min: metricdata.NewExtrema[N](1),
840+
Count: 7,
841+
Min: metricdata.NewExtrema[N](-1),
836842
Max: metricdata.NewExtrema[N](16),
837-
Sum: 31,
843+
Sum: 30,
838844
Scale: -1,
839845
PositiveBucket: metricdata.ExponentialBucket{
840846
Offset: -1,
841847
Counts: []uint64{1, 4, 1},
842848
},
849+
NegativeBucket: metricdata.ExponentialBucket{
850+
Offset: -1,
851+
Counts: []uint64{1},
852+
},
843853
},
844854
{
845855
Attributes: overflowSet,
@@ -888,6 +898,7 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
888898
{ctx, 2, alice},
889899
{ctx, 16, alice},
890900
{ctx, 1, alice},
901+
{ctx, -1, alice},
891902
},
892903
expect: output{
893904
n: 1,
@@ -898,15 +909,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
898909
Attributes: fltrAlice,
899910
StartTime: staticTime,
900911
Time: staticTime,
901-
Count: 6,
902-
Min: metricdata.NewExtrema[N](1),
912+
Count: 7,
913+
Min: metricdata.NewExtrema[N](-1),
903914
Max: metricdata.NewExtrema[N](16),
904-
Sum: 31,
915+
Sum: 30,
905916
Scale: -1,
906917
PositiveBucket: metricdata.ExponentialBucket{
907918
Offset: -1,
908919
Counts: []uint64{1, 4, 1},
909920
},
921+
NegativeBucket: metricdata.ExponentialBucket{
922+
Offset: -1,
923+
Counts: []uint64{1},
924+
},
910925
},
911926
},
912927
},
@@ -927,15 +942,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
927942
Attributes: fltrAlice,
928943
StartTime: staticTime,
929944
Time: staticTime,
930-
Count: 9,
931-
Min: metricdata.NewExtrema[N](1),
945+
Count: 10,
946+
Min: metricdata.NewExtrema[N](-1),
932947
Max: metricdata.NewExtrema[N](16),
933-
Sum: 44,
948+
Sum: 43,
934949
Scale: -1,
935950
PositiveBucket: metricdata.ExponentialBucket{
936951
Offset: -1,
937952
Counts: []uint64{1, 6, 2},
938953
},
954+
NegativeBucket: metricdata.ExponentialBucket{
955+
Offset: -1,
956+
Counts: []uint64{1},
957+
},
939958
},
940959
},
941960
},
@@ -952,15 +971,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
952971
Attributes: fltrAlice,
953972
StartTime: staticTime,
954973
Time: staticTime,
955-
Count: 9,
956-
Min: metricdata.NewExtrema[N](1),
974+
Count: 10,
975+
Min: metricdata.NewExtrema[N](-1),
957976
Max: metricdata.NewExtrema[N](16),
958-
Sum: 44,
977+
Sum: 43,
959978
Scale: -1,
960979
PositiveBucket: metricdata.ExponentialBucket{
961980
Offset: -1,
962981
Counts: []uint64{1, 6, 2},
963982
},
983+
NegativeBucket: metricdata.ExponentialBucket{
984+
Offset: -1,
985+
Counts: []uint64{1},
986+
},
964987
},
965988
},
966989
},
@@ -985,15 +1008,19 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) {
9851008
Attributes: fltrAlice,
9861009
StartTime: staticTime,
9871010
Time: staticTime,
988-
Count: 9,
989-
Min: metricdata.NewExtrema[N](1),
1011+
Count: 10,
1012+
Min: metricdata.NewExtrema[N](-1),
9901013
Max: metricdata.NewExtrema[N](16),
991-
Sum: 44,
1014+
Sum: 43,
9921015
Scale: -1,
9931016
PositiveBucket: metricdata.ExponentialBucket{
9941017
Offset: -1,
9951018
Counts: []uint64{1, 6, 2},
9961019
},
1020+
NegativeBucket: metricdata.ExponentialBucket{
1021+
Offset: -1,
1022+
Counts: []uint64{1},
1023+
},
9971024
},
9981025
{
9991026
Attributes: overflowSet,

0 commit comments

Comments
 (0)