Skip to content

Commit

Permalink
Fix HistogramDataPoints transform in otlpmetric
Browse files Browse the repository at this point in the history
Fixes open-telemetry#3284

The transform uses the same reference a histogram datapoint sum value
for all transformed metrics. This results in all transformed metrics
being exported with the same sum (see open-telemetry#3284). This changes the transform
to correctly reference a unique sum for each datapoint.
  • Loading branch information
MrAlias committed Oct 15, 2022
1 parent b6a22ab commit c1b6ea3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion exporters/otlp/otlpmetric/internal/transform/metricdata.go
Expand Up @@ -173,12 +173,13 @@ func Histogram(h metricdata.Histogram) (*mpb.Metric_Histogram, error) {
func HistogramDataPoints(dPts []metricdata.HistogramDataPoint) []*mpb.HistogramDataPoint {
out := make([]*mpb.HistogramDataPoint, 0, len(dPts))
for _, dPt := range dPts {
sum := dPt.Sum
out = append(out, &mpb.HistogramDataPoint{
Attributes: AttrIter(dPt.Attributes.Iter()),
StartTimeUnixNano: uint64(dPt.StartTime.UnixNano()),
TimeUnixNano: uint64(dPt.Time.UnixNano()),
Count: dPt.Count,
Sum: &dPt.Sum,
Sum: &sum,
BucketCounts: dPt.BucketCounts,
ExplicitBounds: dPt.Bounds,
Min: dPt.Min,
Expand Down
37 changes: 29 additions & 8 deletions exporters/otlp/otlpmetric/internal/transform/metricdata_test.go
Expand Up @@ -51,29 +51,50 @@ var (
Value: &cpb.AnyValue_StringValue{StringValue: "bob"},
}}

min, max, sum = 2.0, 4.0, 90.0
otelHDP = []metricdata.HistogramDataPoint{{
minA, maxA, sumA = 2.0, 4.0, 90.0
minB, maxB, sumB = 4.0, 150.0, 234.0
otelHDP = []metricdata.HistogramDataPoint{{
Attributes: alice,
StartTime: start,
Time: end,
Count: 30,
Bounds: []float64{1, 5},
BucketCounts: []uint64{0, 30, 0},
Min: &min,
Max: &max,
Sum: sum,
Min: &minA,
Max: &maxA,
Sum: sumA,
}, {
Attributes: bob,
StartTime: start,
Time: end,
Count: 3,
Bounds: []float64{1, 5},
BucketCounts: []uint64{0, 1, 2},
Min: &minB,
Max: &maxB,
Sum: sumB,
}}

pbHDP = []*mpb.HistogramDataPoint{{
Attributes: []*cpb.KeyValue{pbAlice},
StartTimeUnixNano: uint64(start.UnixNano()),
TimeUnixNano: uint64(end.UnixNano()),
Count: 30,
Sum: &sum,
Sum: &sumA,
ExplicitBounds: []float64{1, 5},
BucketCounts: []uint64{0, 30, 0},
Min: &min,
Max: &max,
Min: &minA,
Max: &maxA,
}, {
Attributes: []*cpb.KeyValue{pbBob},
StartTimeUnixNano: uint64(start.UnixNano()),
TimeUnixNano: uint64(end.UnixNano()),
Count: 3,
Sum: &sumB,
ExplicitBounds: []float64{1, 5},
BucketCounts: []uint64{0, 1, 2},
Min: &minB,
Max: &maxB,
}}

otelHist = metricdata.Histogram{
Expand Down

0 comments on commit c1b6ea3

Please sign in to comment.