diff --git a/.chloggen/promote-processor_transform_ConvertBetweenSumAndGaugeMetricContext-to-beta.yaml b/.chloggen/promote-processor_transform_ConvertBetweenSumAndGaugeMetricContext-to-beta.yaml new file mode 100644 index 000000000000..3133d28899d5 --- /dev/null +++ b/.chloggen/promote-processor_transform_ConvertBetweenSumAndGaugeMetricContext-to-beta.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: transformprocessor + +# 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 flag from alpha to beta" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34567] + +# (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: + +# 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: [user] diff --git a/processor/transformprocessor/config.go b/processor/transformprocessor/config.go index 8c184510ed5a..2eaeb094d5e5 100644 --- a/processor/transformprocessor/config.go +++ b/processor/transformprocessor/config.go @@ -41,6 +41,7 @@ type Config struct { LogStatements []common.ContextStatements `mapstructure:"log_statements"` FlattenData bool `mapstructure:"flatten_data"` + logger *zap.Logger } var _ component.Config = (*Config)(nil) @@ -48,6 +49,10 @@ 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/factory.go b/processor/transformprocessor/factory.go index 7138907dc303..0dda808a1e62 100644 --- a/processor/transformprocessor/factory.go +++ b/processor/transformprocessor/factory.go @@ -90,6 +90,7 @@ func createMetricsProcessor( nextConsumer consumer.Metrics, ) (processor.Metrics, error) { oCfg := cfg.(*Config) + oCfg.logger = set.Logger proc, err := metrics.NewProcessor(oCfg.MetricStatements, oCfg.ErrorMode, set.TelemetrySettings) if err != nil { diff --git a/processor/transformprocessor/internal/metrics/functions.go b/processor/transformprocessor/internal/metrics/functions.go index beee15b3f7d7..e9e58b08a212 100644 --- a/processor/transformprocessor/internal/metrics/functions.go +++ b/processor/transformprocessor/internal/metrics/functions.go @@ -12,9 +12,9 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlfuncs" ) -var useConvertBetweenSumAndGaugeMetricContext = featuregate.GlobalRegistry().MustRegister( +var UseConvertBetweenSumAndGaugeMetricContext = featuregate.GlobalRegistry().MustRegister( "processor.transform.ConvertBetweenSumAndGaugeMetricContext", - featuregate.StageAlpha, + featuregate.StageBeta, featuregate.WithRegisterDescription("When enabled will use metric context for conversion between sum and gauge"), ) @@ -26,7 +26,7 @@ func DataPointFunctions() map[string]ottl.Factory[ottldatapoint.TransformContext newConvertSummaryCountValToSumFactory(), ) - if !useConvertBetweenSumAndGaugeMetricContext.IsEnabled() { + if !UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() { for _, f := range []ottl.Factory[ottldatapoint.TransformContext]{ newConvertDatapointSumToGaugeFactory(), newConvertDatapointGaugeToSumFactory(), @@ -53,7 +53,7 @@ func MetricFunctions() map[string]ottl.Factory[ottlmetric.TransformContext] { newAggregateOnAttributesFactory(), ) - if useConvertBetweenSumAndGaugeMetricContext.IsEnabled() { + if UseConvertBetweenSumAndGaugeMetricContext.IsEnabled() { for _, f := range []ottl.Factory[ottlmetric.TransformContext]{ newConvertSumToGaugeFactory(), newConvertGaugeToSumFactory(), diff --git a/processor/transformprocessor/internal/metrics/functions_test.go b/processor/transformprocessor/internal/metrics/functions_test.go index 2ea2da3eea89..98a08e18652f 100644 --- a/processor/transformprocessor/internal/metrics/functions_test.go +++ b/processor/transformprocessor/internal/metrics/functions_test.go @@ -16,18 +16,45 @@ import ( ) func Test_DataPointFunctions(t *testing.T) { - expected := ottlfuncs.StandardFuncs[ottldatapoint.TransformContext]() - expected["convert_sum_to_gauge"] = newConvertDatapointSumToGaugeFactory() - expected["convert_gauge_to_sum"] = newConvertDatapointGaugeToSumFactory() - expected["convert_summary_sum_val_to_sum"] = newConvertSummarySumValToSumFactory() - expected["convert_summary_count_val_to_sum"] = newConvertSummaryCountValToSumFactory() + type testCase struct { + name string + flagEnabled bool + } - actual := DataPointFunctions() + tests := []testCase{ + { + name: "ConvertBetweenSumAndGaugeMetricContextEnabled enabled", + flagEnabled: true, + }, + { + name: "ConvertBetweenSumAndGaugeMetricContextEnabled disabled", + flagEnabled: false, + }, + } - require.Equal(t, len(expected), len(actual)) - for k := range actual { - assert.Contains(t, expected, k) + 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)) + for k := range actual { + assert.Contains(t, expected, k) + } + }, + ) } + } func Test_MetricFunctions(t *testing.T) { @@ -40,7 +67,6 @@ func Test_MetricFunctions(t *testing.T) { expected["copy_metric"] = newCopyMetricFactory() expected["scale_metric"] = newScaleMetricFactory() - defer testutil.SetFeatureGateForTest(t, useConvertBetweenSumAndGaugeMetricContext, true)() actual := MetricFunctions() require.Equal(t, len(expected), len(actual)) for k := range actual {