Skip to content

Commit

Permalink
[pkg/otlp/model] Use min and max fields for delta Histograms and Expo…
Browse files Browse the repository at this point in the history
…nentialHistograms
  • Loading branch information
mx-psi committed Nov 3, 2022
1 parent 48bb510 commit 600901d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
13 changes: 11 additions & 2 deletions pkg/otlp/model/translator/exponential_histograms_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/otlp/model/translator/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
48 changes: 26 additions & 22 deletions pkg/otlp/model/translator/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()),
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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})
Expand Down
11 changes: 11 additions & 0 deletions releasenotes/notes/otlp-histogram-078c3b47edcb9556.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 600901d

Please sign in to comment.