Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/tanzuobservability] exponential histogram adjustment. #10135

Merged
merged 3 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- `datadogexporter`: add error checks for datadog exporter (#9964)
- `groupbyattrsprocessor`: copied aggregationtemporality when grouping metrics. (#9088)
- `mongodbreceiver`: Fix issue where receiver startup could hang (#10111)
- `tanzuobservabilityexporter`: Improve how negative values in exponential histograms are handled. (#10135)

## v0.51.0

Expand Down
9 changes: 2 additions & 7 deletions exporter/tanzuobservabilityexporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions exporter/tanzuobservabilityexporter/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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) {
Expand Down