From c56d20e9e0afccc43179da12f60e24e5729caca9 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Thu, 19 May 2022 14:11:45 -0700 Subject: [PATCH] [otlp] add optional min/max fields to histograms (#5399) * [otlp] add optional min/max fields to histograms Fixes #5380 * update changelog * don't bother defining reusable variables --- CHANGELOG.md | 1 + .../cmd/pdatagen/internal/metrics_structs.go | 36 +++++++++ pdata/internal/generated_pmetric.go | 80 +++++++++++++++++++ pdata/internal/generated_pmetric_test.go | 36 +++++++++ 4 files changed, 153 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d42bf27011..3692f06d5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ ### 💡 Enhancements 💡 - Update OTLP to v0.17.0 (#5335) + - Add optional min/max fields to histograms (#5399) ### 🧰 Bug fixes 🧰 diff --git a/pdata/internal/cmd/pdatagen/internal/metrics_structs.go b/pdata/internal/cmd/pdatagen/internal/metrics_structs.go index a3023fc87f5..5db1decbe03 100644 --- a/pdata/internal/cmd/pdatagen/internal/metrics_structs.go +++ b/pdata/internal/cmd/pdatagen/internal/metrics_structs.go @@ -289,6 +289,24 @@ var histogramDataPoint = &messageValueStruct{ explicitBoundsField, exemplarsField, dataPointFlagsField, + &optionalPrimitiveValue{ + fieldName: "Min", + fieldType: "Double", + originFieldName: "Min", + originTypePrefix: "otlpmetrics.HistogramDataPoint_", + returnType: "float64", + defaultVal: "float64(0.0)", + testVal: "float64(9.23)", + }, + &optionalPrimitiveValue{ + fieldName: "Max", + fieldType: "Double", + originFieldName: "Max", + originTypePrefix: "otlpmetrics.HistogramDataPoint_", + returnType: "float64", + defaultVal: "float64(0.0)", + testVal: "float64(182.55)", + }, }, } @@ -338,6 +356,24 @@ var exponentialHistogramDataPoint = &messageValueStruct{ }, exemplarsField, dataPointFlagsField, + &optionalPrimitiveValue{ + fieldName: "Min", + fieldType: "Double", + originFieldName: "Min", + originTypePrefix: "otlpmetrics.ExponentialHistogramDataPoint_", + returnType: "float64", + defaultVal: "float64(0.0)", + testVal: "float64(9.23)", + }, + &optionalPrimitiveValue{ + fieldName: "Max", + fieldType: "Double", + originFieldName: "Max", + originTypePrefix: "otlpmetrics.ExponentialHistogramDataPoint_", + returnType: "float64", + defaultVal: "float64(0.0)", + testVal: "float64(182.55)", + }, }, } diff --git a/pdata/internal/generated_pmetric.go b/pdata/internal/generated_pmetric.go index 7806df195ac..abdf3b7019c 100644 --- a/pdata/internal/generated_pmetric.go +++ b/pdata/internal/generated_pmetric.go @@ -1479,6 +1479,38 @@ func (ms HistogramDataPoint) SetFlags(v MetricDataPointFlags) { (*ms.orig).Flags = uint32(v) } +// Min returns the min associated with this HistogramDataPoint. +func (ms HistogramDataPoint) Min() float64 { + return (*ms.orig).GetMin() +} + +// HasMin returns true if the HistogramDataPoint contains a +// Min value, false otherwise. +func (ms HistogramDataPoint) HasMin() bool { + return ms.orig.Min_ != nil +} + +// SetMin replaces the min associated with this HistogramDataPoint. +func (ms HistogramDataPoint) SetMin(v float64) { + (*ms.orig).Min_ = &otlpmetrics.HistogramDataPoint_Min{Min: v} +} + +// Max returns the max associated with this HistogramDataPoint. +func (ms HistogramDataPoint) Max() float64 { + return (*ms.orig).GetMax() +} + +// HasMax returns true if the HistogramDataPoint contains a +// Max value, false otherwise. +func (ms HistogramDataPoint) HasMax() bool { + return ms.orig.Max_ != nil +} + +// SetMax replaces the max associated with this HistogramDataPoint. +func (ms HistogramDataPoint) SetMax(v float64) { + (*ms.orig).Max_ = &otlpmetrics.HistogramDataPoint_Max{Max: v} +} + // CopyTo copies all properties from the current struct to the dest. func (ms HistogramDataPoint) CopyTo(dest HistogramDataPoint) { ms.Attributes().CopyTo(dest.Attributes()) @@ -1505,6 +1537,14 @@ func (ms HistogramDataPoint) CopyTo(dest HistogramDataPoint) { ms.Exemplars().CopyTo(dest.Exemplars()) dest.SetFlags(ms.Flags()) + if ms.HasMin() { + dest.SetMin(ms.Min()) + } + + if ms.HasMax() { + dest.SetMax(ms.Max()) + } + } // ExponentialHistogramDataPointSlice logically represents a slice of ExponentialHistogramDataPoint. @@ -1767,6 +1807,38 @@ func (ms ExponentialHistogramDataPoint) SetFlags(v MetricDataPointFlags) { (*ms.orig).Flags = uint32(v) } +// Min returns the min associated with this ExponentialHistogramDataPoint. +func (ms ExponentialHistogramDataPoint) Min() float64 { + return (*ms.orig).GetMin() +} + +// HasMin returns true if the ExponentialHistogramDataPoint contains a +// Min value, false otherwise. +func (ms ExponentialHistogramDataPoint) HasMin() bool { + return ms.orig.Min_ != nil +} + +// SetMin replaces the min associated with this ExponentialHistogramDataPoint. +func (ms ExponentialHistogramDataPoint) SetMin(v float64) { + (*ms.orig).Min_ = &otlpmetrics.ExponentialHistogramDataPoint_Min{Min: v} +} + +// Max returns the max associated with this ExponentialHistogramDataPoint. +func (ms ExponentialHistogramDataPoint) Max() float64 { + return (*ms.orig).GetMax() +} + +// HasMax returns true if the ExponentialHistogramDataPoint contains a +// Max value, false otherwise. +func (ms ExponentialHistogramDataPoint) HasMax() bool { + return ms.orig.Max_ != nil +} + +// SetMax replaces the max associated with this ExponentialHistogramDataPoint. +func (ms ExponentialHistogramDataPoint) SetMax(v float64) { + (*ms.orig).Max_ = &otlpmetrics.ExponentialHistogramDataPoint_Max{Max: v} +} + // CopyTo copies all properties from the current struct to the dest. func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoint) { ms.Attributes().CopyTo(dest.Attributes()) @@ -1780,6 +1852,14 @@ func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoin ms.Negative().CopyTo(dest.Negative()) ms.Exemplars().CopyTo(dest.Exemplars()) dest.SetFlags(ms.Flags()) + if ms.HasMin() { + dest.SetMin(ms.Min()) + } + + if ms.HasMax() { + dest.SetMax(ms.Max()) + } + } // Buckets are a set of bucket counts, encoded in a contiguous array of counts. diff --git a/pdata/internal/generated_pmetric_test.go b/pdata/internal/generated_pmetric_test.go index c0706d647be..6e03b5f6440 100644 --- a/pdata/internal/generated_pmetric_test.go +++ b/pdata/internal/generated_pmetric_test.go @@ -1147,6 +1147,22 @@ func TestHistogramDataPoint_Flags(t *testing.T) { assert.EqualValues(t, testValFlags, ms.Flags()) } +func TestHistogramDataPoint_Min(t *testing.T) { + ms := NewHistogramDataPoint() + assert.EqualValues(t, float64(0.0), ms.Min()) + testValMin := float64(9.23) + ms.SetMin(testValMin) + assert.EqualValues(t, testValMin, ms.Min()) +} + +func TestHistogramDataPoint_Max(t *testing.T) { + ms := NewHistogramDataPoint() + assert.EqualValues(t, float64(0.0), ms.Max()) + testValMax := float64(182.55) + ms.SetMax(testValMax) + assert.EqualValues(t, testValMax, ms.Max()) +} + func TestExponentialHistogramDataPointSlice(t *testing.T) { es := NewExponentialHistogramDataPointSlice() assert.EqualValues(t, 0, es.Len()) @@ -1359,6 +1375,22 @@ func TestExponentialHistogramDataPoint_Flags(t *testing.T) { assert.EqualValues(t, testValFlags, ms.Flags()) } +func TestExponentialHistogramDataPoint_Min(t *testing.T) { + ms := NewExponentialHistogramDataPoint() + assert.EqualValues(t, float64(0.0), ms.Min()) + testValMin := float64(9.23) + ms.SetMin(testValMin) + assert.EqualValues(t, testValMin, ms.Min()) +} + +func TestExponentialHistogramDataPoint_Max(t *testing.T) { + ms := NewExponentialHistogramDataPoint() + assert.EqualValues(t, float64(0.0), ms.Max()) + testValMax := float64(182.55) + ms.SetMax(testValMax) + assert.EqualValues(t, testValMax, ms.Max()) +} + func TestBuckets_MoveTo(t *testing.T) { ms := generateTestBuckets() dest := NewBuckets() @@ -2095,6 +2127,8 @@ func fillTestHistogramDataPoint(tv HistogramDataPoint) { tv.SetMExplicitBounds([]float64{1, 2, 3}) fillTestExemplarSlice(tv.Exemplars()) tv.SetFlags(MetricDataPointFlagsNone) + tv.SetMin(float64(9.23)) + tv.SetMax(float64(182.55)) } func generateTestExponentialHistogramDataPointSlice() ExponentialHistogramDataPointSlice { @@ -2129,6 +2163,8 @@ func fillTestExponentialHistogramDataPoint(tv ExponentialHistogramDataPoint) { fillTestBuckets(tv.Negative()) fillTestExemplarSlice(tv.Exemplars()) tv.SetFlags(MetricDataPointFlagsNone) + tv.SetMin(float64(9.23)) + tv.SetMax(float64(182.55)) } func generateTestBuckets() Buckets {