From 600901d87ad8778dddba7a719736280e9f40af9a Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Thu, 3 Nov 2022 11:48:08 +0100 Subject: [PATCH] [pkg/otlp/model] Use min and max fields for delta Histograms and ExponentialHistograms --- .../exponential_histograms_translator.go | 13 ++++- .../model/translator/metrics_translator.go | 9 ++++ .../translator/metrics_translator_test.go | 48 ++++++++++--------- .../otlp-histogram-078c3b47edcb9556.yaml | 11 +++++ 4 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 releasenotes/notes/otlp-histogram-078c3b47edcb9556.yaml diff --git a/pkg/otlp/model/translator/exponential_histograms_translator.go b/pkg/otlp/model/translator/exponential_histograms_translator.go index b0ac9298ad3b44..dd719d1e7ae4cd 100644 --- a/pkg/otlp/model/translator/exponential_histograms_translator.go +++ b/pkg/otlp/model/translator/exponential_histograms_translator.go @@ -78,8 +78,9 @@ func (t *Translator) exponentialHistogramToDDSketch( // - The sum of values in the population // - A scale, from which the base of the exponential histogram is computed // - Two bucket stores, each with: -// - an offset -// - a list of bucket counts +// - an offset +// - a list of bucket counts +// // - A count of zero values in the population func (t *Translator) mapExponentialHistogramMetrics( ctx context.Context, @@ -147,6 +148,14 @@ func (t *Translator) mapExponentialHistogramMetrics( agentSketch.Basic.Sum = histInfo.sum agentSketch.Basic.Avg = agentSketch.Basic.Sum / float64(agentSketch.Basic.Cnt) } + if delta && p.HasMin() { + // override min if available and delta. + agentSketch.Basic.Min = p.Min() + } + if delta && p.HasMax() { + // override max if available and delta. + agentSketch.Basic.Max = p.Max() + } consumer.ConsumeSketch(ctx, pointDims, ts, agentSketch) } diff --git a/pkg/otlp/model/translator/metrics_translator.go b/pkg/otlp/model/translator/metrics_translator.go index 055339322183fc..888c91fa0299f8 100644 --- a/pkg/otlp/model/translator/metrics_translator.go +++ b/pkg/otlp/model/translator/metrics_translator.go @@ -229,6 +229,15 @@ func (t *Translator) getSketchBuckets( sketch.Basic.Sum = histInfo.sum sketch.Basic.Avg = sketch.Basic.Sum / float64(sketch.Basic.Cnt) } + if delta && p.HasMin() { + // override min if available and delta. + sketch.Basic.Min = p.Min() + } + if delta && p.HasMax() { + // override max if available and delta. + sketch.Basic.Max = p.Max() + } + consumer.ConsumeSketch(ctx, pointDims, ts, sketch) } } diff --git a/pkg/otlp/model/translator/metrics_translator_test.go b/pkg/otlp/model/translator/metrics_translator_test.go index 62a9cafa1e6e80..b2d90238d126b9 100644 --- a/pkg/otlp/model/translator/metrics_translator_test.go +++ b/pkg/otlp/model/translator/metrics_translator_test.go @@ -540,6 +540,8 @@ func TestMapDeltaHistogramMetrics(t *testing.T) { point := slice.AppendEmpty() point.SetCount(20) point.SetSum(math.Pi) + point.SetMin(-15) + point.SetMax(100) point.BucketCounts().FromRaw([]uint64{2, 18}) point.ExplicitBounds().FromRaw([]float64{0}) point.SetTimestamp(ts) @@ -568,8 +570,8 @@ func TestMapDeltaHistogramMetrics(t *testing.T) { sketches := []sketch{ newSketch(dims, uint64(ts), summary.Summary{ - Min: 0, - Max: 0, + Min: -15, + Max: 100, Sum: point.Sum(), Avg: point.Sum() / float64(point.Count()), Cnt: int64(point.Count()), @@ -578,8 +580,8 @@ func TestMapDeltaHistogramMetrics(t *testing.T) { sketchesAttributeTags := []sketch{ newSketch(dimsTags, uint64(ts), summary.Summary{ - Min: 0, - Max: 0, + Min: -15, + Max: 100, Sum: point.Sum(), Avg: point.Sum() / float64(point.Count()), Cnt: 20, @@ -1663,8 +1665,8 @@ func TestMapExponentialHistogram(t *testing.T) { expectedMetrics: nil, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: math.Pi / float64(30), Cnt: 30, @@ -1681,8 +1683,8 @@ func TestMapExponentialHistogram(t *testing.T) { expectedMetrics: nil, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1702,8 +1704,8 @@ func TestMapExponentialHistogram(t *testing.T) { }, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1720,8 +1722,8 @@ func TestMapExponentialHistogram(t *testing.T) { expectedMetrics: nil, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1738,8 +1740,8 @@ func TestMapExponentialHistogram(t *testing.T) { expectedMetrics: nil, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1759,8 +1761,8 @@ func TestMapExponentialHistogram(t *testing.T) { }, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1776,8 +1778,8 @@ func TestMapExponentialHistogram(t *testing.T) { withCountSum: false, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1797,8 +1799,8 @@ func TestMapExponentialHistogram(t *testing.T) { }, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1818,8 +1820,8 @@ func TestMapExponentialHistogram(t *testing.T) { }, expectedSketches: []sketch{ newSketchWithHostname("double.exponential.delta.histogram", summary.Summary{ - Min: -1.0475797592879845, - Max: 1.0974563270357618, + Min: -100_000, + Max: 100_000, Sum: math.Pi, Avg: 0.10471975511965977, Cnt: 30, @@ -1908,6 +1910,8 @@ func createTestExponentialHistogram(additionalAttributes map[string]string, name expDeltaHist.SetCount(30) expDeltaHist.SetZeroCount(10) expDeltaHist.SetSum(math.Pi) + expDeltaHist.SetMin(-100_000) + expDeltaHist.SetMax(100_000) expDeltaHist.Negative().SetOffset(2) expDeltaHist.Negative().BucketCounts().FromRaw([]uint64{3, 2, 5}) diff --git a/releasenotes/notes/otlp-histogram-078c3b47edcb9556.yaml b/releasenotes/notes/otlp-histogram-078c3b47edcb9556.yaml new file mode 100644 index 00000000000000..21015d373095fe --- /dev/null +++ b/releasenotes/notes/otlp-histogram-078c3b47edcb9556.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +enhancements: + - | + OTLP ingest now uses the minimum and maximum fields from delta OTLP Histograms and OTLP ExponentialHistograms when available.