Skip to content

Commit b064c9e

Browse files
committed
use mdatagen for feature gates
Signed-off-by: odubajDT <[email protected]>
1 parent 0049158 commit b064c9e

File tree

8 files changed

+63
-44
lines changed

8 files changed

+63
-44
lines changed

processor/k8sattributesprocessor/documentation.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ This component has the following feature gates:
159159

160160
| Feature Gate | Stage | Description | From Version | To Version | Reference |
161161
| ------------ | ----- | ----------- | ------------ | ---------- | --------- |
162-
| `k8sattr.labelsAnnotationsSingular.allow` | alpha | When enabled, default k8s label and annotation resource attribute keys will be singular, instead of plural | v0.125.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39774) |
162+
| `k8sattr.labelsAnnotationsSingular.allow` | deprecated | When enabled, default k8s label and annotation resource attribute keys will be singular, instead of plural | v0.125.0 | v0.145.0 | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39774) |
163+
| `semconv.k8s.k8sattributes.disableLegacy` | alpha | When enabled, semconv legacy attributes are disabled. | v0.145.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/44589) |
164+
| `semconv.k8s.k8sattributes.enableStable` | alpha | When enabled, semconv stable attributes are enabled. | v0.145.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/44589) |
163165

164166
For more information about feature gates, see the [Feature Gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md) documentation.

processor/k8sattributesprocessor/internal/kube/client.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/distribution/reference"
1717
"go.opentelemetry.io/collector/component"
18-
"go.opentelemetry.io/collector/featuregate"
1918
"go.opentelemetry.io/otel/attribute"
2019
conventions "go.opentelemetry.io/otel/semconv/v1.39.0"
2120
"go.uber.org/zap"
@@ -65,21 +64,6 @@ const (
6564
K8sJobAnnotation = "k8s.job.annotation.%s"
6665
)
6766

68-
var (
69-
EnableStableAttributes = featuregate.GlobalRegistry().MustRegister(
70-
"semconv.k8s.k8sattributes.enableStable",
71-
featuregate.StageAlpha,
72-
featuregate.WithRegisterDescription("When enabled, semconv stable attributes are enabled."),
73-
featuregate.WithRegisterFromVersion("v0.144.0"),
74-
)
75-
DisableLegacyAttributes = featuregate.GlobalRegistry().MustRegister(
76-
"semconv.k8s.k8sattributes.disableLegacy",
77-
featuregate.StageAlpha,
78-
featuregate.WithRegisterDescription("When enabled, semconv legacy attributes are disabled."),
79-
featuregate.WithRegisterFromVersion("v0.144.0"),
80-
)
81-
)
82-
8367
// WatchClient is the main interface provided by this package to a kubernetes cluster.
8468
type WatchClient struct {
8569
m sync.RWMutex
@@ -934,8 +918,8 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
934918
}
935919
}
936920

937-
enableStable := EnableStableAttributes.IsEnabled()
938-
disableLegacy := DisableLegacyAttributes.IsEnabled()
921+
enableStable := metadata.SemconvK8sK8sattributesEnableStableFeatureGate.IsEnabled()
922+
disableLegacy := metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.IsEnabled()
939923

940924
for _, r := range c.Rules.Labels {
941925
if !disableLegacy {
@@ -1183,8 +1167,8 @@ func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContain
11831167
func (c *WatchClient) extractNamespaceAttributes(namespace *api_v1.Namespace) map[string]string {
11841168
tags := map[string]string{}
11851169

1186-
enableStable := EnableStableAttributes.IsEnabled()
1187-
disableLegacy := DisableLegacyAttributes.IsEnabled()
1170+
enableStable := metadata.SemconvK8sK8sattributesEnableStableFeatureGate.IsEnabled()
1171+
disableLegacy := metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.IsEnabled()
11881172

11891173
for _, r := range c.Rules.Labels {
11901174
if !disableLegacy {
@@ -1210,8 +1194,8 @@ func (c *WatchClient) extractNamespaceAttributes(namespace *api_v1.Namespace) ma
12101194
func (c *WatchClient) extractNodeAttributes(node *api_v1.Node) map[string]string {
12111195
tags := map[string]string{}
12121196

1213-
enableStable := EnableStableAttributes.IsEnabled()
1214-
disableLegacy := DisableLegacyAttributes.IsEnabled()
1197+
enableStable := metadata.SemconvK8sK8sattributesEnableStableFeatureGate.IsEnabled()
1198+
disableLegacy := metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.IsEnabled()
12151199

12161200
for _, r := range c.Rules.Labels {
12171201
if !disableLegacy {

processor/k8sattributesprocessor/internal/kube/client_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/client-go/tools/cache"
3232

3333
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
34+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/metadata"
3435
)
3536

3637
func newFakeAPIClientset(_ k8sconfig.APIConfig) (kubernetes.Interface, error) {
@@ -1073,11 +1074,11 @@ func TestExtractionRules(t *testing.T) {
10731074
for _, tc := range testCases {
10741075
t.Run(tc.name, func(t *testing.T) {
10751076
if tc.singularFeatureGate {
1076-
require.NoError(t, featuregate.GlobalRegistry().Set(EnableStableAttributes.ID(), true))
1077-
require.NoError(t, featuregate.GlobalRegistry().Set(DisableLegacyAttributes.ID(), true))
1077+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), true))
1078+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), true))
10781079
defer func() {
1079-
require.NoError(t, featuregate.GlobalRegistry().Set(EnableStableAttributes.ID(), false))
1080-
require.NoError(t, featuregate.GlobalRegistry().Set(DisableLegacyAttributes.ID(), false))
1080+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), false))
1081+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), false))
10811082
}()
10821083
}
10831084

@@ -1379,11 +1380,11 @@ func TestNamespaceExtractionRules(t *testing.T) {
13791380
for _, tc := range testCases {
13801381
t.Run(tc.name, func(t *testing.T) {
13811382
if tc.singularFeatureGate {
1382-
require.NoError(t, featuregate.GlobalRegistry().Set(EnableStableAttributes.ID(), true))
1383-
require.NoError(t, featuregate.GlobalRegistry().Set(DisableLegacyAttributes.ID(), true))
1383+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), true))
1384+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), true))
13841385
defer func() {
1385-
require.NoError(t, featuregate.GlobalRegistry().Set(EnableStableAttributes.ID(), false))
1386-
require.NoError(t, featuregate.GlobalRegistry().Set(DisableLegacyAttributes.ID(), false))
1386+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), false))
1387+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), false))
13871388
}()
13881389
}
13891390

@@ -1639,11 +1640,11 @@ func TestNodeExtractionRules(t *testing.T) {
16391640
for _, tc := range testCases {
16401641
t.Run(tc.name, func(t *testing.T) {
16411642
if tc.singularFeatureGate {
1642-
require.NoError(t, featuregate.GlobalRegistry().Set(EnableStableAttributes.ID(), true))
1643-
require.NoError(t, featuregate.GlobalRegistry().Set(DisableLegacyAttributes.ID(), true))
1643+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), true))
1644+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), true))
16441645
defer func() {
1645-
require.NoError(t, featuregate.GlobalRegistry().Set(EnableStableAttributes.ID(), false))
1646-
require.NoError(t, featuregate.GlobalRegistry().Set(DisableLegacyAttributes.ID(), false))
1646+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), false))
1647+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), false))
16471648
}()
16481649
}
16491650

processor/k8sattributesprocessor/internal/metadata/generated_feature_gates.go

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/k8sattributesprocessor/metadata.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,24 @@ resource_attributes:
136136

137137
feature_gates:
138138
- id: k8sattr.labelsAnnotationsSingular.allow
139-
stage: alpha
139+
stage: deprecated
140140
description: >-
141141
When enabled, default k8s label and annotation resource attribute keys will be singular, instead of plural
142142
from_version: v0.125.0
143+
to_version: v0.145.0
143144
reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39774
145+
- id: semconv.k8s.k8sattributes.disableLegacy
146+
stage: alpha
147+
description: >-
148+
When enabled, semconv legacy attributes are disabled.
149+
from_version: v0.145.0
150+
reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/44589
151+
- id: semconv.k8s.k8sattributes.enableStable
152+
stage: alpha
153+
description: >-
154+
When enabled, semconv stable attributes are enabled.
155+
from_version: v0.145.0
156+
reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/44589
144157

145158
tests:
146159
config:

processor/k8sattributesprocessor/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ func extractFieldRules(fieldType string, fields ...FieldExtractConfig) ([]kube.F
274274
// name for KeyRegex case is set at extraction time/runtime, skipped here
275275
// Use singular form when stable attributes are enabled and legacy attributes are disabled
276276
fieldTypeName := fieldType
277-
enableStable := kube.EnableStableAttributes.IsEnabled()
278-
disableLegacy := kube.DisableLegacyAttributes.IsEnabled()
277+
enableStable := metadata.SemconvK8sK8sattributesEnableStableFeatureGate.IsEnabled()
278+
disableLegacy := metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.IsEnabled()
279279
if enableStable && disableLegacy {
280280
fieldTypeName = strings.TrimSuffix(fieldType, "s")
281281
}

processor/k8sattributesprocessor/options_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
1616
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
17+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/metadata"
1718
)
1819

1920
func TestWithAPIConfig(t *testing.T) {
@@ -737,13 +738,13 @@ func Test_extractFieldRules_FeatureGate(t *testing.T) {
737738
t.Run(tt.name, func(t *testing.T) {
738739
// Set feature gate state for stable and legacy attributes
739740
if tt.featureGateValue {
740-
require.NoError(t, featuregate.GlobalRegistry().Set(kube.EnableStableAttributes.ID(), true))
741-
require.NoError(t, featuregate.GlobalRegistry().Set(kube.DisableLegacyAttributes.ID(), true))
741+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), true))
742+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), true))
742743
}
743744
defer func() {
744745
// Reset to default
745-
require.NoError(t, featuregate.GlobalRegistry().Set(kube.EnableStableAttributes.ID(), false))
746-
require.NoError(t, featuregate.GlobalRegistry().Set(kube.DisableLegacyAttributes.ID(), false))
746+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesEnableStableFeatureGate.ID(), false))
747+
require.NoError(t, featuregate.GlobalRegistry().Set(metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.ID(), false))
747748
}()
748749

749750
got, err := extractFieldRules(tt.fieldType, tt.fields...)

processor/k8sattributesprocessor/processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
2424
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
25+
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/metadata"
2526
)
2627

2728
const (
@@ -59,7 +60,7 @@ func (kp *kubernetesprocessor) initKubeClient(set component.TelemetrySettings, k
5960
}
6061

6162
func (kp *kubernetesprocessor) Start(_ context.Context, host component.Host) error {
62-
if kube.DisableLegacyAttributes.IsEnabled() && !kube.EnableStableAttributes.IsEnabled() {
63+
if metadata.SemconvK8sK8sattributesDisableLegacyFeatureGate.IsEnabled() && !metadata.SemconvK8sK8sattributesEnableStableFeatureGate.IsEnabled() {
6364
err := errors.New("cannot disable legacy attributes without enabling stable attributes")
6465
componentstatus.ReportStatus(host, componentstatus.NewFatalErrorEvent(err))
6566
return err

0 commit comments

Comments
 (0)