From 758d58d857b24620f9cf35b83e560554b2bc4038 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Fri, 19 Aug 2022 14:44:53 -0700 Subject: [PATCH 01/17] use the otel-go expo-histogram mapping functions; address boundary conditions --- .../internal/otlptext/databuffer.go | 26 +++---- .../internal/otlptext/metrics.go | 69 +++++++++++++++++- .../internal/otlptext/metrics_test.go | 72 +++++++++++++++++++ 3 files changed, 149 insertions(+), 18 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/databuffer.go b/exporter/loggingexporter/internal/otlptext/databuffer.go index 65a4f6b7b72..a6eae56fa07 100644 --- a/exporter/loggingexporter/internal/otlptext/databuffer.go +++ b/exporter/loggingexporter/internal/otlptext/databuffer.go @@ -17,7 +17,6 @@ package otlptext // import "go.opentelemetry.io/collector/exporter/loggingexport import ( "bytes" "fmt" - "math" "strconv" "strings" @@ -162,16 +161,7 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis b.logEntry("Max: %f", p.Max()) } - scale := int(p.Scale()) - factor := math.Ldexp(math.Ln2, -scale) - // Note: the equation used here, which is - // math.Exp(index * factor) - // reports +Inf as the _lower_ boundary of the bucket nearest - // infinity, which is incorrect and can be addressed in various - // ways. The OTel-Go implementation of this histogram pending - // in https://github.com/open-telemetry/opentelemetry-go/pull/2393 - // uses a lookup table for the last finite boundary, which can be - // easily computed using `math/big` (for scales up to 20). + m := newExpoHistoMapping(p.Scale()) negB := p.Negative().BucketCounts() posB := p.Positive().BucketCounts() @@ -179,9 +169,10 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis for i := 0; i < negB.Len(); i++ { pos := negB.Len() - i - 1 index := p.Negative().Offset() + int32(pos) - lower := math.Exp(float64(index) * factor) - upper := math.Exp(float64(index+1) * factor) - b.logEntry("Bucket (%f, %f], Count: %d", -upper, -lower, negB.At(pos)) + b.logEntry("Bucket [%s, %s), Count: %d", + m.stringLowerBoundary(index, true), + m.stringLowerBoundary(index+1, true), + negB.At(pos)) } if p.ZeroCount() != 0 { @@ -190,9 +181,10 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis for pos := 0; pos < posB.Len(); pos++ { index := p.Positive().Offset() + int32(pos) - lower := math.Exp(float64(index) * factor) - upper := math.Exp(float64(index+1) * factor) - b.logEntry("Bucket [%f, %f), Count: %d", lower, upper, posB.At(pos)) + b.logEntry("Bucket (%s, %s], Count: %d", + m.stringLowerBoundary(index, false), + m.stringLowerBoundary(index+1, false), + posB.At(pos)) } } } diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index 6c7a4133764..1c013c4984a 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -14,7 +14,22 @@ package otlptext // import "go.opentelemetry.io/collector/exporter/loggingexporter/internal/otlptext" -import "go.opentelemetry.io/collector/pdata/pmetric" +import ( + "fmt" + + "go.opentelemetry.io/collector/pdata/pmetric" + expohisto "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping" + "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" + "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" +) + +// lastBoundary equals and is the least +// unrepresentable float64 greater than 1. +// Can be computed using +// b := big.NewFloat(1) +// b.SetMantExp(b, 1024) +// return b.String() +const lastBoundary = "1.797693135e+308" // NewTextMetricsMarshaler returns a pmetric.Marshaler to encode to OTLP text bytes. func NewTextMetricsMarshaler() pmetric.Marshaler { @@ -50,3 +65,55 @@ func (textMetricsMarshaler) MarshalMetrics(md pmetric.Metrics) ([]byte, error) { return buf.buf.Bytes(), nil } + +type expoHistoMapping struct { + scale int32 + mapping expohisto.Mapping +} + +func newExpoHistoMapping(scale int32) expoHistoMapping { + m := expoHistoMapping{ + scale: scale, + } + if scale >= exponent.MinScale && scale <= exponent.MaxScale { + m.mapping, _ = exponent.NewMapping(int32(scale)) + } else if scale >= logarithm.MinScale && scale <= logarithm.MaxScale { + m.mapping, _ = logarithm.NewMapping(int32(scale)) + } + return m +} + +func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { + // Use the otel-go mapping functions provided the scale and + // index are in range. + if ehm.mapping != nil { + if bound, err := ehm.mapping.LowerBoundary(idx); err == nil { + if neg { + bound = -bound + } + return fmt.Sprintf("%g", bound) + } + } + + var s string + if idx == 0 { + s = "1" + } else if idx > 0 { + // Note: at scale 20, the value (1<<30) leads to exponent 1024 + // The following expression generalizes this for valid scales. + if ehm.scale >= -10 && ehm.scale <= 20 && int64(idx)<<(20-ehm.scale) == 1<<30 { + // Important special case equal to 0x1p1024 is + // the upper boundary of the last valid bucket + // at all scales. + s = lastBoundary + } else { + s = "OVERFLOW" + } + } else { + s = "UNDERFLOW" + } + if neg { + s = "-" + s + } + return s +} diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index cb6a7cbbc41..50b612f222b 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -15,12 +15,17 @@ package otlptext import ( + "fmt" + "math/big" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" + "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" ) func TestMetricsText(t *testing.T) { @@ -48,3 +53,70 @@ func TestMetricsText(t *testing.T) { }) } } + +func TestExpoHistoOverflowMapping(t *testing.T) { + // Compute the string value of 0x1p+1024 + b := big.NewFloat(1) + b.SetMantExp(b, 1024) + expect := b.String() + + // For positive scales, the +Inf threshold happens at 1024<>-scale + for scale := exponent.MinScale; scale <= exponent.MaxScale; scale++ { + m := newExpoHistoMapping(scale) + threshold := int32(1024) >> -scale + + require.Equal(t, expect, m.stringLowerBoundary(threshold, false)) + require.Equal(t, "-"+expect, m.stringLowerBoundary(threshold, true)) + + require.Equal(t, "OVERFLOW", m.stringLowerBoundary(threshold+1, false)) + require.Equal(t, "-OVERFLOW", m.stringLowerBoundary(threshold+1, true)) + } + + // For an invalid scale, any positive index overflows + invalid := newExpoHistoMapping(100) + + require.Equal(t, "OVERFLOW", invalid.stringLowerBoundary(1, false)) + require.Equal(t, "-OVERFLOW", invalid.stringLowerBoundary(1, true)) + + // But index 0 always works + require.Equal(t, "1", invalid.stringLowerBoundary(0, false)) + require.Equal(t, "-1", invalid.stringLowerBoundary(0, true)) +} + +func TestExpoHistoUnderflowMapping(t *testing.T) { + // For all valid scales + for scale := int32(-10); scale <= 20; scale++ { + m := newExpoHistoMapping(scale) + idx := m.mapping.MapToIndex(0x1p-1022) + lb, err := m.mapping.LowerBoundary(idx) + require.NoError(t, err) + + require.Equal(t, fmt.Sprintf("%g", lb), m.stringLowerBoundary(idx, false)) + require.Equal(t, fmt.Sprintf("-%g", lb), m.stringLowerBoundary(idx, true)) + + require.Equal(t, "UNDERFLOW", m.stringLowerBoundary(idx-1, false)) + require.Equal(t, "-UNDERFLOW", m.stringLowerBoundary(idx-1, true)) + } + + // For an invalid scale, any positive index overflows + invalid := newExpoHistoMapping(100) + + require.Equal(t, "UNDERFLOW", invalid.stringLowerBoundary(-1, false)) + require.Equal(t, "-UNDERFLOW", invalid.stringLowerBoundary(-1, true)) +} From 9fae565c356a6954561e4f1145ee7d439c16f1c0 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Fri, 19 Aug 2022 14:53:16 -0700 Subject: [PATCH 02/17] add TODO about subnormals --- exporter/loggingexporter/internal/otlptext/metrics.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index 1c013c4984a..28819fae2b3 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -110,6 +110,12 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { s = "OVERFLOW" } } else { + // TODO: corner cases involving subnormal values may + // be handled here. These are considered out of range + // by the otel-go mapping functions, which will return + // an underflow error for buckets that are entirely + // outside the normal range. These measurements are not + // necessarily invalid, but they are extra work to compute. s = "UNDERFLOW" } if neg { From 171e04a763a3de52cc9ac0414bb6639adc984b6d Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Fri, 19 Aug 2022 15:28:37 -0700 Subject: [PATCH 03/17] fmt --- exporter/loggingexporter/internal/otlptext/metrics.go | 3 ++- exporter/loggingexporter/internal/otlptext/metrics_test.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index 28819fae2b3..74451809dd0 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -17,10 +17,11 @@ package otlptext // import "go.opentelemetry.io/collector/exporter/loggingexport import ( "fmt" - "go.opentelemetry.io/collector/pdata/pmetric" expohisto "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping" "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" + + "go.opentelemetry.io/collector/pdata/pmetric" ) // lastBoundary equals and is the least diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 50b612f222b..09c3ee05287 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -22,10 +22,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" + + "go.opentelemetry.io/collector/internal/testdata" + "go.opentelemetry.io/collector/pdata/pmetric" ) func TestMetricsText(t *testing.T) { From 84a858b4db6e0661b2d96c750cb6d1efbc81161a Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Wed, 24 Aug 2022 13:05:31 -0700 Subject: [PATCH 04/17] gocritic --- exporter/loggingexporter/internal/otlptext/metrics.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index 74451809dd0..d22b72f21e0 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -77,9 +77,9 @@ func newExpoHistoMapping(scale int32) expoHistoMapping { scale: scale, } if scale >= exponent.MinScale && scale <= exponent.MaxScale { - m.mapping, _ = exponent.NewMapping(int32(scale)) + m.mapping, _ = exponent.NewMapping(scale) } else if scale >= logarithm.MinScale && scale <= logarithm.MaxScale { - m.mapping, _ = logarithm.NewMapping(int32(scale)) + m.mapping, _ = logarithm.NewMapping(scale) } return m } @@ -97,9 +97,10 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { } var s string - if idx == 0 { + switch { + case idx == 0: s = "1" - } else if idx > 0 { + case idx > 0: // Note: at scale 20, the value (1<<30) leads to exponent 1024 // The following expression generalizes this for valid scales. if ehm.scale >= -10 && ehm.scale <= 20 && int64(idx)<<(20-ehm.scale) == 1<<30 { @@ -110,7 +111,7 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { } else { s = "OVERFLOW" } - } else { + default: // TODO: corner cases involving subnormal values may // be handled here. These are considered out of range // by the otel-go mapping functions, which will return From a0396603efc0b7f7ab54a676f8c6eaa4565082e7 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Wed, 24 Aug 2022 14:10:15 -0700 Subject: [PATCH 05/17] make genpdata --- pdata/internal/generated_common.go | 22 ++- pdata/internal/generated_plog.go | 94 +++++----- pdata/internal/generated_pmetric.go | 270 +++++++++++++--------------- pdata/internal/generated_ptrace.go | 155 ++++++++-------- pdata/plog/generated_alias.go | 1 + 5 files changed, 246 insertions(+), 296 deletions(-) diff --git a/pdata/internal/generated_common.go b/pdata/internal/generated_common.go index 08df2d6c412..72d1daade40 100644 --- a/pdata/internal/generated_common.go +++ b/pdata/internal/generated_common.go @@ -128,11 +128,10 @@ func (es Slice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es Slice) At(ix int) Value { return newValue(&(*es.orig)[ix]) } @@ -157,13 +156,12 @@ func (es Slice) CopyTo(dest Slice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new Slice can be initialized: -// -// es := NewSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es Slice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { diff --git a/pdata/internal/generated_plog.go b/pdata/internal/generated_plog.go index 7969e4b5f39..3042dfd9291 100644 --- a/pdata/internal/generated_plog.go +++ b/pdata/internal/generated_plog.go @@ -57,11 +57,10 @@ func (es ResourceLogsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ResourceLogsSlice) At(ix int) ResourceLogs { return newResourceLogs((*es.orig)[ix]) } @@ -91,13 +90,12 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ResourceLogsSlice can be initialized: -// -// es := NewResourceLogsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewResourceLogsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ResourceLogsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -121,11 +119,10 @@ func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ResourceLogs) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ResourceLogs) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool) ResourceLogsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -254,11 +251,10 @@ func (es ScopeLogsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ScopeLogsSlice) At(ix int) ScopeLogs { return newScopeLogs((*es.orig)[ix]) } @@ -288,13 +284,12 @@ func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ScopeLogsSlice can be initialized: -// -// es := NewScopeLogsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewScopeLogsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ScopeLogsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -318,11 +313,10 @@ func (es ScopeLogsSlice) AppendEmpty() ScopeLogs { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ScopeLogs) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ScopeLogs) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ScopeLogsSlice) Sort(less func(a, b ScopeLogs) bool) ScopeLogsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -451,11 +445,10 @@ func (es LogRecordSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es LogRecordSlice) At(ix int) LogRecord { return newLogRecord((*es.orig)[ix]) } @@ -485,13 +478,12 @@ func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new LogRecordSlice can be initialized: -// -// es := NewLogRecordSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewLogRecordSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es LogRecordSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -515,11 +507,10 @@ func (es LogRecordSlice) AppendEmpty() LogRecord { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b LogRecord) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b LogRecord) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es LogRecordSlice) Sort(less func(a, b LogRecord) bool) LogRecordSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -559,6 +550,7 @@ func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool) { // LogRecord are experimental implementation of OpenTelemetry Log Data Model. +// // This is a reference type, if passed by value and callee modifies it the // caller will see the modification. // diff --git a/pdata/internal/generated_pmetric.go b/pdata/internal/generated_pmetric.go index e73b6426c6c..2c295bc422a 100644 --- a/pdata/internal/generated_pmetric.go +++ b/pdata/internal/generated_pmetric.go @@ -57,11 +57,10 @@ func (es ResourceMetricsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ResourceMetricsSlice) At(ix int) ResourceMetrics { return newResourceMetrics((*es.orig)[ix]) } @@ -91,13 +90,12 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ResourceMetricsSlice can be initialized: -// -// es := NewResourceMetricsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewResourceMetricsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ResourceMetricsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -121,11 +119,10 @@ func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ResourceMetrics) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ResourceMetrics) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ResourceMetricsSlice) Sort(less func(a, b ResourceMetrics) bool) ResourceMetricsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -254,11 +251,10 @@ func (es ScopeMetricsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ScopeMetricsSlice) At(ix int) ScopeMetrics { return newScopeMetrics((*es.orig)[ix]) } @@ -288,13 +284,12 @@ func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ScopeMetricsSlice can be initialized: -// -// es := NewScopeMetricsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewScopeMetricsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ScopeMetricsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -318,11 +313,10 @@ func (es ScopeMetricsSlice) AppendEmpty() ScopeMetrics { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ScopeMetrics) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ScopeMetrics) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ScopeMetricsSlice) Sort(less func(a, b ScopeMetrics) bool) ScopeMetricsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -451,11 +445,10 @@ func (es MetricSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es MetricSlice) At(ix int) Metric { return newMetric((*es.orig)[ix]) } @@ -485,13 +478,12 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new MetricSlice can be initialized: -// -// es := NewMetricSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewMetricSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es MetricSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -515,11 +507,10 @@ func (es MetricSlice) AppendEmpty() Metric { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b Metric) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b Metric) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es MetricSlice) Sort(less func(a, b Metric) bool) MetricSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1010,11 +1001,10 @@ func (es NumberDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es NumberDataPointSlice) At(ix int) NumberDataPoint { return newNumberDataPoint((*es.orig)[ix]) } @@ -1044,13 +1034,12 @@ func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new NumberDataPointSlice can be initialized: -// -// es := NewNumberDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewNumberDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es NumberDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1074,11 +1063,10 @@ func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b NumberDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b NumberDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es NumberDataPointSlice) Sort(less func(a, b NumberDataPoint) bool) NumberDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1267,11 +1255,10 @@ func (es HistogramDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es HistogramDataPointSlice) At(ix int) HistogramDataPoint { return newHistogramDataPoint((*es.orig)[ix]) } @@ -1301,13 +1288,12 @@ func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new HistogramDataPointSlice can be initialized: -// -// es := NewHistogramDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewHistogramDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es HistogramDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1331,11 +1317,10 @@ func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b HistogramDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b HistogramDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es HistogramDataPointSlice) Sort(less func(a, b HistogramDataPoint) bool) HistogramDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1586,11 +1571,10 @@ func (es ExponentialHistogramDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ExponentialHistogramDataPointSlice) At(ix int) ExponentialHistogramDataPoint { return newExponentialHistogramDataPoint((*es.orig)[ix]) } @@ -1620,13 +1604,12 @@ func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDat // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ExponentialHistogramDataPointSlice can be initialized: -// -// es := NewExponentialHistogramDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewExponentialHistogramDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ExponentialHistogramDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1650,11 +1633,10 @@ func (es ExponentialHistogramDataPointSlice) AppendEmpty() ExponentialHistogramD // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ExponentialHistogramDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ExponentialHistogramDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ExponentialHistogramDataPointSlice) Sort(less func(a, b ExponentialHistogramDataPoint) bool) ExponentialHistogramDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1970,11 +1952,10 @@ func (es SummaryDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SummaryDataPointSlice) At(ix int) SummaryDataPoint { return newSummaryDataPoint((*es.orig)[ix]) } @@ -2004,13 +1985,12 @@ func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SummaryDataPointSlice can be initialized: -// -// es := NewSummaryDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewSummaryDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SummaryDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -2034,11 +2014,10 @@ func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b SummaryDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b SummaryDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SummaryDataPointSlice) Sort(less func(a, b SummaryDataPoint) bool) SummaryDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -2206,11 +2185,10 @@ func (es ValueAtQuantileSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ValueAtQuantileSlice) At(ix int) ValueAtQuantile { return newValueAtQuantile((*es.orig)[ix]) } @@ -2240,13 +2218,12 @@ func (es ValueAtQuantileSlice) CopyTo(dest ValueAtQuantileSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ValueAtQuantileSlice can be initialized: -// -// es := NewValueAtQuantileSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewValueAtQuantileSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ValueAtQuantileSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -2270,11 +2247,10 @@ func (es ValueAtQuantileSlice) AppendEmpty() ValueAtQuantile { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ValueAtQuantile) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ValueAtQuantile) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ValueAtQuantileSlice) Sort(less func(a, b ValueAtQuantile) bool) ValueAtQuantileSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -2402,11 +2378,10 @@ func (es ExemplarSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ExemplarSlice) At(ix int) Exemplar { return newExemplar(&(*es.orig)[ix]) } @@ -2431,13 +2406,12 @@ func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ExemplarSlice can be initialized: -// -// es := NewExemplarSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewExemplarSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ExemplarSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { diff --git a/pdata/internal/generated_ptrace.go b/pdata/internal/generated_ptrace.go index 5f17d6f362b..92cb9bfa248 100644 --- a/pdata/internal/generated_ptrace.go +++ b/pdata/internal/generated_ptrace.go @@ -57,11 +57,10 @@ func (es ResourceSpansSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ResourceSpansSlice) At(ix int) ResourceSpans { return newResourceSpans((*es.orig)[ix]) } @@ -91,13 +90,12 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ResourceSpansSlice can be initialized: -// -// es := NewResourceSpansSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewResourceSpansSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ResourceSpansSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -121,11 +119,10 @@ func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ResourceSpans) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ResourceSpans) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ResourceSpansSlice) Sort(less func(a, b ResourceSpans) bool) ResourceSpansSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -254,11 +251,10 @@ func (es ScopeSpansSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ScopeSpansSlice) At(ix int) ScopeSpans { return newScopeSpans((*es.orig)[ix]) } @@ -288,13 +284,12 @@ func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ScopeSpansSlice can be initialized: -// -// es := NewScopeSpansSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewScopeSpansSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ScopeSpansSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -318,11 +313,10 @@ func (es ScopeSpansSlice) AppendEmpty() ScopeSpans { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b ScopeSpans) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b ScopeSpans) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ScopeSpansSlice) Sort(less func(a, b ScopeSpans) bool) ScopeSpansSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -451,11 +445,10 @@ func (es SpanSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SpanSlice) At(ix int) Span { return newSpan((*es.orig)[ix]) } @@ -485,13 +478,12 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SpanSlice can be initialized: -// -// es := NewSpanSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewSpanSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SpanSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -515,11 +507,10 @@ func (es SpanSlice) AppendEmpty() Span { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b Span) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b Span) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SpanSlice) Sort(less func(a, b Span) bool) SpanSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -771,11 +762,10 @@ func (es SpanEventSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SpanEventSlice) At(ix int) SpanEvent { return newSpanEvent((*es.orig)[ix]) } @@ -805,13 +795,12 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SpanEventSlice can be initialized: -// -// es := NewSpanEventSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewSpanEventSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SpanEventSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -835,11 +824,10 @@ func (es SpanEventSlice) AppendEmpty() SpanEvent { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b SpanEvent) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b SpanEvent) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SpanEventSlice) Sort(less func(a, b SpanEvent) bool) SpanEventSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -985,11 +973,10 @@ func (es SpanLinkSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SpanLinkSlice) At(ix int) SpanLink { return newSpanLink((*es.orig)[ix]) } @@ -1019,13 +1006,12 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SpanLinkSlice can be initialized: -// -// es := NewSpanLinkSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// es := NewSpanLinkSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SpanLinkSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1049,11 +1035,10 @@ func (es SpanLinkSlice) AppendEmpty() SpanLink { // can be compared. // // Returns the same instance to allow nicer code like: -// -// lessFunc := func(a, b SpanLink) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// lessFunc := func(a, b SpanLink) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SpanLinkSlice) Sort(less func(a, b SpanLink) bool) SpanLinkSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es diff --git a/pdata/plog/generated_alias.go b/pdata/plog/generated_alias.go index e9d9fdb8ba3..aacb32d4343 100644 --- a/pdata/plog/generated_alias.go +++ b/pdata/plog/generated_alias.go @@ -84,6 +84,7 @@ var NewLogRecordSlice = internal.NewLogRecordSlice // LogRecord are experimental implementation of OpenTelemetry Log Data Model. +// // This is a reference type, if passed by value and callee modifies it the // caller will see the modification. // From dcce4a1e885e9fb291325967c268da81e72d3fcb Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Wed, 24 Aug 2022 14:47:37 -0700 Subject: [PATCH 06/17] gofmt-1.19 --- .../internal/otlptext/metrics.go | 7 +- .../internal/otlptext/metrics_test.go | 1 - pdata/internal/generated_common.go | 22 +- pdata/internal/generated_plog.go | 94 +++--- pdata/internal/generated_pmetric.go | 270 ++++++++++-------- pdata/internal/generated_ptrace.go | 155 +++++----- pdata/plog/generated_alias.go | 1 - 7 files changed, 300 insertions(+), 250 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index d22b72f21e0..266dde9c1df 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -27,9 +27,10 @@ import ( // lastBoundary equals and is the least // unrepresentable float64 greater than 1. // Can be computed using -// b := big.NewFloat(1) -// b.SetMantExp(b, 1024) -// return b.String() +// +// b := big.NewFloat(1) +// b.SetMantExp(b, 1024) +// return b.String() const lastBoundary = "1.797693135e+308" // NewTextMetricsMarshaler returns a pmetric.Marshaler to encode to OTLP text bytes. diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 09c3ee05287..6e3912af170 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -21,7 +21,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" diff --git a/pdata/internal/generated_common.go b/pdata/internal/generated_common.go index 72d1daade40..08df2d6c412 100644 --- a/pdata/internal/generated_common.go +++ b/pdata/internal/generated_common.go @@ -128,10 +128,11 @@ func (es Slice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es Slice) At(ix int) Value { return newValue(&(*es.orig)[ix]) } @@ -156,12 +157,13 @@ func (es Slice) CopyTo(dest Slice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new Slice can be initialized: -// es := NewSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es Slice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { diff --git a/pdata/internal/generated_plog.go b/pdata/internal/generated_plog.go index 3042dfd9291..7969e4b5f39 100644 --- a/pdata/internal/generated_plog.go +++ b/pdata/internal/generated_plog.go @@ -57,10 +57,11 @@ func (es ResourceLogsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ResourceLogsSlice) At(ix int) ResourceLogs { return newResourceLogs((*es.orig)[ix]) } @@ -90,12 +91,13 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ResourceLogsSlice can be initialized: -// es := NewResourceLogsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewResourceLogsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ResourceLogsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -119,10 +121,11 @@ func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ResourceLogs) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ResourceLogs) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool) ResourceLogsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -251,10 +254,11 @@ func (es ScopeLogsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ScopeLogsSlice) At(ix int) ScopeLogs { return newScopeLogs((*es.orig)[ix]) } @@ -284,12 +288,13 @@ func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ScopeLogsSlice can be initialized: -// es := NewScopeLogsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewScopeLogsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ScopeLogsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -313,10 +318,11 @@ func (es ScopeLogsSlice) AppendEmpty() ScopeLogs { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ScopeLogs) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ScopeLogs) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ScopeLogsSlice) Sort(less func(a, b ScopeLogs) bool) ScopeLogsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -445,10 +451,11 @@ func (es LogRecordSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es LogRecordSlice) At(ix int) LogRecord { return newLogRecord((*es.orig)[ix]) } @@ -478,12 +485,13 @@ func (es LogRecordSlice) CopyTo(dest LogRecordSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new LogRecordSlice can be initialized: -// es := NewLogRecordSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewLogRecordSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es LogRecordSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -507,10 +515,11 @@ func (es LogRecordSlice) AppendEmpty() LogRecord { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b LogRecord) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b LogRecord) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es LogRecordSlice) Sort(less func(a, b LogRecord) bool) LogRecordSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -550,7 +559,6 @@ func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool) { // LogRecord are experimental implementation of OpenTelemetry Log Data Model. -// // This is a reference type, if passed by value and callee modifies it the // caller will see the modification. // diff --git a/pdata/internal/generated_pmetric.go b/pdata/internal/generated_pmetric.go index 2c295bc422a..e73b6426c6c 100644 --- a/pdata/internal/generated_pmetric.go +++ b/pdata/internal/generated_pmetric.go @@ -57,10 +57,11 @@ func (es ResourceMetricsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ResourceMetricsSlice) At(ix int) ResourceMetrics { return newResourceMetrics((*es.orig)[ix]) } @@ -90,12 +91,13 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ResourceMetricsSlice can be initialized: -// es := NewResourceMetricsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewResourceMetricsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ResourceMetricsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -119,10 +121,11 @@ func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ResourceMetrics) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ResourceMetrics) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ResourceMetricsSlice) Sort(less func(a, b ResourceMetrics) bool) ResourceMetricsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -251,10 +254,11 @@ func (es ScopeMetricsSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ScopeMetricsSlice) At(ix int) ScopeMetrics { return newScopeMetrics((*es.orig)[ix]) } @@ -284,12 +288,13 @@ func (es ScopeMetricsSlice) CopyTo(dest ScopeMetricsSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ScopeMetricsSlice can be initialized: -// es := NewScopeMetricsSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewScopeMetricsSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ScopeMetricsSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -313,10 +318,11 @@ func (es ScopeMetricsSlice) AppendEmpty() ScopeMetrics { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ScopeMetrics) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ScopeMetrics) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ScopeMetricsSlice) Sort(less func(a, b ScopeMetrics) bool) ScopeMetricsSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -445,10 +451,11 @@ func (es MetricSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es MetricSlice) At(ix int) Metric { return newMetric((*es.orig)[ix]) } @@ -478,12 +485,13 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new MetricSlice can be initialized: -// es := NewMetricSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewMetricSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es MetricSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -507,10 +515,11 @@ func (es MetricSlice) AppendEmpty() Metric { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b Metric) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b Metric) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es MetricSlice) Sort(less func(a, b Metric) bool) MetricSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1001,10 +1010,11 @@ func (es NumberDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es NumberDataPointSlice) At(ix int) NumberDataPoint { return newNumberDataPoint((*es.orig)[ix]) } @@ -1034,12 +1044,13 @@ func (es NumberDataPointSlice) CopyTo(dest NumberDataPointSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new NumberDataPointSlice can be initialized: -// es := NewNumberDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewNumberDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es NumberDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1063,10 +1074,11 @@ func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b NumberDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b NumberDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es NumberDataPointSlice) Sort(less func(a, b NumberDataPoint) bool) NumberDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1255,10 +1267,11 @@ func (es HistogramDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es HistogramDataPointSlice) At(ix int) HistogramDataPoint { return newHistogramDataPoint((*es.orig)[ix]) } @@ -1288,12 +1301,13 @@ func (es HistogramDataPointSlice) CopyTo(dest HistogramDataPointSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new HistogramDataPointSlice can be initialized: -// es := NewHistogramDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewHistogramDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es HistogramDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1317,10 +1331,11 @@ func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b HistogramDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b HistogramDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es HistogramDataPointSlice) Sort(less func(a, b HistogramDataPoint) bool) HistogramDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1571,10 +1586,11 @@ func (es ExponentialHistogramDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ExponentialHistogramDataPointSlice) At(ix int) ExponentialHistogramDataPoint { return newExponentialHistogramDataPoint((*es.orig)[ix]) } @@ -1604,12 +1620,13 @@ func (es ExponentialHistogramDataPointSlice) CopyTo(dest ExponentialHistogramDat // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ExponentialHistogramDataPointSlice can be initialized: -// es := NewExponentialHistogramDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewExponentialHistogramDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ExponentialHistogramDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1633,10 +1650,11 @@ func (es ExponentialHistogramDataPointSlice) AppendEmpty() ExponentialHistogramD // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ExponentialHistogramDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ExponentialHistogramDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ExponentialHistogramDataPointSlice) Sort(less func(a, b ExponentialHistogramDataPoint) bool) ExponentialHistogramDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -1952,10 +1970,11 @@ func (es SummaryDataPointSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SummaryDataPointSlice) At(ix int) SummaryDataPoint { return newSummaryDataPoint((*es.orig)[ix]) } @@ -1985,12 +2004,13 @@ func (es SummaryDataPointSlice) CopyTo(dest SummaryDataPointSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SummaryDataPointSlice can be initialized: -// es := NewSummaryDataPointSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewSummaryDataPointSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SummaryDataPointSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -2014,10 +2034,11 @@ func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b SummaryDataPoint) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b SummaryDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SummaryDataPointSlice) Sort(less func(a, b SummaryDataPoint) bool) SummaryDataPointSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -2185,10 +2206,11 @@ func (es ValueAtQuantileSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ValueAtQuantileSlice) At(ix int) ValueAtQuantile { return newValueAtQuantile((*es.orig)[ix]) } @@ -2218,12 +2240,13 @@ func (es ValueAtQuantileSlice) CopyTo(dest ValueAtQuantileSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ValueAtQuantileSlice can be initialized: -// es := NewValueAtQuantileSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewValueAtQuantileSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ValueAtQuantileSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -2247,10 +2270,11 @@ func (es ValueAtQuantileSlice) AppendEmpty() ValueAtQuantile { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ValueAtQuantile) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ValueAtQuantile) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ValueAtQuantileSlice) Sort(less func(a, b ValueAtQuantile) bool) ValueAtQuantileSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -2378,10 +2402,11 @@ func (es ExemplarSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ExemplarSlice) At(ix int) Exemplar { return newExemplar(&(*es.orig)[ix]) } @@ -2406,12 +2431,13 @@ func (es ExemplarSlice) CopyTo(dest ExemplarSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ExemplarSlice can be initialized: -// es := NewExemplarSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewExemplarSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ExemplarSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { diff --git a/pdata/internal/generated_ptrace.go b/pdata/internal/generated_ptrace.go index 92cb9bfa248..5f17d6f362b 100644 --- a/pdata/internal/generated_ptrace.go +++ b/pdata/internal/generated_ptrace.go @@ -57,10 +57,11 @@ func (es ResourceSpansSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ResourceSpansSlice) At(ix int) ResourceSpans { return newResourceSpans((*es.orig)[ix]) } @@ -90,12 +91,13 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ResourceSpansSlice can be initialized: -// es := NewResourceSpansSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewResourceSpansSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ResourceSpansSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -119,10 +121,11 @@ func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ResourceSpans) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ResourceSpans) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ResourceSpansSlice) Sort(less func(a, b ResourceSpans) bool) ResourceSpansSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -251,10 +254,11 @@ func (es ScopeSpansSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es ScopeSpansSlice) At(ix int) ScopeSpans { return newScopeSpans((*es.orig)[ix]) } @@ -284,12 +288,13 @@ func (es ScopeSpansSlice) CopyTo(dest ScopeSpansSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new ScopeSpansSlice can be initialized: -// es := NewScopeSpansSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewScopeSpansSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es ScopeSpansSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -313,10 +318,11 @@ func (es ScopeSpansSlice) AppendEmpty() ScopeSpans { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b ScopeSpans) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b ScopeSpans) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es ScopeSpansSlice) Sort(less func(a, b ScopeSpans) bool) ScopeSpansSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -445,10 +451,11 @@ func (es SpanSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SpanSlice) At(ix int) Span { return newSpan((*es.orig)[ix]) } @@ -478,12 +485,13 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SpanSlice can be initialized: -// es := NewSpanSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewSpanSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SpanSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -507,10 +515,11 @@ func (es SpanSlice) AppendEmpty() Span { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b Span) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b Span) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SpanSlice) Sort(less func(a, b Span) bool) SpanSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -762,10 +771,11 @@ func (es SpanEventSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SpanEventSlice) At(ix int) SpanEvent { return newSpanEvent((*es.orig)[ix]) } @@ -795,12 +805,13 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SpanEventSlice can be initialized: -// es := NewSpanEventSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewSpanEventSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SpanEventSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -824,10 +835,11 @@ func (es SpanEventSlice) AppendEmpty() SpanEvent { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b SpanEvent) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b SpanEvent) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SpanEventSlice) Sort(less func(a, b SpanEvent) bool) SpanEventSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es @@ -973,10 +985,11 @@ func (es SpanLinkSlice) Len() int { // At returns the element at the given index. // // This function is used mostly for iterating over all the values in the slice: -// for i := 0; i < es.Len(); i++ { -// e := es.At(i) -// ... // Do something with the element -// } +// +// for i := 0; i < es.Len(); i++ { +// e := es.At(i) +// ... // Do something with the element +// } func (es SpanLinkSlice) At(ix int) SpanLink { return newSpanLink((*es.orig)[ix]) } @@ -1006,12 +1019,13 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { // 2. If the newCap > cap then the slice capacity will be expanded to equal newCap. // // Here is how a new SpanLinkSlice can be initialized: -// es := NewSpanLinkSlice() -// es.EnsureCapacity(4) -// for i := 0; i < 4; i++ { -// e := es.AppendEmpty() -// // Here should set all the values for e. -// } +// +// es := NewSpanLinkSlice() +// es.EnsureCapacity(4) +// for i := 0; i < 4; i++ { +// e := es.AppendEmpty() +// // Here should set all the values for e. +// } func (es SpanLinkSlice) EnsureCapacity(newCap int) { oldCap := cap(*es.orig) if newCap <= oldCap { @@ -1035,10 +1049,11 @@ func (es SpanLinkSlice) AppendEmpty() SpanLink { // can be compared. // // Returns the same instance to allow nicer code like: -// lessFunc := func(a, b SpanLink) bool { -// return a.Name() < b.Name() // choose any comparison here -// } -// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +// +// lessFunc := func(a, b SpanLink) bool { +// return a.Name() < b.Name() // choose any comparison here +// } +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) func (es SpanLinkSlice) Sort(less func(a, b SpanLink) bool) SpanLinkSlice { sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es diff --git a/pdata/plog/generated_alias.go b/pdata/plog/generated_alias.go index aacb32d4343..e9d9fdb8ba3 100644 --- a/pdata/plog/generated_alias.go +++ b/pdata/plog/generated_alias.go @@ -84,7 +84,6 @@ var NewLogRecordSlice = internal.NewLogRecordSlice // LogRecord are experimental implementation of OpenTelemetry Log Data Model. -// // This is a reference type, if passed by value and callee modifies it the // caller will see the modification. // From d82f3e4931ebd1eb2074dc4f340608c6c40351d8 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Wed, 5 Oct 2022 16:06:16 -0700 Subject: [PATCH 07/17] Update to use github.com/lightstep/go-expohisto --- exporter/loggingexporter/internal/otlptext/metrics.go | 6 +++--- exporter/loggingexporter/internal/otlptext/metrics_test.go | 4 ++-- go.mod | 1 + go.sum | 2 ++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index c56458ca30e..e893b53ebd6 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -17,9 +17,9 @@ package otlptext // import "go.opentelemetry.io/collector/exporter/loggingexport import ( "fmt" - expohisto "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping" - "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" - "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" + expohisto "github.com/lightstep/go-expohisto/mapping" + "github.com/lightstep/go-expohisto/mapping/exponent" + "github.com/lightstep/go-expohisto/mapping/logarithm" "go.opentelemetry.io/collector/pdata/pmetric" ) diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 6e3912af170..c42249279c9 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -19,10 +19,10 @@ import ( "math/big" "testing" + "github.com/lightstep/go-expohisto/mapping/exponent" + "github.com/lightstep/go-expohisto/mapping/logarithm" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/exponent" - "go.opentelemetry.io/otel/sdk/metric/aggregator/exponential/mapping/logarithm" "go.opentelemetry.io/collector/internal/testdata" "go.opentelemetry.io/collector/pdata/pmetric" diff --git a/go.mod b/go.mod index 9a73c354731..e1f39a38ee8 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/google/uuid v1.3.0 github.com/klauspost/compress v1.15.11 github.com/knadh/koanf v1.4.3 + github.com/lightstep/go-expohisto v1.0.0 github.com/magiconair/properties v1.8.6 github.com/mitchellh/mapstructure v1.5.0 github.com/mostynb/go-grpc-compression v1.1.17 diff --git a/go.sum b/go.sum index 35576d3746e..48d22a1de82 100644 --- a/go.sum +++ b/go.sum @@ -276,6 +276,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lightstep/go-expohisto v1.0.0 h1:UPtTS1rGdtehbbAF7o/dhkWLTDI73UifG8LbfQI7cA4= +github.com/lightstep/go-expohisto v1.0.0/go.mod h1:xDXD0++Mu2FOaItXtdDfksfgxfV0z1TMPa+e/EUd0cs= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= From 63d2dd1a810509aa4f908eb6b3145743b6cc05a8 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Wed, 5 Oct 2022 16:12:42 -0700 Subject: [PATCH 08/17] tidy --- cmd/otelcorecol/go.mod | 1 + cmd/otelcorecol/go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cmd/otelcorecol/go.mod b/cmd/otelcorecol/go.mod index 90461fbe8d5..74a4396d7f1 100644 --- a/cmd/otelcorecol/go.mod +++ b/cmd/otelcorecol/go.mod @@ -31,6 +31,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.11 // indirect github.com/knadh/koanf v1.4.3 // indirect + github.com/lightstep/go-expohisto v1.0.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect diff --git a/cmd/otelcorecol/go.sum b/cmd/otelcorecol/go.sum index e7ec1bafcd2..23b21bed76a 100644 --- a/cmd/otelcorecol/go.sum +++ b/cmd/otelcorecol/go.sum @@ -274,6 +274,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lightstep/go-expohisto v1.0.0 h1:UPtTS1rGdtehbbAF7o/dhkWLTDI73UifG8LbfQI7cA4= +github.com/lightstep/go-expohisto v1.0.0/go.mod h1:xDXD0++Mu2FOaItXtdDfksfgxfV0z1TMPa+e/EUd0cs= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= From 1bfde7bcb030bf8b41044700f77ca0cc1b95eb07 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Wed, 14 Dec 2022 16:33:17 -0800 Subject: [PATCH 09/17] fix the tests --- cmd/otelcorecol/go.mod | 1 + exporter/loggingexporter/go.mod | 1 + exporter/loggingexporter/go.sum | 2 ++ .../internal/otlptext/databuffer.go | 2 +- .../internal/otlptext/metrics.go | 2 +- .../metrics/metrics_with_all_types.out | 12 +++++----- go.sum | 2 -- internal/testdata/metric.go | 22 ++++++++++++------- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/cmd/otelcorecol/go.mod b/cmd/otelcorecol/go.mod index f9b60fa9441..25706993793 100644 --- a/cmd/otelcorecol/go.mod +++ b/cmd/otelcorecol/go.mod @@ -40,6 +40,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.13 // indirect github.com/knadh/koanf v1.4.4 // indirect + github.com/lightstep/go-expohisto v1.0.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect diff --git a/exporter/loggingexporter/go.mod b/exporter/loggingexporter/go.mod index 6ae412897e6..375cb0f2c18 100644 --- a/exporter/loggingexporter/go.mod +++ b/exporter/loggingexporter/go.mod @@ -3,6 +3,7 @@ module go.opentelemetry.io/collector/exporter/loggingexporter go 1.18 require ( + github.com/lightstep/go-expohisto v1.0.0 github.com/stretchr/testify v1.8.1 go.opentelemetry.io/collector v0.67.0 go.opentelemetry.io/collector/component v0.67.0 diff --git a/exporter/loggingexporter/go.sum b/exporter/loggingexporter/go.sum index 9805fa19211..a25970e0be0 100644 --- a/exporter/loggingexporter/go.sum +++ b/exporter/loggingexporter/go.sum @@ -174,6 +174,8 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lightstep/go-expohisto v1.0.0 h1:UPtTS1rGdtehbbAF7o/dhkWLTDI73UifG8LbfQI7cA4= +github.com/lightstep/go-expohisto v1.0.0/go.mod h1:xDXD0++Mu2FOaItXtdDfksfgxfV0z1TMPa+e/EUd0cs= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= diff --git a/exporter/loggingexporter/internal/otlptext/databuffer.go b/exporter/loggingexporter/internal/otlptext/databuffer.go index c684db6ada9..fd76fe95d74 100644 --- a/exporter/loggingexporter/internal/otlptext/databuffer.go +++ b/exporter/loggingexporter/internal/otlptext/databuffer.go @@ -178,8 +178,8 @@ func (b *dataBuffer) logExponentialHistogramDataPoints(ps pmetric.ExponentialHis pos := negB.Len() - i - 1 index := p.Negative().Offset() + int32(pos) b.logEntry("Bucket [%s, %s), Count: %d", - m.stringLowerBoundary(index, true), m.stringLowerBoundary(index+1, true), + m.stringLowerBoundary(index, true), negB.At(pos)) } diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index e893b53ebd6..b3c3855a0dc 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -93,7 +93,7 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { if neg { bound = -bound } - return fmt.Sprintf("%g", bound) + return fmt.Sprintf("%f", bound) } } diff --git a/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out b/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out index db291f3f22d..0927f507ffc 100644 --- a/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out +++ b/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out @@ -127,11 +127,11 @@ StartTimestamp: 2020-02-11 20:26:12.000000321 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC Count: 5 Sum: 0.150000 -Bucket (-1.414214, -1.000000], Count: 1 -Bucket (-1.000000, -0.707107], Count: 1 +Bucket [-1.414214, -1.000000), Count: 1 +Bucket [-1.000000, -0.707107), Count: 1 Bucket [0, 0], Count: 1 -Bucket [1.414214, 2.000000), Count: 1 -Bucket [2.000000, 2.828427), Count: 1 +Bucket (1.414214, 2.000000], Count: 1 +Bucket (2.000000, 2.828427], Count: 1 ExponentialHistogramDataPoints #1 Data point attributes: -> label-2: Str(label-value-2) @@ -142,8 +142,8 @@ Sum: 1.250000 Min: 0.000000 Max: 1.000000 Bucket [0, 0], Count: 1 -Bucket [0.250000, 1.000000), Count: 1 -Bucket [1.000000, 4.000000), Count: 1 +Bucket (0.250000, 1.000000], Count: 1 +Bucket (1.000000, 4.000000], Count: 1 Metric #6 Descriptor: -> Name: summary diff --git a/go.sum b/go.sum index d225fed7b14..ef34bb23565 100644 --- a/go.sum +++ b/go.sum @@ -275,8 +275,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/lightstep/go-expohisto v1.0.0 h1:UPtTS1rGdtehbbAF7o/dhkWLTDI73UifG8LbfQI7cA4= -github.com/lightstep/go-expohisto v1.0.0/go.mod h1:xDXD0++Mu2FOaItXtdDfksfgxfV0z1TMPa+e/EUd0cs= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/internal/testdata/metric.go b/internal/testdata/metric.go index ce682d47d60..612b3a37808 100644 --- a/internal/testdata/metric.go +++ b/internal/testdata/metric.go @@ -218,19 +218,25 @@ func initExponentialHistogramMetric(hm pmetric.Metric) { hdp0.SetZeroCount(1) hdp0.SetScale(1) - // positive index 1 and 2 are values sqrt(2), 2 at scale 1 + // at scale 1, + // postitive bucket index 0 is (1, sqrt(2)] (not represented) + // postitive bucket index 1 is (sqrt(2), 2] + // postitive bucket index 2 is (2, 2*sqrt(2)] hdp0.Positive().SetOffset(1) hdp0.Positive().BucketCounts().FromRaw([]uint64{1, 1}) - // negative index -1 and 0 are values -1/sqrt(2), -1 at scale 1 + + // at scale 1 + // negative bucket index 0 is -(1, sqrt(2)] + // negative bucket index -1 is -(sqrt(2)/2, 1] hdp0.Negative().SetOffset(-1) hdp0.Negative().BucketCounts().FromRaw([]uint64{1, 1}) // The above will print: - // Bucket (-1.414214, -1.000000], Count: 1 - // Bucket (-1.000000, -0.707107], Count: 1 + // Bucket [-1.414214, -1.000000), Count: 1 + // Bucket [-1.000000, -0.707107), Count: 1 // Bucket [0, 0], Count: 1 - // Bucket [0.707107, 1.000000), Count: 1 - // Bucket [1.000000, 1.414214), Count: 1 + // Bucket (1.414214, 2.000000], Count: 1 + // Bucket (2.000000, 2.828427], Count: 1 hdp1 := hdps.AppendEmpty() initMetricAttributes2(hdp1.Attributes()) @@ -249,8 +255,8 @@ func initExponentialHistogramMetric(hm pmetric.Metric) { // The above will print: // Bucket [0, 0], Count: 1 - // Bucket [0.250000, 1.000000), Count: 1 - // Bucket [1.000000, 4.000000), Count: 1 + // Bucket (0.250000, 1.000000], Count: 1 + // Bucket (1.000000, 4.000000], Count: 1 exemplar := hdp1.Exemplars().AppendEmpty() exemplar.SetTimestamp(metricExemplarTimestamp) From a2c22d3b54f36920cd029c4cb94db267723a9d04 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:04:18 -0800 Subject: [PATCH 10/17] refinements for new boundary regime: be sure to print underflow when a valid boundary is subnormal --- .../internal/otlptext/metrics.go | 31 ++++++++++------- .../internal/otlptext/metrics_test.go | 34 ++++++++++++++----- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index b3c3855a0dc..ffc587a15ea 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -24,14 +24,9 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" ) -// lastBoundary equals and is the least -// unrepresentable float64 greater than 1. -// Can be computed using -// -// b := big.NewFloat(1) -// b.SetMantExp(b, 1024) -// return b.String() -const lastBoundary = "1.797693135e+308" +// greatestBoundary equals and is the smallest unrepresentable float64 +// greater than 1. See TestLastBoundary for the definition in code. +const greatestBoundary = "1.79769e+308" // NewTextMetricsMarshaler returns a pmetric.Marshaler to encode to OTLP text bytes. func NewTextMetricsMarshaler() pmetric.Marshaler { @@ -90,17 +85,21 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { // index are in range. if ehm.mapping != nil { if bound, err := ehm.mapping.LowerBoundary(idx); err == nil { - if neg { - bound = -bound + // If the boundary is a subnormal number, fmt.Sprintf() + // won't help, use the generic fallback below. + if bound >= 0x1p-1022 { + if neg { + bound = -bound + } + return fmt.Sprintf("%f", bound) } - return fmt.Sprintf("%f", bound) } } var s string switch { case idx == 0: - s = "1" + s = fmt.Sprintf("%f", 1.0) case idx > 0: // Note: at scale 20, the value (1<<30) leads to exponent 1024 // The following expression generalizes this for valid scales. @@ -108,7 +107,7 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { // Important special case equal to 0x1p1024 is // the upper boundary of the last valid bucket // at all scales. - s = lastBoundary + s = greatestBoundary } else { s = "OVERFLOW" } @@ -119,6 +118,12 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { // an underflow error for buckets that are entirely // outside the normal range. These measurements are not // necessarily invalid, but they are extra work to compute. + // + // There is one case that falls through to this branch + // under ordinary circumstances. Because the value at + // the subnormal boundary 0x1p-1022 falls into a + // bucket (subnormal, 0x1p-1022], we therefore print that + // bucket as (UNDERFLOW, 0x1p-1022]. s = "UNDERFLOW" } if neg { diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index a9d33e9afa1..508bafe259d 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -72,9 +72,7 @@ func TestMetricsText(t *testing.T) { func TestExpoHistoOverflowMapping(t *testing.T) { // Compute the string value of 0x1p+1024 - b := big.NewFloat(1) - b.SetMantExp(b, 1024) - expect := b.String() + expect := expectGreatestBoundary() // For positive scales, the +Inf threshold happens at 1024< Date: Thu, 15 Dec 2022 10:21:01 -0800 Subject: [PATCH 11/17] Update formatting, test it --- .../internal/otlptext/metrics.go | 21 +++++++++++++----- .../internal/otlptext/metrics_test.go | 22 ++++++++++++++----- .../metrics/metrics_with_all_types.out | 12 +++++----- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index ffc587a15ea..7b4990c132b 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -28,6 +28,10 @@ import ( // greater than 1. See TestLastBoundary for the definition in code. const greatestBoundary = "1.79769e+308" +// boundaryFormat is used with Sprintf() to format exponential +// histogram boundaries. +const boundaryFormat = "%.6g" + // NewTextMetricsMarshaler returns a pmetric.Marshaler to encode to OTLP text bytes. func NewTextMetricsMarshaler() pmetric.Marshaler { return textMetricsMarshaler{} @@ -91,7 +95,7 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { if neg { bound = -bound } - return fmt.Sprintf("%f", bound) + return fmt.Sprintf(boundaryFormat, bound) } } } @@ -99,7 +103,7 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { var s string switch { case idx == 0: - s = fmt.Sprintf("%f", 1.0) + s = "1" case idx > 0: // Note: at scale 20, the value (1<<30) leads to exponent 1024 // The following expression generalizes this for valid scales. @@ -112,9 +116,9 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { s = "OVERFLOW" } default: - // TODO: corner cases involving subnormal values may + // Note: corner cases involving subnormal values may // be handled here. These are considered out of range - // by the otel-go mapping functions, which will return + // by the go-expohisto mapping functions, which will return // an underflow error for buckets that are entirely // outside the normal range. These measurements are not // necessarily invalid, but they are extra work to compute. @@ -122,8 +126,13 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { // There is one case that falls through to this branch // under ordinary circumstances. Because the value at // the subnormal boundary 0x1p-1022 falls into a - // bucket (subnormal, 0x1p-1022], we therefore print that - // bucket as (UNDERFLOW, 0x1p-1022]. + // bucket (subnormal, 0x1p-1022], where the subnormal + // value depends on scale. The fallthrough here means + // we print that bucket as (UNDERFLOW, 0x1p-1022], + // which is correct for the go-expohisto reference + // implementation in the sense that it rounds + // subnormal values up => all subnormal values fall + // into the bucket printed as "(UNDERFLOW, 0x1p-1022]". s = "UNDERFLOW" } if neg { diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 508bafe259d..451de68a585 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -109,8 +109,8 @@ func TestExpoHistoOverflowMapping(t *testing.T) { require.Equal(t, "-OVERFLOW", invalid.stringLowerBoundary(1, true)) // But index 0 always works - require.Equal(t, "1.000000", invalid.stringLowerBoundary(0, false)) - require.Equal(t, "-1.000000", invalid.stringLowerBoundary(0, true)) + require.Equal(t, "1", invalid.stringLowerBoundary(0, false)) + require.Equal(t, "-1", invalid.stringLowerBoundary(0, true)) } func TestExpoHistoUnderflowMapping(t *testing.T) { @@ -124,8 +124,8 @@ func TestExpoHistoUnderflowMapping(t *testing.T) { lb, err := m.mapping.LowerBoundary(idx) require.NoError(t, err) - require.Equal(t, fmt.Sprintf("%f", lb), m.stringLowerBoundary(idx, false)) - require.Equal(t, fmt.Sprintf("-%f", lb), m.stringLowerBoundary(idx, true)) + require.Equal(t, fmt.Sprintf(boundaryFormat, lb), m.stringLowerBoundary(idx, false)) + require.Equal(t, fmt.Sprintf("-"+boundaryFormat, lb), m.stringLowerBoundary(idx, true)) require.Equal(t, "UNDERFLOW", m.stringLowerBoundary(idx-1, false)) require.Equal(t, "-UNDERFLOW", m.stringLowerBoundary(idx-1, true)) @@ -147,10 +147,20 @@ func expectGreatestBoundary() string { return b.Text('g', 6) } -// TestGreatestBoundary verifies greatestBoundary is hard-coded -// correctly. +// TestGreatestBoundary verifies greatestBoundary is hard-coded correctly. func TestGreatestBoundary(t *testing.T) { expect := expectGreatestBoundary() + // Require that the formatting of greatestBoundary should + // match the formatting of normal boundaries. Change the call + // to b.Text() in expectGreatestBoundary to match + // boundaryFormat then update this test. + require.Equal(t, boundaryFormat, "%.6g") + + // Require the formatting of "1" to match the boundaryFormat. + invalid := newExpoHistoMapping(100) + require.Equal(t, fmt.Sprintf(boundaryFormat, 1.0), invalid.stringLowerBoundary(0, false)) + + // Require the correct hard-coded value. require.Equal(t, expect, greatestBoundary) } diff --git a/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out b/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out index 0927f507ffc..09050b58703 100644 --- a/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out +++ b/exporter/loggingexporter/internal/otlptext/testdata/metrics/metrics_with_all_types.out @@ -127,11 +127,11 @@ StartTimestamp: 2020-02-11 20:26:12.000000321 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC Count: 5 Sum: 0.150000 -Bucket [-1.414214, -1.000000), Count: 1 -Bucket [-1.000000, -0.707107), Count: 1 +Bucket [-1.41421, -1), Count: 1 +Bucket [-1, -0.707107), Count: 1 Bucket [0, 0], Count: 1 -Bucket (1.414214, 2.000000], Count: 1 -Bucket (2.000000, 2.828427], Count: 1 +Bucket (1.41421, 2], Count: 1 +Bucket (2, 2.82843], Count: 1 ExponentialHistogramDataPoints #1 Data point attributes: -> label-2: Str(label-value-2) @@ -142,8 +142,8 @@ Sum: 1.250000 Min: 0.000000 Max: 1.000000 Bucket [0, 0], Count: 1 -Bucket (0.250000, 1.000000], Count: 1 -Bucket (1.000000, 4.000000], Count: 1 +Bucket (0.25, 1], Count: 1 +Bucket (1, 4], Count: 1 Metric #6 Descriptor: -> Name: summary From e914abbc4736e4dce986661c10f3f9ac4600d301 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:22:53 -0800 Subject: [PATCH 12/17] correct name --- exporter/loggingexporter/internal/otlptext/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index 7b4990c132b..754751a4600 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -85,7 +85,7 @@ func newExpoHistoMapping(scale int32) expoHistoMapping { } func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { - // Use the otel-go mapping functions provided the scale and + // Use the go-expohisto mapping functions provided the scale and // index are in range. if ehm.mapping != nil { if bound, err := ehm.mapping.LowerBoundary(idx); err == nil { From 9014ca1f3aefe81acb2b8825a9c85e6921e602c6 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:25:43 -0800 Subject: [PATCH 13/17] fix --- .../loggingexporter/internal/otlptext/metrics_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 451de68a585..0fad087998e 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -147,10 +147,9 @@ func expectGreatestBoundary() string { return b.Text('g', 6) } -// TestGreatestBoundary verifies greatestBoundary is hard-coded correctly. -func TestGreatestBoundary(t *testing.T) { - expect := expectGreatestBoundary() - +// TestBoundaryFormatting verifies greatestBoundary is hard-coded +// correctly and formatted like normal boundaries. +func TestBoundaryFormatting(t *testing.T) { // Require that the formatting of greatestBoundary should // match the formatting of normal boundaries. Change the call // to b.Text() in expectGreatestBoundary to match @@ -162,5 +161,5 @@ func TestGreatestBoundary(t *testing.T) { require.Equal(t, fmt.Sprintf(boundaryFormat, 1.0), invalid.stringLowerBoundary(0, false)) // Require the correct hard-coded value. - require.Equal(t, expect, greatestBoundary) + require.Equal(t, expectGreatestBoundary(), greatestBoundary) } From 6ba1a92eb8539dba228e6b11e480ad6efc370aea Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:40:08 -0800 Subject: [PATCH 14/17] more comment --- .../internal/otlptext/metrics.go | 19 +++++++++++-------- .../internal/otlptext/metrics_test.go | 10 ++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics.go b/exporter/loggingexporter/internal/otlptext/metrics.go index 754751a4600..c811b8f919a 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics.go +++ b/exporter/loggingexporter/internal/otlptext/metrics.go @@ -124,15 +124,18 @@ func (ehm expoHistoMapping) stringLowerBoundary(idx int32, neg bool) string { // necessarily invalid, but they are extra work to compute. // // There is one case that falls through to this branch - // under ordinary circumstances. Because the value at + // to describe the lower boundary of a bucket + // containing a normal value. Because the value at // the subnormal boundary 0x1p-1022 falls into a - // bucket (subnormal, 0x1p-1022], where the subnormal - // value depends on scale. The fallthrough here means - // we print that bucket as (UNDERFLOW, 0x1p-1022], - // which is correct for the go-expohisto reference - // implementation in the sense that it rounds - // subnormal values up => all subnormal values fall - // into the bucket printed as "(UNDERFLOW, 0x1p-1022]". + // bucket (X, 0x1p-1022], where the subnormal value X + // depends on scale. The fallthrough here means we + // print that bucket as "(UNDERFLOW, 2.22507e-308]", + // (note 0x1p-1022 == 2.22507e-308). This is correct + // with respect to the reference implementation, which + // first rounds subnormal values up to 0x1p-1022. The + // result (for the reference implementation) is all + // subnormal values will fall into the bucket that + // prints "(UNDERFLOW, 2.22507e-308]". s = "UNDERFLOW" } if neg { diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 0fad087998e..4c743f2419a 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -162,4 +162,14 @@ func TestBoundaryFormatting(t *testing.T) { // Require the correct hard-coded value. require.Equal(t, expectGreatestBoundary(), greatestBoundary) + + // Verify that 0x1p-1022 falls into a bucket that formats like + // (UNDERFLOW, 2.22507e-308] + valid := newExpoHistoMapping(0) + boundIdx := valid.stringLowerBoundary(-1022, false) + lowIdx := valid.stringLowerBoundary(-1023, false) + + fmt.Println("BIDX", boundIdx) + require.Equal(t, fmt.Sprintf(boundaryFormat, 0x1p-1022), boundIdx) + require.Equal(t, "UNDERFLOW", lowIdx) } From 3138b79d71aab495d8c7cac1f2b0a892784b8c78 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:50:13 -0800 Subject: [PATCH 15/17] fix internal/testdata comments --- internal/testdata/metric.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/testdata/metric.go b/internal/testdata/metric.go index 612b3a37808..07926965309 100644 --- a/internal/testdata/metric.go +++ b/internal/testdata/metric.go @@ -232,11 +232,11 @@ func initExponentialHistogramMetric(hm pmetric.Metric) { hdp0.Negative().BucketCounts().FromRaw([]uint64{1, 1}) // The above will print: - // Bucket [-1.414214, -1.000000), Count: 1 - // Bucket [-1.000000, -0.707107), Count: 1 + // Bucket [-1.41421, -1), Count: 1 + // Bucket [-1, -0.707107), Count: 1 // Bucket [0, 0], Count: 1 - // Bucket (1.414214, 2.000000], Count: 1 - // Bucket (2.000000, 2.828427], Count: 1 + // Bucket (1.41421, 2], Count: 1 + // Bucket (2, 2.82843], Count: 1 hdp1 := hdps.AppendEmpty() initMetricAttributes2(hdp1.Attributes()) @@ -255,8 +255,8 @@ func initExponentialHistogramMetric(hm pmetric.Metric) { // The above will print: // Bucket [0, 0], Count: 1 - // Bucket (0.250000, 1.000000], Count: 1 - // Bucket (1.000000, 4.000000], Count: 1 + // Bucket (0.25, 1], Count: 1 + // Bucket (1, 4], Count: 1 exemplar := hdp1.Exemplars().AppendEmpty() exemplar.SetTimestamp(metricExemplarTimestamp) From 6b7464973485bfc8346eea1f5eeb862b5c576ceb Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:50:40 -0800 Subject: [PATCH 16/17] fix typoes --- internal/testdata/metric.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/testdata/metric.go b/internal/testdata/metric.go index 07926965309..fbb8723157b 100644 --- a/internal/testdata/metric.go +++ b/internal/testdata/metric.go @@ -219,9 +219,9 @@ func initExponentialHistogramMetric(hm pmetric.Metric) { hdp0.SetScale(1) // at scale 1, - // postitive bucket index 0 is (1, sqrt(2)] (not represented) - // postitive bucket index 1 is (sqrt(2), 2] - // postitive bucket index 2 is (2, 2*sqrt(2)] + // positive bucket index 0 is (1, sqrt(2)] (not represented) + // positive bucket index 1 is (sqrt(2), 2] + // positive bucket index 2 is (2, 2*sqrt(2)] hdp0.Positive().SetOffset(1) hdp0.Positive().BucketCounts().FromRaw([]uint64{1, 1}) From 41008fa499c5fc527a80fa68ee7e569c62150ae9 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 15 Dec 2022 10:57:10 -0800 Subject: [PATCH 17/17] remove print --- exporter/loggingexporter/internal/otlptext/metrics_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/exporter/loggingexporter/internal/otlptext/metrics_test.go b/exporter/loggingexporter/internal/otlptext/metrics_test.go index 4c743f2419a..5b3eb89ec69 100644 --- a/exporter/loggingexporter/internal/otlptext/metrics_test.go +++ b/exporter/loggingexporter/internal/otlptext/metrics_test.go @@ -168,8 +168,6 @@ func TestBoundaryFormatting(t *testing.T) { valid := newExpoHistoMapping(0) boundIdx := valid.stringLowerBoundary(-1022, false) lowIdx := valid.stringLowerBoundary(-1023, false) - - fmt.Println("BIDX", boundIdx) require.Equal(t, fmt.Sprintf(boundaryFormat, 0x1p-1022), boundIdx) require.Equal(t, "UNDERFLOW", lowIdx) }