From 29c44096ed89292f5bdfd5ecb3de24238d3c3c33 Mon Sep 17 00:00:00 2001 From: Ansen Garvin Date: Fri, 8 May 2026 13:40:00 -0700 Subject: [PATCH 1/2] chore: migrate pkg/ottl feature gates to metadata.yaml --- .../contexts/internal/ctxotelcol/otelcol.go | 14 +++-------- .../internal/ctxotelcol/otelcol_test.go | 7 +++--- pkg/ottl/documentation.md | 14 +++++++++++ pkg/ottl/factory.go | 9 ++------ .../metadata/generated_feature_gates.go | 23 +++++++++++++++++++ pkg/ottl/metadata.yaml | 13 +++++++++++ 6 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 pkg/ottl/documentation.md create mode 100644 pkg/ottl/internal/metadata/generated_feature_gates.go diff --git a/pkg/ottl/contexts/internal/ctxotelcol/otelcol.go b/pkg/ottl/contexts/internal/ctxotelcol/otelcol.go index 599a698cabbe6..6186e81743e60 100644 --- a/pkg/ottl/contexts/internal/ctxotelcol/otelcol.go +++ b/pkg/ottl/contexts/internal/ctxotelcol/otelcol.go @@ -7,26 +7,18 @@ import ( "context" "errors" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxerror" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/metadata" ) -var ( - enableOTelColContext = featuregate.GlobalRegistry().MustRegister( - "ottl.contexts.enableOTelColContext", - featuregate.StageBeta, - featuregate.WithRegisterDescription("Enable the `otelcol` context for OTTL. This allows users using `otelcol.*` paths in their OTTL statements and conditions."), - featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/46437"), - featuregate.WithRegisterFromVersion("v0.147.0")) - errOTelColContextDisabled = errors.New("OTTL `otelcol` context requires the `ottl.contexts.enableOTelColContext` feature gate to be enabled") -) +var errOTelColContextDisabled = errors.New("OTTL `otelcol` context requires the `ottl.contexts.enableOTelColContext` feature gate to be enabled") func PathGetSetter[K any](path ottl.Path[K]) (ottl.GetSetter[K], error) { - if !enableOTelColContext.IsEnabled() { + if !metadata.OttlContextsEnableOTelColContextFeatureGate.IsEnabled() { return nil, errOTelColContextDisabled } switch path.Name() { diff --git a/pkg/ottl/contexts/internal/ctxotelcol/otelcol_test.go b/pkg/ottl/contexts/internal/ctxotelcol/otelcol_test.go index 959644bded9cd..2f4ac04da02cc 100644 --- a/pkg/ottl/contexts/internal/ctxotelcol/otelcol_test.go +++ b/pkg/ottl/contexts/internal/ctxotelcol/otelcol_test.go @@ -16,6 +16,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/pathtest" + featureMetadata "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -477,12 +478,12 @@ func TestContextGrpcMetadata(t *testing.T) { } func Test_enableOTelColContextFeatureGate(t *testing.T) { - original := enableOTelColContext.IsEnabled() + original := featureMetadata.OttlContextsEnableOTelColContextFeatureGate.IsEnabled() defer func() { - require.NoError(t, featuregate.GlobalRegistry().Set(enableOTelColContext.ID(), original)) + require.NoError(t, featuregate.GlobalRegistry().Set(featureMetadata.OttlContextsEnableOTelColContextFeatureGate.ID(), original)) }() - require.NoError(t, featuregate.GlobalRegistry().Set(enableOTelColContext.ID(), false)) + require.NoError(t, featuregate.GlobalRegistry().Set(featureMetadata.OttlContextsEnableOTelColContextFeatureGate.ID(), false)) _, err := PathGetSetter(&pathtest.Path[testContext]{}) assert.Equal(t, errOTelColContextDisabled, err) } diff --git a/pkg/ottl/documentation.md b/pkg/ottl/documentation.md new file mode 100644 index 0000000000000..21aff3fdb493b --- /dev/null +++ b/pkg/ottl/documentation.md @@ -0,0 +1,14 @@ +[comment]: <> (Code generated by mdatagen. DO NOT EDIT.) + +# ottl + +## Feature Gates + +This component has the following feature gates: + +| Feature Gate | Stage | Description | From Version | To Version | Reference | +| ------------ | ----- | ----------- | ------------ | ---------- | --------- | +| `ottl.PanicDuplicateName` | beta | When enabled, the CreateFactoryMap panics if the name is duplicated. | v0.141.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/44630) | +| `ottl.contexts.enableOTelColContext` | beta | Enable the `otelcol` context for OTTL. This allows users using `otelcol.*` paths in their OTTL statements and conditions. | v0.147.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/46437) | + +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/pkg/ottl/factory.go b/pkg/ottl/factory.go index 45b8cfb7fd613..4e6caa3d242e8 100644 --- a/pkg/ottl/factory.go +++ b/pkg/ottl/factory.go @@ -5,13 +5,8 @@ package ottl // import "github.com/open-telemetry/opentelemetry-collector-contri import ( "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/featuregate" -) -var panicDuplicateName = featuregate.GlobalRegistry().MustRegister( - "ottl.PanicDuplicateName", - featuregate.StageBeta, - featuregate.WithRegisterDescription("When enabled, the CreateFactoryMap panics if the name is duplicated."), + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/metadata" ) // Arguments holds the arguments for an OTTL function, with arguments @@ -90,7 +85,7 @@ func CreateFactoryMap[K any](factories ...Factory[K]) map[string]Factory[K] { factoryMap := map[string]Factory[K]{} for _, fn := range factories { - if panicDuplicateName.IsEnabled() { + if metadata.OttlPanicDuplicateNameFeatureGate.IsEnabled() { if _, ok := factoryMap[fn.Name()]; ok { panic("duplicate factory name: " + fn.Name()) } diff --git a/pkg/ottl/internal/metadata/generated_feature_gates.go b/pkg/ottl/internal/metadata/generated_feature_gates.go new file mode 100644 index 0000000000000..44b390b947ce0 --- /dev/null +++ b/pkg/ottl/internal/metadata/generated_feature_gates.go @@ -0,0 +1,23 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/featuregate" +) + +var OttlPanicDuplicateNameFeatureGate = featuregate.GlobalRegistry().MustRegister( + "ottl.PanicDuplicateName", + featuregate.StageBeta, + featuregate.WithRegisterDescription("When enabled, the CreateFactoryMap panics if the name is duplicated."), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/44630"), + featuregate.WithRegisterFromVersion("v0.141.0"), +) + +var OttlContextsEnableOTelColContextFeatureGate = featuregate.GlobalRegistry().MustRegister( + "ottl.contexts.enableOTelColContext", + featuregate.StageBeta, + featuregate.WithRegisterDescription("Enable the `otelcol` context for OTTL. This allows users using `otelcol.*` paths in their OTTL statements and conditions."), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/46437"), + featuregate.WithRegisterFromVersion("v0.147.0"), +) diff --git a/pkg/ottl/metadata.yaml b/pkg/ottl/metadata.yaml index 000c6e2f93266..1f09941bcff36 100644 --- a/pkg/ottl/metadata.yaml +++ b/pkg/ottl/metadata.yaml @@ -10,3 +10,16 @@ status: active: [TylerHelmuth, evan-bradley, edmocosta, bogdandrutu] emeritus: [anuraaga, kentquirk] seeking_new: true + +feature_gates: + - id: "ottl.PanicDuplicateName" + description: When enabled, the CreateFactoryMap panics if the name is duplicated. + stage: beta + from_version: v0.141.0 + reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/44630 + + - id: "ottl.contexts.enableOTelColContext" + description: Enable the `otelcol` context for OTTL. This allows users using `otelcol.*` paths in their OTTL statements and conditions. + stage: beta + from_version: v0.147.0 + reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/46437 \ No newline at end of file From 0d9fff3d50fcb022bccb7cf151d614f3dfc5cab1 Mon Sep 17 00:00:00 2001 From: Ansen Garvin Date: Fri, 8 May 2026 13:50:51 -0700 Subject: [PATCH 2/2] chore: remove forbidigo exclusion --- .golangci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ca2fe28bedb60..5f47f11ef3343 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -146,9 +146,6 @@ linters: - linters: - forbidigo path: internal/filter/ - - linters: - - forbidigo - path: pkg/ottl/ - linters: - forbidigo path: receiver/awscontainerinsightreceiver/