From 770befbc7a5e4f436b67e7bb9ecf42bf3c5e7053 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Wed, 6 Nov 2024 07:34:13 -0700 Subject: [PATCH] [pkg/ottl] set `processor.transform.ConvertBetweenSumAndGaugeMetricContext` as stable (#36216) #### Description Set the `processor.transform.ConvertBetweenSumAndGaugeMetricContext` feature gate as stable #### Link to tracking issue Fixes https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/34567 --------- Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> --- .chloggen/transform-set-stable-gate.yaml | 27 ++++ processor/transformprocessor/config.go | 4 - processor/transformprocessor/go.mod | 3 - .../func_convert_gauge_to_sum_datapoint.go | 58 ------- ...unc_convert_gauge_to_sum_datapoint_test.go | 149 ------------------ .../func_convert_sum_to_gauge_datapoint.go | 37 ----- ...unc_convert_sum_to_gauge_datapoint_test.go | 99 ------------ .../internal/metrics/functions.go | 23 +-- .../internal/metrics/functions_test.go | 8 - 9 files changed, 31 insertions(+), 377 deletions(-) create mode 100644 .chloggen/transform-set-stable-gate.yaml delete mode 100644 processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint.go delete mode 100644 processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go delete mode 100644 processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint.go delete mode 100644 processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go diff --git a/.chloggen/transform-set-stable-gate.yaml b/.chloggen/transform-set-stable-gate.yaml new file mode 100644 index 000000000000..fcc79907b87e --- /dev/null +++ b/.chloggen/transform-set-stable-gate.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/ottl + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Promote `processor.transform.ConvertBetweenSumAndGaugeMetricContext` feature gate to Stable + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [36216] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: This gate can no longer be disabled. The `convert_sum_to_gauge` and `convert_gauge_to_sum` may now only be used with the `metric` context. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/processor/transformprocessor/config.go b/processor/transformprocessor/config.go index 2eaeb094d5e5..8c5b7f35e7d4 100644 --- a/processor/transformprocessor/config.go +++ b/processor/transformprocessor/config.go @@ -49,10 +49,6 @@ var _ component.Config = (*Config)(nil) func (c *Config) Validate() error { var errors error - if c.logger != nil && metrics.UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() { - c.logger.Sugar().Infof("Metric conversion functions use metric context since %s is enabled. If your statements are not parsing, check if you're using the metrics conversion functions via the datapoint context.", metrics.UseConvertBetweenSumAndGaugeMetricContext.ID()) - } - if len(c.TraceStatements) > 0 { pc, err := common.NewTraceParserCollection(component.TelemetrySettings{Logger: zap.NewNop()}, common.WithSpanParser(traces.SpanFunctions()), common.WithSpanEventParser(traces.SpanEventFunctions())) if err != nil { diff --git a/processor/transformprocessor/go.mod b/processor/transformprocessor/go.mod index bad6d0c0d87a..14cfee5afeca 100644 --- a/processor/transformprocessor/go.mod +++ b/processor/transformprocessor/go.mod @@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/processor/trans go 1.22.0 require ( - github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.112.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.112.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.112.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil v0.112.0 @@ -100,8 +99,6 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../pkg/golden -replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common - replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter => ../../internal/filter replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/pdatautil => ../../internal/pdatautil diff --git a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint.go b/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint.go deleted file mode 100644 index 61c848ab1b52..000000000000 --- a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" - -import ( - "context" - "fmt" - - "go.opentelemetry.io/collector/pdata/pmetric" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" -) - -func newConvertDatapointGaugeToSumFactory() ottl.Factory[ottldatapoint.TransformContext] { - return ottl.NewFactory("convert_gauge_to_sum", &convertGaugeToSumArguments{}, createConvertDatapointGaugeToSumFunction) -} - -func createConvertDatapointGaugeToSumFunction(_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[ottldatapoint.TransformContext], error) { - // use the same args as in metric context - args, ok := oArgs.(*convertGaugeToSumArguments) - - if !ok { - return nil, fmt.Errorf("ConvertGaugeToSumFactory args must be of type *ConvertGaugeToSumArguments") - } - - return convertDatapointGaugeToSum(args.StringAggTemp, args.Monotonic) -} - -func convertDatapointGaugeToSum(stringAggTemp string, monotonic bool) (ottl.ExprFunc[ottldatapoint.TransformContext], error) { - var aggTemp pmetric.AggregationTemporality - switch stringAggTemp { - case "delta": - aggTemp = pmetric.AggregationTemporalityDelta - case "cumulative": - aggTemp = pmetric.AggregationTemporalityCumulative - default: - return nil, fmt.Errorf("unknown aggregation temporality: %s", stringAggTemp) - } - - return func(_ context.Context, tCtx ottldatapoint.TransformContext) (any, error) { - metric := tCtx.GetMetric() - if metric.Type() != pmetric.MetricTypeGauge { - return nil, nil - } - - dps := metric.Gauge().DataPoints() - - metric.SetEmptySum().SetAggregationTemporality(aggTemp) - metric.Sum().SetIsMonotonic(monotonic) - - // Setting the data type removed all the data points, so we must move them back to the metric. - dps.MoveAndAppendTo(metric.Sum().DataPoints()) - - return nil, nil - }, nil -} diff --git a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go b/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go deleted file mode 100644 index 926f3021a8e9..000000000000 --- a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/pmetric" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" -) - -func Test_convertDatapointGaugeToSum(t *testing.T) { - gaugeInput := pmetric.NewMetric() - - dp1 := gaugeInput.SetEmptyGauge().DataPoints().AppendEmpty() - dp1.SetIntValue(10) - - dp2 := gaugeInput.Gauge().DataPoints().AppendEmpty() - dp2.SetDoubleValue(14.5) - - sumInput := pmetric.NewMetric() - sumInput.SetEmptySum() - - histogramInput := pmetric.NewMetric() - histogramInput.SetEmptyHistogram() - - expoHistogramInput := pmetric.NewMetric() - expoHistogramInput.SetEmptyHistogram() - - summaryInput := pmetric.NewMetric() - summaryInput.SetEmptySummary() - - tests := []struct { - name string - stringAggTemp string - monotonic bool - input pmetric.Metric - want func(pmetric.Metric) - }{ - { - name: "convert gauge to cumulative sum", - stringAggTemp: "cumulative", - monotonic: false, - input: gaugeInput, - want: func(metric pmetric.Metric) { - gaugeInput.CopyTo(metric) - - dps := gaugeInput.Gauge().DataPoints() - - metric.SetEmptySum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) - metric.Sum().SetIsMonotonic(false) - - dps.CopyTo(metric.Sum().DataPoints()) - }, - }, - { - name: "convert gauge to delta sum", - stringAggTemp: "delta", - monotonic: true, - input: gaugeInput, - want: func(metric pmetric.Metric) { - gaugeInput.CopyTo(metric) - - dps := gaugeInput.Gauge().DataPoints() - - metric.SetEmptySum().SetAggregationTemporality(pmetric.AggregationTemporalityDelta) - metric.Sum().SetIsMonotonic(true) - - dps.CopyTo(metric.Sum().DataPoints()) - }, - }, - { - name: "noop for sum", - stringAggTemp: "delta", - monotonic: true, - input: sumInput, - want: func(metric pmetric.Metric) { - sumInput.CopyTo(metric) - }, - }, - { - name: "noop for histogram", - stringAggTemp: "delta", - monotonic: true, - input: histogramInput, - want: func(metric pmetric.Metric) { - histogramInput.CopyTo(metric) - }, - }, - { - name: "noop for exponential histogram", - stringAggTemp: "delta", - monotonic: true, - input: expoHistogramInput, - want: func(metric pmetric.Metric) { - expoHistogramInput.CopyTo(metric) - }, - }, - { - name: "noop for summary", - stringAggTemp: "delta", - monotonic: true, - input: summaryInput, - want: func(metric pmetric.Metric) { - summaryInput.CopyTo(metric) - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - metric := pmetric.NewMetric() - tt.input.CopyTo(metric) - - ctx := ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) - - exprFunc, _ := convertDatapointGaugeToSum(tt.stringAggTemp, tt.monotonic) - - _, err := exprFunc(nil, ctx) - assert.NoError(t, err) - - expected := pmetric.NewMetric() - tt.want(expected) - - assert.Equal(t, expected, metric) - }) - } -} - -func Test_convertDatapointGaugeToSum_validation(t *testing.T) { - tests := []struct { - name string - stringAggTemp string - }{ - { - name: "invalid aggregation temporality", - stringAggTemp: "not a real aggregation temporality", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - _, err := convertDatapointGaugeToSum(tt.stringAggTemp, true) - assert.Error(t, err, "unknown aggregation temporality: not a real aggregation temporality") - }) - } -} diff --git a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint.go b/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint.go deleted file mode 100644 index 1943d2d9796a..000000000000 --- a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics" - -import ( - "context" - - "go.opentelemetry.io/collector/pdata/pmetric" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" -) - -func newConvertDatapointSumToGaugeFactory() ottl.Factory[ottldatapoint.TransformContext] { - return ottl.NewFactory("convert_sum_to_gauge", nil, createDatapointConvertSumToGaugeFunction) -} - -func createDatapointConvertSumToGaugeFunction(_ ottl.FunctionContext, _ ottl.Arguments) (ottl.ExprFunc[ottldatapoint.TransformContext], error) { - return convertDatapointSumToGauge() -} - -func convertDatapointSumToGauge() (ottl.ExprFunc[ottldatapoint.TransformContext], error) { - return func(_ context.Context, tCtx ottldatapoint.TransformContext) (any, error) { - metric := tCtx.GetMetric() - if metric.Type() != pmetric.MetricTypeSum { - return nil, nil - } - - dps := metric.Sum().DataPoints() - - // Setting the data type removed all the data points, so we must move them back to the metric. - dps.MoveAndAppendTo(metric.SetEmptyGauge().DataPoints()) - - return nil, nil - }, nil -} diff --git a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go b/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go deleted file mode 100644 index 206f899c6e28..000000000000 --- a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package metrics - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/pmetric" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" -) - -func Test_convertDatapointSumToGauge(t *testing.T) { - sumInput := pmetric.NewMetric() - - dp1 := sumInput.SetEmptySum().DataPoints().AppendEmpty() - dp1.SetIntValue(10) - - dp2 := sumInput.Sum().DataPoints().AppendEmpty() - dp2.SetDoubleValue(14.5) - - gaugeInput := pmetric.NewMetric() - gaugeInput.SetEmptyGauge() - - histogramInput := pmetric.NewMetric() - histogramInput.SetEmptyHistogram() - - expoHistogramInput := pmetric.NewMetric() - expoHistogramInput.SetEmptyExponentialHistogram() - - summaryInput := pmetric.NewMetric() - summaryInput.SetEmptySummary() - - tests := []struct { - name string - input pmetric.Metric - want func(pmetric.Metric) - }{ - { - name: "convert sum to gauge", - input: sumInput, - want: func(metric pmetric.Metric) { - sumInput.CopyTo(metric) - - dps := sumInput.Sum().DataPoints() - dps.CopyTo(metric.SetEmptyGauge().DataPoints()) - }, - }, - { - name: "noop for gauge", - input: gaugeInput, - want: func(metric pmetric.Metric) { - gaugeInput.CopyTo(metric) - }, - }, - { - name: "noop for histogram", - input: histogramInput, - want: func(metric pmetric.Metric) { - histogramInput.CopyTo(metric) - }, - }, - { - name: "noop for exponential histogram", - input: expoHistogramInput, - want: func(metric pmetric.Metric) { - expoHistogramInput.CopyTo(metric) - }, - }, - { - name: "noop for summary", - input: summaryInput, - want: func(metric pmetric.Metric) { - summaryInput.CopyTo(metric) - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - metric := pmetric.NewMetric() - tt.input.CopyTo(metric) - - ctx := ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) - - exprFunc, _ := convertDatapointSumToGauge() - - _, err := exprFunc(nil, ctx) - assert.NoError(t, err) - - expected := pmetric.NewMetric() - tt.want(expected) - - assert.Equal(t, expected, metric) - }) - } -} diff --git a/processor/transformprocessor/internal/metrics/functions.go b/processor/transformprocessor/internal/metrics/functions.go index 23851dcd5ae0..8d18771b7320 100644 --- a/processor/transformprocessor/internal/metrics/functions.go +++ b/processor/transformprocessor/internal/metrics/functions.go @@ -14,8 +14,9 @@ import ( var UseConvertBetweenSumAndGaugeMetricContext = featuregate.GlobalRegistry().MustRegister( "processor.transform.ConvertBetweenSumAndGaugeMetricContext", - featuregate.StageBeta, + featuregate.StageStable, featuregate.WithRegisterDescription("When enabled will use metric context for conversion between sum and gauge"), + featuregate.WithRegisterToVersion("v0.114.0"), ) func DataPointFunctions() map[string]ottl.Factory[ottldatapoint.TransformContext] { @@ -26,15 +27,6 @@ func DataPointFunctions() map[string]ottl.Factory[ottldatapoint.TransformContext newConvertSummaryCountValToSumFactory(), ) - if !UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() { - for _, f := range []ottl.Factory[ottldatapoint.TransformContext]{ - newConvertDatapointSumToGaugeFactory(), - newConvertDatapointGaugeToSumFactory(), - } { - datapointFunctions[f.Name()] = f - } - } - for k, v := range datapointFunctions { functions[k] = v } @@ -48,6 +40,8 @@ func MetricFunctions() map[string]ottl.Factory[ottlmetric.TransformContext] { metricFunctions := ottl.CreateFactoryMap( newExtractSumMetricFactory(), newExtractCountMetricFactory(), + newConvertGaugeToSumFactory(), + newConvertSumToGaugeFactory(), newCopyMetricFactory(), newScaleMetricFactory(), newAggregateOnAttributesFactory(), @@ -55,15 +49,6 @@ func MetricFunctions() map[string]ottl.Factory[ottlmetric.TransformContext] { newAggregateOnAttributeValueFactory(), ) - if UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() { - for _, f := range []ottl.Factory[ottlmetric.TransformContext]{ - newConvertSumToGaugeFactory(), - newConvertGaugeToSumFactory(), - } { - metricFunctions[f.Name()] = f - } - } - for k, v := range metricFunctions { functions[k] = v } diff --git a/processor/transformprocessor/internal/metrics/functions_test.go b/processor/transformprocessor/internal/metrics/functions_test.go index 10e959be2df8..62def6453fe2 100644 --- a/processor/transformprocessor/internal/metrics/functions_test.go +++ b/processor/transformprocessor/internal/metrics/functions_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlfuncs" @@ -34,17 +33,10 @@ func Test_DataPointFunctions(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - defer testutil.SetFeatureGateForTest(t, UseConvertBetweenSumAndGaugeMetricContext, tt.flagEnabled)() - expected := ottlfuncs.StandardFuncs[ottldatapoint.TransformContext]() expected["convert_summary_sum_val_to_sum"] = newConvertSummarySumValToSumFactory() expected["convert_summary_count_val_to_sum"] = newConvertSummaryCountValToSumFactory() - if !tt.flagEnabled { - expected["convert_sum_to_gauge"] = newConvertDatapointSumToGaugeFactory() - expected["convert_gauge_to_sum"] = newConvertDatapointGaugeToSumFactory() - } - actual := DataPointFunctions() require.Equal(t, len(expected), len(actual))