From 5eef5bd6985bc9d06fa065762668dfdb732e56ad Mon Sep 17 00:00:00 2001 From: Zhonghao Zhao Date: Tue, 12 Nov 2024 19:38:53 +0000 Subject: [PATCH] Split EMF log with larger than 100 buckets. --- exporter/awsemfexporter/datapoint.go | 191 +++++-- exporter/awsemfexporter/datapoint_test.go | 476 +++++++++++++++++- exporter/awsemfexporter/grouped_metric.go | 3 +- .../awsemfexporter/grouped_metric_test.go | 44 +- exporter/awsemfexporter/metric_translator.go | 2 + 5 files changed, 669 insertions(+), 47 deletions(-) diff --git a/exporter/awsemfexporter/datapoint.go b/exporter/awsemfexporter/datapoint.go index 1104a9e59e41..031dd43e2eb8 100644 --- a/exporter/awsemfexporter/datapoint.go +++ b/exporter/awsemfexporter/datapoint.go @@ -109,6 +109,12 @@ type summaryMetricEntry struct { count uint64 } +type dataPointSplit struct { + cWMetricHistogram *cWMetricHistogram + length int + capacity int +} + // CalculateDeltaDatapoints retrieves the NumberDataPoint at the given index and performs rate/delta calculation if necessary. func (dps numberDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationScopeName string, _ bool, calculators *emfCalculators) ([]dataPoint, bool) { metric := dps.NumberDataPointSlice.At(i) @@ -193,58 +199,159 @@ func (dps histogramDataPointSlice) IsStaleNaNInf(i int) (bool, pcommon.Map) { } // CalculateDeltaDatapoints retrieves the ExponentialHistogramDataPoint at the given index. +// As CloudWatch EMF logs allows in maximum of 100 target members, the exponential histogram metric are split into multiple data points as needed, +// each containing a maximum of 100 buckets, to comply with CloudWatch EMF log constraints. +// Note that the number of values and counts in each split may not be less than splitThreshold as we are only adding non-zero bucket counts. +// +// For each split data point: +// - Min and Max values are recalculated based on the bucket boundary within that specific split. +// - Sum is only assigned to the first split to ensure the total sum of the datapoints after aggregation is correct. +// - Count is accumulated based on the bucket counts within each split. func (dps exponentialHistogramDataPointSlice) CalculateDeltaDatapoints(idx int, instrumentationScopeName string, _ bool, _ *emfCalculators) ([]dataPoint, bool) { metric := dps.ExponentialHistogramDataPointSlice.At(idx) + const splitThreshold = 100 + var currentBucketIndex = 0 + var datapoints []dataPoint + var currentPositiveIndex = metric.Positive().BucketCounts().Len() - 1 + var currentZeroIndex = 0 + var currentNegativeIndex = 0 + totalBucketLen := metric.Positive().BucketCounts().Len() + metric.Negative().BucketCounts().Len() + if metric.ZeroCount() > 0 { + totalBucketLen++ + } + + if totalBucketLen == 0 { + return []dataPoint{{ + name: dps.metricName, + value: &cWMetricHistogram{ + Values: []float64{}, + Counts: []float64{}, + Count: metric.Count(), + Sum: metric.Sum(), + Max: metric.Max(), + Min: metric.Min(), + }, + labels: createLabels(metric.Attributes(), instrumentationScopeName), + timestampMs: unixNanoToMilliseconds(metric.Timestamp()), + }}, true + } + + for currentBucketIndex < totalBucketLen { + // Create a new dataPointSplit with a capacity of up to splitThreshold buckets + split := dataPointSplit{ + cWMetricHistogram: &cWMetricHistogram{ + Values: []float64{}, + Counts: []float64{}, + Max: metric.Max(), + Min: metric.Min(), + Count: 0, + Sum: 0, + }, + length: 0, + capacity: splitThreshold, + } + + // Only assign `Sum` if this is the first split to make sure the total sum of the datapoints after aggregation is correct. + if currentBucketIndex == 0 { + split.cWMetricHistogram.Sum = metric.Sum() + } + + if totalBucketLen-currentBucketIndex < splitThreshold { + split.capacity = totalBucketLen - currentBucketIndex + } + + // Set mid-point of positive buckets in values/counts array. + currentBucketIndex, currentPositiveIndex = iteratePositiveBuckets(&split, metric, currentBucketIndex, currentPositiveIndex, totalBucketLen) + // Set count of zero bucket in values/counts array. + currentBucketIndex, currentZeroIndex = iterateZeroBucket(&split, metric, currentBucketIndex, currentZeroIndex, totalBucketLen) + // Set mid-point of negative buckets in values/counts array. + currentBucketIndex, currentNegativeIndex = iterateNegativeBuckets(&split, metric, currentBucketIndex, currentNegativeIndex, totalBucketLen) + + // Add the current split to the datapoints list + datapoints = append(datapoints, dataPoint{ + name: dps.metricName, + value: split.cWMetricHistogram, + labels: createLabels(metric.Attributes(), instrumentationScopeName), + timestampMs: unixNanoToMilliseconds(metric.Timestamp()), + }) + } + return datapoints, true +} + +func iteratePositiveBuckets(split *dataPointSplit, metric pmetric.ExponentialHistogramDataPoint, currentBucketIndex int, currentPositiveIndex int, totalBucketLen int) (int, int) { scale := metric.Scale() base := math.Pow(2, math.Pow(2, float64(-scale))) - arrayValues := []float64{} - arrayCounts := []float64{} - var bucketBegin float64 - var bucketEnd float64 - - // Set mid-point of positive buckets in values/counts array. positiveBuckets := metric.Positive() positiveOffset := positiveBuckets.Offset() positiveBucketCounts := positiveBuckets.BucketCounts() - bucketBegin = 0 - bucketEnd = 0 - for i := 0; i < positiveBucketCounts.Len(); i++ { - index := i + int(positiveOffset) - if bucketBegin == 0 { - bucketBegin = math.Pow(base, float64(index)) + bucketBegin := 0.0 + bucketEnd := 0.0 + + for split.length < split.capacity && currentPositiveIndex >= 0 { + index := currentPositiveIndex + int(positiveOffset) + if bucketEnd == 0 { + bucketEnd = math.Pow(base, float64(index+1)) } else { - bucketBegin = bucketEnd + bucketEnd = bucketBegin } - bucketEnd = math.Pow(base, float64(index+1)) + bucketBegin = math.Pow(base, float64(index)) metricVal := (bucketBegin + bucketEnd) / 2 - count := positiveBucketCounts.At(i) + count := positiveBucketCounts.At(currentPositiveIndex) if count > 0 { - arrayValues = append(arrayValues, metricVal) - arrayCounts = append(arrayCounts, float64(count)) + split.cWMetricHistogram.Values = append(split.cWMetricHistogram.Values, metricVal) + split.cWMetricHistogram.Counts = append(split.cWMetricHistogram.Counts, float64(count)) + split.length++ + split.cWMetricHistogram.Count += count + if split.length == 1 && currentBucketIndex != 0 { + split.cWMetricHistogram.Max = bucketEnd + } + if split.length == split.capacity && currentBucketIndex != totalBucketLen-1 { + split.cWMetricHistogram.Min = bucketBegin + } } + currentBucketIndex++ + currentPositiveIndex-- } - // Set count of zero bucket in values/counts array. - if metric.ZeroCount() > 0 { - arrayValues = append(arrayValues, 0) - arrayCounts = append(arrayCounts, float64(metric.ZeroCount())) + return currentBucketIndex, currentPositiveIndex +} + +func iterateZeroBucket(split *dataPointSplit, metric pmetric.ExponentialHistogramDataPoint, currentBucketIndex int, currentZeroIndex int, totalBucketLen int) (int, int) { + if metric.ZeroCount() > 0 && split.length < split.capacity && currentZeroIndex == 0 { + split.cWMetricHistogram.Values = append(split.cWMetricHistogram.Values, 0) + split.cWMetricHistogram.Counts = append(split.cWMetricHistogram.Counts, float64(metric.ZeroCount())) + split.length++ + split.cWMetricHistogram.Count += metric.ZeroCount() + if split.length == 1 && currentBucketIndex != 0 { + split.cWMetricHistogram.Max = 0 + } + if split.length == split.capacity && currentBucketIndex != totalBucketLen-1 { + split.cWMetricHistogram.Min = 0 + } + currentZeroIndex++ + currentBucketIndex++ } - // Set mid-point of negative buckets in values/counts array. + return currentBucketIndex, currentZeroIndex +} + +func iterateNegativeBuckets(split *dataPointSplit, metric pmetric.ExponentialHistogramDataPoint, currentBucketIndex int, currentNegativeIndex int, totalBucketLen int) (int, int) { // According to metrics spec, the value in histogram is expected to be non-negative. // https://opentelemetry.io/docs/specs/otel/metrics/api/#histogram // However, the negative support is defined in metrics data model. // https://opentelemetry.io/docs/specs/otel/metrics/data-model/#exponentialhistogram // The negative is also supported but only verified with unit test. - + scale := metric.Scale() + base := math.Pow(2, math.Pow(2, float64(-scale))) negativeBuckets := metric.Negative() negativeOffset := negativeBuckets.Offset() negativeBucketCounts := negativeBuckets.BucketCounts() - bucketBegin = 0 - bucketEnd = 0 - for i := 0; i < negativeBucketCounts.Len(); i++ { - index := i + int(negativeOffset) + bucketBegin := 0.0 + bucketEnd := 0.0 + + for split.length < split.capacity && currentNegativeIndex < metric.Negative().BucketCounts().Len() { + index := currentNegativeIndex + int(negativeOffset) if bucketEnd == 0 { bucketEnd = -math.Pow(base, float64(index)) } else { @@ -252,26 +359,24 @@ func (dps exponentialHistogramDataPointSlice) CalculateDeltaDatapoints(idx int, } bucketBegin = -math.Pow(base, float64(index+1)) metricVal := (bucketBegin + bucketEnd) / 2 - count := negativeBucketCounts.At(i) + count := negativeBucketCounts.At(currentNegativeIndex) if count > 0 { - arrayValues = append(arrayValues, metricVal) - arrayCounts = append(arrayCounts, float64(count)) + split.cWMetricHistogram.Values = append(split.cWMetricHistogram.Values, metricVal) + split.cWMetricHistogram.Counts = append(split.cWMetricHistogram.Counts, float64(count)) + split.length++ + split.cWMetricHistogram.Count += count + if split.length == 1 && currentBucketIndex != 0 { + split.cWMetricHistogram.Max = bucketEnd + } + if split.length == split.capacity && currentBucketIndex != totalBucketLen-1 { + split.cWMetricHistogram.Min = bucketBegin + } } + currentBucketIndex++ + currentNegativeIndex++ } - return []dataPoint{{ - name: dps.metricName, - value: &cWMetricHistogram{ - Values: arrayValues, - Counts: arrayCounts, - Count: metric.Count(), - Sum: metric.Sum(), - Max: metric.Max(), - Min: metric.Min(), - }, - labels: createLabels(metric.Attributes(), instrumentationScopeName), - timestampMs: unixNanoToMilliseconds(metric.Timestamp()), - }}, true + return currentBucketIndex, currentNegativeIndex } func (dps exponentialHistogramDataPointSlice) IsStaleNaNInf(i int) (bool, pcommon.Map) { diff --git a/exporter/awsemfexporter/datapoint_test.go b/exporter/awsemfexporter/datapoint_test.go index 597f1d4b091c..a3004608b0c8 100644 --- a/exporter/awsemfexporter/datapoint_test.go +++ b/exporter/awsemfexporter/datapoint_test.go @@ -244,6 +244,35 @@ func generateTestExponentialHistogramMetricWithInfs(name string) pmetric.Metrics return otelMetrics } +func generateTestExponentialHistogramMetricWithLongBuckets(name string) pmetric.Metrics { + otelMetrics := pmetric.NewMetrics() + rs := otelMetrics.ResourceMetrics().AppendEmpty() + metrics := rs.ScopeMetrics().AppendEmpty().Metrics() + metric := metrics.AppendEmpty() + metric.SetName(name) + metric.SetUnit("Seconds") + exponentialHistogramMetric := metric.SetEmptyExponentialHistogram() + + exponentialHistogramDatapoint := exponentialHistogramMetric.DataPoints().AppendEmpty() + exponentialHistogramDatapoint.SetCount(3662) + exponentialHistogramDatapoint.SetSum(1000) + exponentialHistogramDatapoint.SetMin(-9e+17) + exponentialHistogramDatapoint.SetMax(9e+17) + exponentialHistogramDatapoint.SetZeroCount(2) + posBucketCounts := make([]uint64, 60) + for i := range posBucketCounts { + posBucketCounts[i] = uint64(i + 1) + } + exponentialHistogramDatapoint.Positive().BucketCounts().FromRaw(posBucketCounts) + negBucketCounts := make([]uint64, 60) + for i := range negBucketCounts { + negBucketCounts[i] = uint64(i + 1) + } + exponentialHistogramDatapoint.Negative().BucketCounts().FromRaw(negBucketCounts) + exponentialHistogramDatapoint.Attributes().PutStr("label1", "value1") + return otelMetrics +} + func generateTestSummaryMetric(name string) pmetric.Metrics { otelMetrics := pmetric.NewMetrics() rs := otelMetrics.ResourceMetrics().AppendEmpty() @@ -850,7 +879,7 @@ func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing. }(), expectedDatapoint: dataPoint{ name: "foo", - value: &cWMetricHistogram{Values: []float64{1.5, 3, 6, 0, -1.5, -3, -6}, Counts: []float64{1, 2, 3, 4, 1, 2, 3}}, + value: &cWMetricHistogram{Values: []float64{6, 3, 1.5, 0, -1.5, -3, -6}, Counts: []float64{3, 2, 1, 4, 1, 2, 3}, Count: 16}, labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, }, }, @@ -871,7 +900,7 @@ func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing. }(), expectedDatapoint: dataPoint{ name: "foo", - value: &cWMetricHistogram{Values: []float64{0.625, 2.5, 10, 0, -0.625, -2.5, -10}, Counts: []float64{1, 2, 3, 4, 1, 2, 3}}, + value: &cWMetricHistogram{Values: []float64{10, 2.5, 0.625, 0, -0.625, -2.5, -10}, Counts: []float64{3, 2, 1, 4, 1, 2, 3}, Count: 16}, labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1", "label2": "value2"}, }, }, @@ -895,6 +924,449 @@ func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSlice(t *testing. } +func TestCalculateDeltaDatapoints_ExponentialHistogramDataPointSliceWithSplitDataPoints(t *testing.T) { + dmd := generateDeltaMetricMetadata(false, "foo", false) + + testCases := []struct { + name string + histogramDPS pmetric.ExponentialHistogramDataPointSlice + expectedDatapoints []dataPoint + }{ + { + name: "Exponential histogram with more than 100 buckets, including positive, negative and zero buckets", + histogramDPS: func() pmetric.ExponentialHistogramDataPointSlice { + histogramDPS := pmetric.NewExponentialHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + posBucketCounts := make([]uint64, 60) + for i := range posBucketCounts { + posBucketCounts[i] = uint64(i + 1) + } + histogramDP.Positive().BucketCounts().FromRaw(posBucketCounts) + histogramDP.SetZeroCount(2) + negBucketCounts := make([]uint64, 60) + for i := range negBucketCounts { + negBucketCounts[i] = uint64(i + 1) + } + histogramDP.Negative().BucketCounts().FromRaw(negBucketCounts) + histogramDP.SetSum(1000) + histogramDP.SetMin(-9e+17) + histogramDP.SetMax(9e+17) + histogramDP.SetCount(uint64(3662)) + histogramDP.Attributes().PutStr("label1", "value1") + return histogramDPS + }(), + expectedDatapoints: []dataPoint{ + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{8.646911284551352e+17, 4.323455642275676e+17, 2.161727821137838e+17, 1.080863910568919e+17, 5.404319552844595e+16, 2.7021597764222976e+16, + 1.3510798882111488e+16, 6.755399441055744e+15, 3.377699720527872e+15, 1.688849860263936e+15, 8.44424930131968e+14, 4.22212465065984e+14, + 2.11106232532992e+14, 1.05553116266496e+14, 5.2776558133248e+13, 2.6388279066624e+13, 1.3194139533312e+13, 6.597069766656e+12, 3.298534883328e+12, + 1.649267441664e+12, 8.24633720832e+11, 4.12316860416e+11, 2.06158430208e+11, 1.03079215104e+11, 5.1539607552e+10, 2.5769803776e+10, + 1.2884901888e+10, 6.442450944e+09, 3.221225472e+09, 1.610612736e+09, 8.05306368e+08, 4.02653184e+08, 2.01326592e+08, 1.00663296e+08, + 5.0331648e+07, 2.5165824e+07, 1.2582912e+07, 6.291456e+06, 3.145728e+06, 1.572864e+06, 786432, 393216, 196608, 98304, 49152, 24576, + 12288, 6144, 3072, 1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 1.5, 0, -1.5, -3, -6, -12, -24, -48, -96, -192, -384, -768, -1536, -3072, + -6144, -12288, -24576, -49152, -98304, -196608, -393216, -786432, -1.572864e+06, -3.145728e+06, -6.291456e+06, -1.2582912e+07, -2.5165824e+07, + -5.0331648e+07, -1.00663296e+08, -2.01326592e+08, -4.02653184e+08, -8.05306368e+08, -1.610612736e+09, -3.221225472e+09, -6.442450944e+09, + -1.2884901888e+10, -2.5769803776e+10, -5.1539607552e+10, -1.03079215104e+11, -2.06158430208e+11, -4.12316860416e+11}, + Counts: []float64{60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, + 6, 5, 4, 3, 2, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39}, + Sum: 1000, Count: 2612, Min: -5.49755813888e+11, Max: 9e+17}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{-8.24633720832e+11, -1.649267441664e+12, -3.298534883328e+12, -6.597069766656e+12, -1.3194139533312e+13, -2.6388279066624e+13, -5.2776558133248e+13, + -1.05553116266496e+14, -2.11106232532992e+14, -4.22212465065984e+14, -8.44424930131968e+14, -1.688849860263936e+15, -3.377699720527872e+15, + -6.755399441055744e+15, -1.3510798882111488e+16, -2.7021597764222976e+16, -5.404319552844595e+16, -1.080863910568919e+17, -2.161727821137838e+17, + -4.323455642275676e+17, -8.646911284551352e+17}, + Counts: []float64{40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, + Sum: 0, Count: 1050, Min: -9e+17, Max: -5.49755813888e+11}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + }, + }, + { + name: "Exponential histogram with more than 100 buckets, including positive and zero buckets", + histogramDPS: func() pmetric.ExponentialHistogramDataPointSlice { + histogramDPS := pmetric.NewExponentialHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + posBucketCounts := make([]uint64, 120) + for i := range posBucketCounts { + posBucketCounts[i] = uint64(i + 1) + } + histogramDP.Positive().BucketCounts().FromRaw(posBucketCounts) + histogramDP.SetZeroCount(2) + histogramDP.SetSum(10000) + histogramDP.SetMin(0) + histogramDP.SetMax(9e+36) + histogramDP.SetCount(uint64(7262)) + histogramDP.Attributes().PutStr("label1", "value1") + return histogramDPS + }(), + expectedDatapoints: []dataPoint{ + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{9.969209968386869e+35, 4.9846049841934345e+35, 2.4923024920967173e+35, 1.2461512460483586e+35, 6.230756230241793e+34, + 3.1153781151208966e+34, 1.5576890575604483e+34, 7.788445287802241e+33, 3.894222643901121e+33, 1.9471113219505604e+33, + 9.735556609752802e+32, 4.867778304876401e+32, 2.4338891524382005e+32, 1.2169445762191002e+32, 6.084722881095501e+31, + 3.0423614405477506e+31, 1.5211807202738753e+31, 7.605903601369376e+30, 3.802951800684688e+30, 1.901475900342344e+30, + 9.50737950171172e+29, 4.75368975085586e+29, 2.37684487542793e+29, 1.188422437713965e+29, 5.942112188569825e+28, + 2.9710560942849127e+28, 1.4855280471424563e+28, 7.427640235712282e+27, 3.713820117856141e+27, 1.8569100589280704e+27, + 9.284550294640352e+26, 4.642275147320176e+26, 2.321137573660088e+26, 1.160568786830044e+26, 5.80284393415022e+25, + 2.90142196707511e+25, 1.450710983537555e+25, 7.253554917687775e+24, 3.6267774588438875e+24, 1.8133887294219438e+24, + 9.066943647109719e+23, 4.5334718235548594e+23, 2.2667359117774297e+23, 1.1333679558887149e+23, 5.666839779443574e+22, + 2.833419889721787e+22, 1.4167099448608936e+22, 7.083549724304468e+21, 3.541774862152234e+21, 1.770887431076117e+21, + 8.854437155380585e+20, 4.4272185776902924e+20, 2.2136092888451462e+20, 1.1068046444225731e+20, 5.5340232221128655e+19, + 2.7670116110564327e+19, 1.3835058055282164e+19, 6.917529027641082e+18, 3.458764513820541e+18, 1.7293822569102705e+18, + 8.646911284551352e+17, 4.323455642275676e+17, 2.161727821137838e+17, 1.080863910568919e+17, 5.404319552844595e+16, + 2.7021597764222976e+16, 1.3510798882111488e+16, 6.755399441055744e+15, 3.377699720527872e+15, 1.688849860263936e+15, + 8.44424930131968e+14, 4.22212465065984e+14, 2.11106232532992e+14, 1.05553116266496e+14, 5.2776558133248e+13, + 2.6388279066624e+13, 1.3194139533312e+13, 6.597069766656e+12, 3.298534883328e+12, 1.649267441664e+12, 8.24633720832e+11, + 4.12316860416e+11, 2.06158430208e+11, 1.03079215104e+11, 5.1539607552e+10, 2.5769803776e+10, 1.2884901888e+10, + 6.442450944e+09, 3.221225472e+09, 1.610612736e+09, 8.05306368e+08, 4.02653184e+08, 2.01326592e+08, 1.00663296e+08, + 5.0331648e+07, 2.5165824e+07, 1.2582912e+07, 6.291456e+06, 3.145728e+06, 1.572864e+06}, + Counts: []float64{120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, + 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, + 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, + 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21}, + Sum: 10000, Count: 7050, Min: 1.048576e+06, Max: 9e+36}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{786432, 393216, 196608, 98304, 49152, 24576, 12288, 6144, 3072, 1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 1.5, 0}, + Counts: []float64{20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2}, + Sum: 0, Count: 212, Min: 0, Max: 1.048576e+06}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + }, + }, + { + name: "Exponential histogram with more than 100 buckets, including negative and zero buckets", + histogramDPS: func() pmetric.ExponentialHistogramDataPointSlice { + histogramDPS := pmetric.NewExponentialHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + negBucketCounts := make([]uint64, 120) + for i := range negBucketCounts { + negBucketCounts[i] = uint64(i + 1) + } + histogramDP.Negative().BucketCounts().FromRaw(negBucketCounts) + histogramDP.SetZeroCount(2) + histogramDP.SetSum(10000) + histogramDP.SetMin(-9e+36) + histogramDP.SetMax(0) + histogramDP.SetCount(uint64(7262)) + histogramDP.Attributes().PutStr("label1", "value1") + return histogramDPS + }(), + expectedDatapoints: []dataPoint{ + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{0, -1.5, -3, -6, -12, -24, -48, -96, -192, -384, -768, -1536, -3072, -6144, -12288, -24576, + -49152, -98304, -196608, -393216, -786432, -1.572864e+06, -3.145728e+06, -6.291456e+06, -1.2582912e+07, + -2.5165824e+07, -5.0331648e+07, -1.00663296e+08, -2.01326592e+08, -4.02653184e+08, -8.05306368e+08, + -1.610612736e+09, -3.221225472e+09, -6.442450944e+09, -1.2884901888e+10, -2.5769803776e+10, + -5.1539607552e+10, -1.03079215104e+11, -2.06158430208e+11, -4.12316860416e+11, -8.24633720832e+11, + -1.649267441664e+12, -3.298534883328e+12, -6.597069766656e+12, -1.3194139533312e+13, -2.6388279066624e+13, + -5.2776558133248e+13, -1.05553116266496e+14, -2.11106232532992e+14, -4.22212465065984e+14, -8.44424930131968e+14, + -1.688849860263936e+15, -3.377699720527872e+15, -6.755399441055744e+15, -1.3510798882111488e+16, + -2.7021597764222976e+16, -5.404319552844595e+16, -1.080863910568919e+17, -2.161727821137838e+17, + -4.323455642275676e+17, -8.646911284551352e+17, -1.7293822569102705e+18, -3.458764513820541e+18, + -6.917529027641082e+18, -1.3835058055282164e+19, -2.7670116110564327e+19, -5.5340232221128655e+19, + -1.1068046444225731e+20, -2.2136092888451462e+20, -4.4272185776902924e+20, -8.854437155380585e+20, + -1.770887431076117e+21, -3.541774862152234e+21, -7.083549724304468e+21, -1.4167099448608936e+22, + -2.833419889721787e+22, -5.666839779443574e+22, -1.1333679558887149e+23, -2.2667359117774297e+23, + -4.5334718235548594e+23, -9.066943647109719e+23, -1.8133887294219438e+24, -3.6267774588438875e+24, + -7.253554917687775e+24, -1.450710983537555e+25, -2.90142196707511e+25, -5.80284393415022e+25, + -1.160568786830044e+26, -2.321137573660088e+26, -4.642275147320176e+26, -9.284550294640352e+26, + -1.8569100589280704e+27, -3.713820117856141e+27, -7.427640235712282e+27, -1.4855280471424563e+28, + -2.9710560942849127e+28, -5.942112188569825e+28, -1.188422437713965e+29, -2.37684487542793e+29, -4.75368975085586e+29}, + Counts: []float64{2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99}, + Sum: 10000, Count: 4952, Min: -6.338253001141147e+29, Max: 0}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{-9.50737950171172e+29, -1.901475900342344e+30, -3.802951800684688e+30, -7.605903601369376e+30, + -1.5211807202738753e+31, -3.0423614405477506e+31, -6.084722881095501e+31, -1.2169445762191002e+32, + -2.4338891524382005e+32, -4.867778304876401e+32, -9.735556609752802e+32, -1.9471113219505604e+33, -3.894222643901121e+33, + -7.788445287802241e+33, -1.5576890575604483e+34, -3.1153781151208966e+34, -6.230756230241793e+34, -1.2461512460483586e+35, + -2.4923024920967173e+35, -4.9846049841934345e+35, -9.969209968386869e+35}, + Counts: []float64{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120}, + Sum: 0, Count: 2310, Min: -9e+36, Max: -6.338253001141147e+29}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + }, + }, + { + name: "Exponential histogram with more than 100 buckets, including positive and negative buckets", + histogramDPS: func() pmetric.ExponentialHistogramDataPointSlice { + histogramDPS := pmetric.NewExponentialHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + posBucketCounts := make([]uint64, 60) + for i := range posBucketCounts { + posBucketCounts[i] = uint64(i + 1) + } + histogramDP.Positive().BucketCounts().FromRaw(posBucketCounts) + negBucketCounts := make([]uint64, 60) + for i := range negBucketCounts { + negBucketCounts[i] = uint64(i + 1) + } + histogramDP.Negative().BucketCounts().FromRaw(negBucketCounts) + histogramDP.SetSum(1000) + histogramDP.SetMin(-9e+17) + histogramDP.SetMax(9e+17) + histogramDP.SetCount(uint64(3660)) + histogramDP.Attributes().PutStr("label1", "value1") + return histogramDPS + }(), + expectedDatapoints: []dataPoint{ + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{8.646911284551352e+17, 4.323455642275676e+17, 2.161727821137838e+17, 1.080863910568919e+17, 5.404319552844595e+16, 2.7021597764222976e+16, + 1.3510798882111488e+16, 6.755399441055744e+15, 3.377699720527872e+15, 1.688849860263936e+15, 8.44424930131968e+14, 4.22212465065984e+14, + 2.11106232532992e+14, 1.05553116266496e+14, 5.2776558133248e+13, 2.6388279066624e+13, 1.3194139533312e+13, 6.597069766656e+12, 3.298534883328e+12, + 1.649267441664e+12, 8.24633720832e+11, 4.12316860416e+11, 2.06158430208e+11, 1.03079215104e+11, 5.1539607552e+10, 2.5769803776e+10, + 1.2884901888e+10, 6.442450944e+09, 3.221225472e+09, 1.610612736e+09, 8.05306368e+08, 4.02653184e+08, 2.01326592e+08, 1.00663296e+08, + 5.0331648e+07, 2.5165824e+07, 1.2582912e+07, 6.291456e+06, 3.145728e+06, 1.572864e+06, 786432, 393216, 196608, 98304, 49152, 24576, + 12288, 6144, 3072, 1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 1.5, -1.5, -3, -6, -12, -24, -48, -96, -192, -384, -768, -1536, -3072, + -6144, -12288, -24576, -49152, -98304, -196608, -393216, -786432, -1.572864e+06, -3.145728e+06, -6.291456e+06, -1.2582912e+07, -2.5165824e+07, + -5.0331648e+07, -1.00663296e+08, -2.01326592e+08, -4.02653184e+08, -8.05306368e+08, -1.610612736e+09, -3.221225472e+09, -6.442450944e+09, + -1.2884901888e+10, -2.5769803776e+10, -5.1539607552e+10, -1.03079215104e+11, -2.06158430208e+11, -4.12316860416e+11, -8.24633720832e+11}, + Counts: []float64{60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, + 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40}, + Sum: 1000, Count: 2650, Min: -1.099511627776e+12, Max: 9e+17}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{-1.649267441664e+12, -3.298534883328e+12, -6.597069766656e+12, -1.3194139533312e+13, -2.6388279066624e+13, -5.2776558133248e+13, + -1.05553116266496e+14, -2.11106232532992e+14, -4.22212465065984e+14, -8.44424930131968e+14, -1.688849860263936e+15, -3.377699720527872e+15, + -6.755399441055744e+15, -1.3510798882111488e+16, -2.7021597764222976e+16, -5.404319552844595e+16, -1.080863910568919e+17, -2.161727821137838e+17, + -4.323455642275676e+17, -8.646911284551352e+17}, + Counts: []float64{41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}, + Sum: 0, Count: 1010, Min: -9e+17, Max: -1.099511627776e+12}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + }, + }, + { + name: "Exponential histogram with exact 200 buckets, including positive, negative buckets", + histogramDPS: func() pmetric.ExponentialHistogramDataPointSlice { + histogramDPS := pmetric.NewExponentialHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + posBucketCounts := make([]uint64, 100) + for i := range posBucketCounts { + posBucketCounts[i] = uint64(i + 1) + } + histogramDP.Positive().BucketCounts().FromRaw(posBucketCounts) + negBucketCounts := make([]uint64, 100) + for i := range negBucketCounts { + negBucketCounts[i] = uint64(i + 1) + } + histogramDP.Negative().BucketCounts().FromRaw(negBucketCounts) + histogramDP.SetSum(100000) + histogramDP.SetMin(-9e+36) + histogramDP.SetMax(9e+36) + histogramDP.SetCount(uint64(3662)) + histogramDP.Attributes().PutStr("label1", "value1") + return histogramDPS + }(), + expectedDatapoints: []dataPoint{ + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{ + 9.50737950171172e+29, 4.75368975085586e+29, 2.37684487542793e+29, 1.188422437713965e+29, 5.942112188569825e+28, + 2.9710560942849127e+28, 1.4855280471424563e+28, 7.427640235712282e+27, 3.713820117856141e+27, 1.8569100589280704e+27, + 9.284550294640352e+26, 4.642275147320176e+26, 2.321137573660088e+26, 1.160568786830044e+26, 5.80284393415022e+25, + 2.90142196707511e+25, 1.450710983537555e+25, 7.253554917687775e+24, 3.6267774588438875e+24, 1.8133887294219438e+24, + 9.066943647109719e+23, 4.5334718235548594e+23, 2.2667359117774297e+23, 1.1333679558887149e+23, 5.666839779443574e+22, + 2.833419889721787e+22, 1.4167099448608936e+22, 7.083549724304468e+21, 3.541774862152234e+21, 1.770887431076117e+21, + 8.854437155380585e+20, 4.4272185776902924e+20, 2.2136092888451462e+20, 1.1068046444225731e+20, 5.5340232221128655e+19, + 2.7670116110564327e+19, 1.3835058055282164e+19, 6.917529027641082e+18, 3.458764513820541e+18, 1.7293822569102705e+18, + 8.646911284551352e+17, 4.323455642275676e+17, 2.161727821137838e+17, 1.080863910568919e+17, 5.404319552844595e+16, + 2.7021597764222976e+16, 1.3510798882111488e+16, 6.755399441055744e+15, 3.377699720527872e+15, 1.688849860263936e+15, + 8.44424930131968e+14, 4.22212465065984e+14, 2.11106232532992e+14, 1.05553116266496e+14, 5.2776558133248e+13, + 2.6388279066624e+13, 1.3194139533312e+13, 6.597069766656e+12, 3.298534883328e+12, 1.649267441664e+12, 8.24633720832e+11, + 4.12316860416e+11, 2.06158430208e+11, 1.03079215104e+11, 5.1539607552e+10, 2.5769803776e+10, 1.2884901888e+10, 6.442450944e+09, + 3.221225472e+09, 1.610612736e+09, 8.05306368e+08, 4.02653184e+08, 2.01326592e+08, 1.00663296e+08, 5.0331648e+07, + 2.5165824e+07, 1.2582912e+07, 6.291456e+06, 3.145728e+06, 1.572864e+06, 786432, 393216, 196608, 98304, 49152, 24576, 12288, + 6144, 3072, 1536, 768, 384, 192, 96, 48, 24, 12, 6, 3, 1.5}, + Counts: []float64{ + 100, 99, 98, 97, 96, 95, 94, + 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, + 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, + 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, + Sum: 100000, Count: 5050, Min: 1, Max: 9e+36}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{ + -1.5, -3, -6, -12, -24, -48, -96, -192, -384, -768, -1536, -3072, -6144, -12288, -24576, -49152, -98304, -196608, -393216, + -786432, -1.572864e+06, -3.145728e+06, -6.291456e+06, -1.2582912e+07, -2.5165824e+07, -5.0331648e+07, -1.00663296e+08, + -2.01326592e+08, -4.02653184e+08, -8.05306368e+08, -1.610612736e+09, -3.221225472e+09, -6.442450944e+09, -1.2884901888e+10, + -2.5769803776e+10, -5.1539607552e+10, -1.03079215104e+11, -2.06158430208e+11, -4.12316860416e+11, -8.24633720832e+11, + -1.649267441664e+12, -3.298534883328e+12, -6.597069766656e+12, -1.3194139533312e+13, -2.6388279066624e+13, -5.2776558133248e+13, + -1.05553116266496e+14, -2.11106232532992e+14, -4.22212465065984e+14, -8.44424930131968e+14, -1.688849860263936e+15, + -3.377699720527872e+15, -6.755399441055744e+15, -1.3510798882111488e+16, -2.7021597764222976e+16, + -5.404319552844595e+16, -1.080863910568919e+17, -2.161727821137838e+17, -4.323455642275676e+17, -8.646911284551352e+17, + -1.7293822569102705e+18, -3.458764513820541e+18, -6.917529027641082e+18, -1.3835058055282164e+19, -2.7670116110564327e+19, + -5.5340232221128655e+19, -1.1068046444225731e+20, -2.2136092888451462e+20, -4.4272185776902924e+20, -8.854437155380585e+20, + -1.770887431076117e+21, -3.541774862152234e+21, -7.083549724304468e+21, -1.4167099448608936e+22, -2.833419889721787e+22, + -5.666839779443574e+22, -1.1333679558887149e+23, -2.2667359117774297e+23, -4.5334718235548594e+23, -9.066943647109719e+23, + -1.8133887294219438e+24, -3.6267774588438875e+24, -7.253554917687775e+24, -1.450710983537555e+25, -2.90142196707511e+25, + -5.80284393415022e+25, -1.160568786830044e+26, -2.321137573660088e+26, -4.642275147320176e+26, -9.284550294640352e+26, + -1.8569100589280704e+27, -3.713820117856141e+27, -7.427640235712282e+27, -1.4855280471424563e+28, -2.9710560942849127e+28, + -5.942112188569825e+28, -1.188422437713965e+29, -2.37684487542793e+29, -4.75368975085586e+29, -9.50737950171172e+29}, + Counts: []float64{ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100}, + Sum: 0, Count: 5050, Min: -9e+36, Max: -1}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + }, + }, + { + name: "Exponential histogram with more than 200 buckets, including positive, negative and zero buckets", + histogramDPS: func() pmetric.ExponentialHistogramDataPointSlice { + histogramDPS := pmetric.NewExponentialHistogramDataPointSlice() + histogramDP := histogramDPS.AppendEmpty() + posBucketCounts := make([]uint64, 120) + for i := range posBucketCounts { + posBucketCounts[i] = uint64(i + 1) + } + histogramDP.Positive().BucketCounts().FromRaw(posBucketCounts) + histogramDP.SetZeroCount(2) + negBucketCounts := make([]uint64, 120) + for i := range negBucketCounts { + negBucketCounts[i] = uint64(i + 1) + } + histogramDP.Negative().BucketCounts().FromRaw(negBucketCounts) + histogramDP.SetSum(100000) + histogramDP.SetMin(-9e+36) + histogramDP.SetMax(9e+36) + histogramDP.SetCount(uint64(3662)) + histogramDP.Attributes().PutStr("label1", "value1") + return histogramDPS + }(), + expectedDatapoints: []dataPoint{ + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{ + 9.969209968386869e+35, 4.9846049841934345e+35, 2.4923024920967173e+35, 1.2461512460483586e+35, 6.230756230241793e+34, + 3.1153781151208966e+34, 1.5576890575604483e+34, 7.788445287802241e+33, 3.894222643901121e+33, 1.9471113219505604e+33, + 9.735556609752802e+32, 4.867778304876401e+32, 2.4338891524382005e+32, 1.2169445762191002e+32, 6.084722881095501e+31, + 3.0423614405477506e+31, 1.5211807202738753e+31, 7.605903601369376e+30, 3.802951800684688e+30, 1.901475900342344e+30, + 9.50737950171172e+29, 4.75368975085586e+29, 2.37684487542793e+29, 1.188422437713965e+29, 5.942112188569825e+28, + 2.9710560942849127e+28, 1.4855280471424563e+28, 7.427640235712282e+27, 3.713820117856141e+27, 1.8569100589280704e+27, + 9.284550294640352e+26, 4.642275147320176e+26, 2.321137573660088e+26, 1.160568786830044e+26, 5.80284393415022e+25, + 2.90142196707511e+25, 1.450710983537555e+25, 7.253554917687775e+24, 3.6267774588438875e+24, 1.8133887294219438e+24, + 9.066943647109719e+23, 4.5334718235548594e+23, 2.2667359117774297e+23, 1.1333679558887149e+23, 5.666839779443574e+22, + 2.833419889721787e+22, 1.4167099448608936e+22, 7.083549724304468e+21, 3.541774862152234e+21, 1.770887431076117e+21, + 8.854437155380585e+20, 4.4272185776902924e+20, 2.2136092888451462e+20, 1.1068046444225731e+20, 5.5340232221128655e+19, + 2.7670116110564327e+19, 1.3835058055282164e+19, 6.917529027641082e+18, 3.458764513820541e+18, 1.7293822569102705e+18, + 8.646911284551352e+17, 4.323455642275676e+17, 2.161727821137838e+17, 1.080863910568919e+17, 5.404319552844595e+16, + 2.7021597764222976e+16, 1.3510798882111488e+16, 6.755399441055744e+15, 3.377699720527872e+15, 1.688849860263936e+15, + 8.44424930131968e+14, 4.22212465065984e+14, 2.11106232532992e+14, 1.05553116266496e+14, 5.2776558133248e+13, + 2.6388279066624e+13, 1.3194139533312e+13, 6.597069766656e+12, 3.298534883328e+12, 1.649267441664e+12, 8.24633720832e+11, + 4.12316860416e+11, 2.06158430208e+11, 1.03079215104e+11, 5.1539607552e+10, 2.5769803776e+10, 1.2884901888e+10, + 6.442450944e+09, 3.221225472e+09, 1.610612736e+09, 8.05306368e+08, 4.02653184e+08, 2.01326592e+08, 1.00663296e+08, 5.0331648e+07, + 2.5165824e+07, 1.2582912e+07, 6.291456e+06, 3.145728e+06, 1.572864e+06}, + Counts: []float64{ + 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, + 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, + 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, + 27, 26, 25, 24, 23, 22, 21}, + Sum: 100000, Count: 7050, Min: 1048576, Max: 9e+36}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{ + 786432, 393216, 196608, 98304, 49152, 24576, 12288, 6144, 3072, 1536, 768, 384, 192, 96, 48, 24, + 12, 6, 3, 1.5, 0, -1.5, -3, -6, -12, -24, -48, -96, -192, -384, -768, -1536, + -3072, -6144, -12288, -24576, -49152, -98304, -196608, -393216, -786432, -1.572864e+06, -3.145728e+06, -6.291456e+06, + -1.2582912e+07, -2.5165824e+07, -5.0331648e+07, -1.00663296e+08, -2.01326592e+08, -4.02653184e+08, -8.05306368e+08, + -1.610612736e+09, -3.221225472e+09, -6.442450944e+09, -1.2884901888e+10, -2.5769803776e+10, -5.1539607552e+10, + -1.03079215104e+11, -2.06158430208e+11, -4.12316860416e+11, -8.24633720832e+11, -1.649267441664e+12, + -3.298534883328e+12, -6.597069766656e+12, -1.3194139533312e+13, -2.6388279066624e+13, -5.2776558133248e+13, + -1.05553116266496e+14, -2.11106232532992e+14, -4.22212465065984e+14, -8.44424930131968e+14, + -1.688849860263936e+15, -3.377699720527872e+15, -6.755399441055744e+15, -1.3510798882111488e+16, + -2.7021597764222976e+16, -5.404319552844595e+16, -1.080863910568919e+17, -2.161727821137838e+17, + -4.323455642275676e+17, -8.646911284551352e+17, -1.7293822569102705e+18, -3.458764513820541e+18, + -6.917529027641082e+18, -1.3835058055282164e+19, -2.7670116110564327e+19, -5.5340232221128655e+19, + -1.1068046444225731e+20, -2.2136092888451462e+20, -4.4272185776902924e+20, -8.854437155380585e+20, + -1.770887431076117e+21, -3.541774862152234e+21, -7.083549724304468e+21, -1.4167099448608936e+22, + -2.833419889721787e+22, -5.666839779443574e+22, -1.1333679558887149e+23, -2.2667359117774297e+23, + -4.5334718235548594e+23}, + Counts: []float64{ + 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79}, + Sum: 0, Count: 3372, Min: -6.044629098073146e+23, Max: 1048576}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + { + name: "foo", + value: &cWMetricHistogram{ + Values: []float64{ + -9.066943647109719e+23, -1.8133887294219438e+24, -3.6267774588438875e+24, -7.253554917687775e+24, -1.450710983537555e+25, + -2.90142196707511e+25, -5.80284393415022e+25, -1.160568786830044e+26, -2.321137573660088e+26, -4.642275147320176e+26, + -9.284550294640352e+26, -1.8569100589280704e+27, -3.713820117856141e+27, -7.427640235712282e+27, -1.4855280471424563e+28, + -2.9710560942849127e+28, -5.942112188569825e+28, -1.188422437713965e+29, -2.37684487542793e+29, -4.75368975085586e+29, + -9.50737950171172e+29, -1.901475900342344e+30, -3.802951800684688e+30, -7.605903601369376e+30, -1.5211807202738753e+31, + -3.0423614405477506e+31, -6.084722881095501e+31, -1.2169445762191002e+32, -2.4338891524382005e+32, -4.867778304876401e+32, + -9.735556609752802e+32, -1.9471113219505604e+33, -3.894222643901121e+33, -7.788445287802241e+33, -1.5576890575604483e+34, + -3.1153781151208966e+34, -6.230756230241793e+34, -1.2461512460483586e+35, -2.4923024920967173e+35, -4.9846049841934345e+35, + -9.969209968386869e+35}, + Counts: []float64{ + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120}, + Sum: 0, Count: 4100, Min: -9e+36, Max: -6.044629098073146e+23}, + labels: map[string]string{oTellibDimensionKey: instrLibName, "label1": "value1"}, + }, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(_ *testing.T) { + exponentialHistogramDatapointSlice := exponentialHistogramDataPointSlice{dmd, tc.histogramDPS} + emfCalcs := setupEmfCalculators() + defer require.NoError(t, shutdownEmfCalculators(emfCalcs)) + dps, retained := exponentialHistogramDatapointSlice.CalculateDeltaDatapoints(0, instrLibName, false, emfCalcs) + + assert.True(t, retained) + assert.Equal(t, 1, exponentialHistogramDatapointSlice.Len()) + assert.Equal(t, len(tc.expectedDatapoints), len(dps)) + for i, expectedDP := range tc.expectedDatapoints { + assert.Equal(t, expectedDP, dps[i], "datapoint mismatch at index %d", i) + } + }) + } + +} + func TestIsStaleNaNInf_ExponentialHistogramDataPointSlice(t *testing.T) { testCases := []struct { diff --git a/exporter/awsemfexporter/grouped_metric.go b/exporter/awsemfexporter/grouped_metric.go index dd3426cdc2e9..bd896e9c4194 100644 --- a/exporter/awsemfexporter/grouped_metric.go +++ b/exporter/awsemfexporter/grouped_metric.go @@ -57,7 +57,7 @@ func addToGroupedMetric( continue } - for _, dp := range dps { + for i, dp := range dps { labels := dp.labels if metricType, ok := labels["Type"]; ok { @@ -87,6 +87,7 @@ func addToGroupedMetric( } // Extra params to use when grouping metrics + metadata.groupedMetricMetadata.batchIndex = i groupKey := aws.NewKey(metadata.groupedMetricMetadata, labels) if _, ok := groupedMetrics[groupKey]; ok { // if MetricName already exists in metrics map, print warning log diff --git a/exporter/awsemfexporter/grouped_metric_test.go b/exporter/awsemfexporter/grouped_metric_test.go index d2b1a86610f0..6e09d82b7a3e 100644 --- a/exporter/awsemfexporter/grouped_metric_test.go +++ b/exporter/awsemfexporter/grouped_metric_test.go @@ -406,6 +406,43 @@ func TestAddToGroupedMetric(t *testing.T) { assert.Equal(t, expectedLogs, logs.AllUntimed()) }) + t.Run("Duplicate metric names with different metricIndex", func(t *testing.T) { + emfCalcs := setupEmfCalculators() + defer require.NoError(t, shutdownEmfCalculators(emfCalcs)) + groupedMetrics := make(map[any]*groupedMetric) + generateMetrics := []pmetric.Metrics{ + generateTestExponentialHistogramMetricWithLongBuckets("test_multiBucket_metric"), + } + finalOtelMetrics := generateOtelTestMetrics(generateMetrics...) + + rms := finalOtelMetrics.ResourceMetrics() + ilms := rms.At(0).ScopeMetrics() + metrics := ilms.At(0).Metrics() + assert.Equal(t, 1, metrics.Len()) + + for i := 0; i < metrics.Len(); i++ { + err := addToGroupedMetric(metrics.At(i), + groupedMetrics, + generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, metrics.At(i).Type()), + true, + nil, + testCfg, + emfCalcs, + ) + assert.NoError(t, err) + } + assert.Equal(t, 2, len(groupedMetrics)) + expectedLabels := map[string]string{oTellibDimensionKey: instrumentationLibName, "label1": "value1"} + idx := 0 + for _, v := range groupedMetrics { + assert.Equal(t, 1, len(v.metrics)) + assert.Equal(t, 2, len(v.labels)) + assert.Equal(t, generateTestMetricMetadata(namespace, timestamp, logGroup, logStreamName, instrumentationLibName, metrics.At(0).Type(), idx), v.metadata) + assert.Equal(t, expectedLabels, v.labels) + idx++ + } + }) + } func TestAddKubernetesWrapper(t *testing.T) { @@ -508,7 +545,11 @@ func TestTranslateUnit(t *testing.T) { assert.Equal(t, "Count", v) } -func generateTestMetricMetadata(namespace string, timestamp int64, logGroup, logStreamName, instrumentationScopeName string, metricType pmetric.MetricType) cWMetricMetadata { +func generateTestMetricMetadata(namespace string, timestamp int64, logGroup, logStreamName, instrumentationScopeName string, metricType pmetric.MetricType, batchIndex ...int) cWMetricMetadata { + mIndex := 0 + if len(batchIndex) > 0 { + mIndex = batchIndex[0] + } return cWMetricMetadata{ receiver: prometheusReceiver, groupedMetricMetadata: groupedMetricMetadata{ @@ -517,6 +558,7 @@ func generateTestMetricMetadata(namespace string, timestamp int64, logGroup, log logGroup: logGroup, logStream: logStreamName, metricDataType: metricType, + batchIndex: mIndex, }, instrumentationScopeName: instrumentationScopeName, } diff --git a/exporter/awsemfexporter/metric_translator.go b/exporter/awsemfexporter/metric_translator.go index 26aba7bd368e..3b35979a5394 100644 --- a/exporter/awsemfexporter/metric_translator.go +++ b/exporter/awsemfexporter/metric_translator.go @@ -75,6 +75,7 @@ type groupedMetricMetadata struct { logGroup string logStream string metricDataType pmetric.MetricType + batchIndex int retainInitialValueForDelta bool } @@ -140,6 +141,7 @@ func (mt metricTranslator) translateOTelToGroupedMetric(rm pmetric.ResourceMetri logGroup: logGroup, logStream: logStream, metricDataType: metric.Type(), + batchIndex: 0, retainInitialValueForDelta: deltaInitialValue, }, instrumentationScopeName: instrumentationScopeName,