Skip to content

feat: Add missing configuration parameter deployment_name_from_replicaset to k8sattributes processor#5183

Merged
dehaansa merged 1 commit intomainfrom
k8sattributes-deploymentextraction
Jan 6, 2026
Merged

feat: Add missing configuration parameter deployment_name_from_replicaset to k8sattributes processor#5183
dehaansa merged 1 commit intomainfrom
k8sattributes-deploymentextraction

Conversation

@dehaansa
Copy link
Contributor

@dehaansa dehaansa commented Jan 6, 2026

Brief description of Pull Request

Add deployment_name_from_replicaset attribute to k8sattributes processor supporting extraction of deployment name from replica set.

Pull Request Details

Issue(s) fixed by this Pull Request

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated
  • Config converters updated

@dehaansa dehaansa requested review from a team and clayton-cornell as code owners January 6, 2026 19:55
@dehaansa dehaansa changed the title feat: add missing configuration parameter deployment_name_from_replicaset to k8sattributes processor feat: Add missing configuration parameter deployment_name_from_replicaset to k8sattributes processor Jan 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

🔍 Dependency Review

github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor grafana/opentelemetry-collector-contrib@73458b01ab23 (replace) -> v0.139.0 (upstream)

Status: ⚠️ Needs Review

Summary:

  • The explicit replace to Grafana’s fork is removed, switching back to upstream k8sattributesprocessor at v0.139.0.
  • The fork was previously used for compatibility with k8s.io/client-go v0.34.1. Moving to upstream implies upstream now supports this; please verify in your CI/build environment.
  • Upstream adds a new extraction option deployment_name_from_replicaset. To expose it in your config API and to pass it through to the processor, minor code changes are required (already included in this PR).

Required code updates:

  • Expose the new boolean option in your component’s config schema and pass it through to the underlying processor config.

Suggested diffs (matching the changes already in this PR):

  • Add the new field to your ExtractConfig and include it in the map:
--- a/internal/component/otelcol/processor/k8sattributes/types.go
+++ b/internal/component/otelcol/processor/k8sattributes/types.go
@@ -17,15 +17,17 @@ func (args FieldExtractConfig) convert() map[string]interface{} {
 }
 
 type ExtractConfig struct {
-	Metadata        []string             `alloy:"metadata,attr,optional"`
-	Annotations     []FieldExtractConfig `alloy:"annotation,block,optional"`
-	Labels          []FieldExtractConfig `alloy:"label,block,optional"`
-	OtelAnnotations bool                 `alloy:"otel_annotations,attr,optional"`
+	Metadata                     []string             `alloy:"metadata,attr,optional"`
+	Annotations                  []FieldExtractConfig `alloy:"annotation,block,optional"`
+	Labels                       []FieldExtractConfig `alloy:"label,block,optional"`
+	OtelAnnotations              bool                 `alloy:"otel_annotations,attr,optional"`
+	DeploymentNameFromReplicaSet bool                 `alloy:"deployment_name_from_replicaset,attr,optional"`
 }
 
 func (args ExtractConfig) convert() map[string]interface{} {
   ...
 	return map[string]interface{}{
-		"metadata":         args.Metadata,
-		"annotations":      annotations,
-		"labels":           labels,
-		"otel_annotations": args.OtelAnnotations,
+		"metadata":                        args.Metadata,
+		"annotations":                     annotations,
+		"labels":                          labels,
+		"otel_annotations":                args.OtelAnnotations,
+		"deployment_name_from_replicaset": args.DeploymentNameFromReplicaSet,
 	}
 }
  • Thread the new field through your otelcol converter:
--- a/internal/converter/internal/otelcolconvert/converter_k8sattributesprocessor.go
+++ b/internal/converter/internal/otelcolconvert/converter_k8sattributesprocessor.go
@@ -55,10 +55,11 @@ func toK8SAttributesProcessor(state *State, id componentstatus.InstanceID, cfg *
 		AuthType:    string(cfg.AuthType),
 		Passthrough: cfg.Passthrough,
 		ExtractConfig: k8sattributes.ExtractConfig{
-			Metadata:        cfg.Extract.Metadata,
-			Annotations:     toFilterExtract(cfg.Extract.Annotations),
-			Labels:          toFilterExtract(cfg.Extract.Labels),
-			OtelAnnotations: cfg.Extract.OtelAnnotations,
+			Metadata:                     cfg.Extract.Metadata,
+			Annotations:                  toFilterExtract(cfg.Extract.Annotations),
+			Labels:                       toFilterExtract(cfg.Extract.Labels),
+			OtelAnnotations:              cfg.Extract.OtelAnnotations,
+			DeploymentNameFromReplicaSet: cfg.Extract.DeploymentNameFromReplicaSet,
 		},
 		Filter: k8sattributes.FilterConfig{
 			Node:      cfg.Filter.Node,
  • Update tests to cover the new option (as shown in this PR):
--- a/internal/component/otelcol/processor/k8sattributes/k8sattributes_test.go
+++ b/internal/component/otelcol/processor/k8sattributes/k8sattributes_test.go
@@ -26,6 +26,8 @@ func Test_Extract(t *testing.T) {
 				"k8s.job.name",
 				"k8s.node.name",
 			]
+
+			deployment_name_from_replicaset = true
 		}
 
 		output {
@@ -44,6 +46,8 @@ func Test_Extract(t *testing.T) {
 
 	extract := &otelObj.Extract
 	require.Equal(t, []string{"k8s.namespace.name", "k8s.job.name", "k8s.node.name"}, extract.Metadata)
+
+	require.True(t, extract.DeploymentNameFromReplicaSet)
 }

Operational considerations:

  • The new flag disables watching ReplicaSet resources and derives deployment name by trimming the hash suffix from the ReplicaSet name. If you depend on live ReplicaSet metadata, ensure this behavioral change is intentional where the flag is enabled.
  • Verify that upstream v0.139.0 is compatible with your k8s.io/client-go version (previous fork addressed this specifically).

Evidence:

  • Replacement removal in go.mod:
-// Use Grafana's patched k8sattributesprocessor with support for k8s.io/client-go v0.34.1
-replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor => github.com/grafana/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.0.0-20251021125353-73458b01ab23
  • Upstream module version now resolved in go.sum:
github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.139.0
  • New config documented in your docs:
    • Added deployment_name_from_replicaset option and description.

Notes

  • go.sum also reflects an update of github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest to v0.139.0. This is a test helper and no go.mod require change is present; no code changes are expected unless you import it directly.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

💻 Deploy preview available (feat: add missing configuration parameter deployment_name_from_replicaset to k8sattributes processor):

Comment on lines -104 to -107
- comment: Use Grafana's patched k8sattributesprocessor with support for k8s.io/client-go v0.34.1
dependency: github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor
replacement: github.com/grafana/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.0.0-20251021125353-73458b01ab23

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay for one less replacement, did this happen because upstream was on a lower version that has since been upgraded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Happened ~a couple months ago open-telemetry/opentelemetry-collector-contrib#43890

@dehaansa dehaansa merged commit b54ca77 into main Jan 6, 2026
48 of 49 checks passed
@dehaansa dehaansa deleted the k8sattributes-deploymentextraction branch January 6, 2026 20:40
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

💻 Deploy preview deleted (feat: Add missing configuration parameter deployment_name_from_replicaset to k8sattributes processor).

@grafana-alloybot grafana-alloybot bot mentioned this pull request Jan 6, 2026
@dehaansa dehaansa added the backport/v1.12 Backport to release/v1.12 label Jan 6, 2026
grafana-alloybot bot pushed a commit that referenced this pull request Jan 6, 2026
…caset` to k8sattributes processor (#5183)

Add missing configuration parameter to k8sattributes processor

(cherry picked from commit b54ca77)
@grafana-alloybot grafana-alloybot bot mentioned this pull request Jan 6, 2026
3 tasks
dehaansa added a commit that referenced this pull request Jan 6, 2026
feat: Add missing configuration parameter `deployment_name_from_replicaset` to k8sattributes processor (#5183)

Add missing configuration parameter to k8sattributes processor

(cherry picked from commit b54ca77)

Co-authored-by: Sam DeHaan <sam.dehaan@grafana.com>
blewis12 pushed a commit that referenced this pull request Jan 7, 2026
…caset` to k8sattributes processor (#5183)

Add missing configuration parameter to k8sattributes processor
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v1.12 Backport to release/v1.12 frozen-due-to-age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants