diff --git a/.golangci.yml b/.golangci.yml index e23dc3b388976..bf6e0f7737ba3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -203,9 +203,6 @@ linters: - linters: - forbidigo path: processor/filterprocessor/ - - linters: - - forbidigo - path: processor/metricsgenerationprocessor/ - linters: - forbidigo path: processor/tailsamplingprocessor/ diff --git a/processor/metricsgenerationprocessor/documentation.md b/processor/metricsgenerationprocessor/documentation.md new file mode 100644 index 0000000000000..ff40fce949167 --- /dev/null +++ b/processor/metricsgenerationprocessor/documentation.md @@ -0,0 +1,13 @@ +[comment]: <> (Code generated by mdatagen. DO NOT EDIT.) + +# metricsgeneration + +## Feature Gates + +This component has the following feature gates: + +| Feature Gate | Stage | Description | From Version | To Version | Reference | +| ------------ | ----- | ----------- | ------------ | ---------- | --------- | +| `metricsgeneration.MatchAttributes` | alpha | When enabled, the metric calculations will only be done between data points whose attributes match. | v0.112.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35425) | + +For more information about feature gates, see the [Feature Gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md) documentation. diff --git a/processor/metricsgenerationprocessor/internal/metadata/generated_feature_gates.go b/processor/metricsgenerationprocessor/internal/metadata/generated_feature_gates.go new file mode 100644 index 0000000000000..cea073bbea851 --- /dev/null +++ b/processor/metricsgenerationprocessor/internal/metadata/generated_feature_gates.go @@ -0,0 +1,15 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/featuregate" +) + +var MetricsgenerationMatchAttributesFeatureGate = featuregate.GlobalRegistry().MustRegister( + "metricsgeneration.MatchAttributes", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("When enabled, the metric calculations will only be done between data points whose attributes match."), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35425"), + featuregate.WithRegisterFromVersion("v0.112.0"), +) diff --git a/processor/metricsgenerationprocessor/metadata.yaml b/processor/metricsgenerationprocessor/metadata.yaml index 0609ee7873a62..a1541219e8469 100644 --- a/processor/metricsgenerationprocessor/metadata.yaml +++ b/processor/metricsgenerationprocessor/metadata.yaml @@ -8,5 +8,12 @@ status: distributions: [contrib] codeowners: active: [Aneurysm9, crobert-1] +feature_gates: + - id: metricsgeneration.MatchAttributes + description: >- + When enabled, the metric calculations will only be done between data points whose attributes match. + stage: alpha + from_version: "v0.112.0" + reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35425 tests: config: diff --git a/processor/metricsgenerationprocessor/processor.go b/processor/metricsgenerationprocessor/processor.go index 8bc44fd563c60..8388637bf4eda 100644 --- a/processor/metricsgenerationprocessor/processor.go +++ b/processor/metricsgenerationprocessor/processor.go @@ -8,17 +8,10 @@ import ( "fmt" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" -) -var matchAttributes = featuregate.GlobalRegistry().MustRegister( - "metricsgeneration.MatchAttributes", - featuregate.StageAlpha, - featuregate.WithRegisterDescription("When enabled, the metric calculations will only be done between data points whose attributes match."), - featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/35425"), - featuregate.WithRegisterFromVersion("v0.112.0"), + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricsgenerationprocessor/internal/metadata" ) type metricsGenerationProcessor struct { @@ -78,7 +71,7 @@ func (mgp *metricsGenerationProcessor) processMetrics(_ context.Context, md pmet continue } - if matchAttributes.IsEnabled() { + if metadata.MetricsgenerationMatchAttributesFeatureGate.IsEnabled() { generateCalculatedMetrics(rm, metric2, rule, mgp.logger) } else { // When matching metric attributes isn't required the value of the first data point of metric2 is diff --git a/processor/metricsgenerationprocessor/processor_test.go b/processor/metricsgenerationprocessor/processor_test.go index 858ca29e07604..412e8af5fbcf2 100644 --- a/processor/metricsgenerationprocessor/processor_test.go +++ b/processor/metricsgenerationprocessor/processor_test.go @@ -293,7 +293,9 @@ func TestMetricsGenerationProcessor(t *testing.T) { ctx := t.Context() require.NoError(t, mgp.Start(ctx, nil)) - cErr := mgp.ConsumeMetrics(t.Context(), test.inMetrics) + inputCopy := pmetric.NewMetrics() + test.inMetrics.CopyTo(inputCopy) + cErr := mgp.ConsumeMetrics(t.Context(), inputCopy) assert.NoError(t, cErr) got := next.AllMetrics() @@ -514,7 +516,7 @@ func TestGoldenFileMetrics(t *testing.T) { for _, testCase := range testCaseNames { t.Run(testCase.name, func(t *testing.T) { - require.NoError(t, featuregate.GlobalRegistry().Set(matchAttributes.ID(), testCase.matchAttributesFlagEnabled)) + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.MetricsgenerationMatchAttributesFeatureGate.ID(), testCase.matchAttributesFlagEnabled)) cm, err := confmaptest.LoadConf(filepath.Join("testdata", testCase.testDir, "config.yaml")) assert.NoError(t, err)