diff --git a/CHANGELOG.md b/CHANGELOG.md index e278db29aad4..e6878d553e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ ### 🧰 Bug fixes 🧰 +- `tanzuobservabilityexporter`: Improve how negative values in exponential histograms are handled. (#10135) + ## v0.52.0 ### 🛑 Breaking changes 🛑 diff --git a/exporter/tanzuobservabilityexporter/metrics.go b/exporter/tanzuobservabilityexporter/metrics.go index 979d0ab6e80e..88d69c68cfc7 100644 --- a/exporter/tanzuobservabilityexporter/metrics.go +++ b/exporter/tanzuobservabilityexporter/metrics.go @@ -710,10 +710,9 @@ func newExponentialHistogramDataPoint(dataPoint pmetric.ExponentialHistogramData positiveBucketCounts := dataPoint.Positive().MBucketCounts() // The total number of buckets is the number of negative buckets + the number of positive - // buckets + 1 for the zero bucket + 1 bucket for negative infinity up to the negative explicit - // bound with largest magnitude + 1 bucket for the largest positive explicit bound up to + // buckets + 1 for the zero bucket + 1 bucket for the largest positive explicit bound up to // positive infinity. - numBucketCounts := 1 + len(negativeBucketCounts) + 1 + len(positiveBucketCounts) + 1 + numBucketCounts := len(negativeBucketCounts) + 1 + len(positiveBucketCounts) + 1 // We pre-allocate the slice setting its length to 0 so that GO doesn't have to keep // re-allocating the slice as it grows. @@ -748,12 +747,8 @@ func appendNegativeBucketsAndExplicitBounds( bucketCounts *[]uint64, explicitBounds *[]float64, ) { - // The count in the first bucket which includes negative infinity is always 0. - *bucketCounts = append(*bucketCounts, 0) - // The smallest negative explicit bound. le := -math.Pow(base, float64(negativeOffset)+float64(len(negativeBucketCounts))) - *explicitBounds = append(*explicitBounds, le) // The first negativeBucketCount has a negative explicit bound with the smallest magnitude; // the last negativeBucketCount has a negative explicit bound with the largest magnitude. diff --git a/exporter/tanzuobservabilityexporter/metrics_test.go b/exporter/tanzuobservabilityexporter/metrics_test.go index 88128fe1c2f0..17b1981ed393 100644 --- a/exporter/tanzuobservabilityexporter/metrics_test.go +++ b/exporter/tanzuobservabilityexporter/metrics_test.go @@ -1102,10 +1102,10 @@ func TestExponentialHistogramDataPoint(t *testing.T) { dataPoint.Attributes().UpsertString("baz", "7") setDataPointTimestamp(1640198765, dataPoint) h := newExponentialHistogramDataPoint(dataPoint) - assert.Equal(t, []uint64{0, 17, 16, 15, 2, 5, 6, 7, 8, 0}, h.MBucketCounts()) + assert.Equal(t, []uint64{17, 16, 15, 2, 5, 6, 7, 8, 0}, h.MBucketCounts()) assert.InDeltaSlice( t, - []float64{-22.6274, -16.0, -11.3137, -8.0, 2.8284, 4.0, 5.6569, 8.0, 11.3137}, + []float64{-16.0, -11.3137, -8.0, 2.8284, 4.0, 5.6569, 8.0, 11.3137}, h.MExplicitBounds(), 0.0001) assert.Equal(t, map[string]string{"foo": "bar", "baz": "7"}, attributesToTags(h.Attributes())) @@ -1119,8 +1119,8 @@ func TestExponentialHistogramDataPoint_ZeroOnly(t *testing.T) { dataPoint.Positive().SetOffset(1) dataPoint.SetZeroCount(5) h := newExponentialHistogramDataPoint(dataPoint) - assert.Equal(t, []uint64{0, 5, 0}, h.MBucketCounts()) - assert.InDeltaSlice(t, []float64{-4.0, 2.0}, h.MExplicitBounds(), 0.0001) + assert.Equal(t, []uint64{5, 0}, h.MBucketCounts()) + assert.InDeltaSlice(t, []float64{2.0}, h.MExplicitBounds(), 0.0001) } func TestAttributesToTagsForMetrics(t *testing.T) {