diff --git a/dependency-replacements.yaml b/dependency-replacements.yaml index ee4710b180f..3f1c2d20a6a 100644 --- a/dependency-replacements.yaml +++ b/dependency-replacements.yaml @@ -112,10 +112,6 @@ replaces: dependency: github.com/openshift/client-go replacement: github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235 - - 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 - - comment: > Do not remove until bug in walqueue backwards compatibility is resolved: https://github.com/deneonet/benc/issues/13 diff --git a/docs/sources/reference/components/otelcol/otelcol.processor.k8sattributes.md b/docs/sources/reference/components/otelcol/otelcol.processor.k8sattributes.md index b212c50329b..b13ce19032d 100644 --- a/docs/sources/reference/components/otelcol/otelcol.processor.k8sattributes.md +++ b/docs/sources/reference/components/otelcol/otelcol.processor.k8sattributes.md @@ -145,10 +145,11 @@ The `extract` block configures which metadata, annotations, and labels to extrac The following attributes are supported: -| Name | Type | Description | Default | Required | -|--------------------|----------------|-----------------------------------------------------------------------------|-------------|----------| -| `metadata` | `list(string)` | Pre-configured metadata keys to add. | _See below_ | no | -| `otel_annotations` | `bool` | Whether to set the [recommended resource attributes][semantic conventions]. | `false` | no | +| Name | Type | Description | Default | Required | +|-----------------------------------|----------------|------------------------------------------------------------------------------------------|-------------|----------| +| `deployment_name_from_replicaset` | `bool` | Whether to set the deployment name by trimming the hash from the end of the replica set. | `false` | no | +| `metadata` | `list(string)` | Pre-configured metadata keys to add. | _See below_ | no | +| `otel_annotations` | `bool` | Whether to set the [recommended resource attributes][semantic conventions]. | `false` | no | The supported `metadata` keys are: @@ -194,6 +195,8 @@ By default, if `metadata` isn't specified, the following fields are extracted an When `otel_annotations` is set to `true`, annotations such as `resource.opentelemetry.io/exampleResource` will be translated to the `exampleResource` resource attribute, etc. +When `deployment_name_from_replicaset` is set to `true`, the processor will extract deployment name from replicaset name by trimming pod template hash. This will disable watching for replicaset resources, which can be useful in environments with limited RBAC permissions as the processor will not need `get`, `watch`, and `list` permissions for replicasets. + [semantic conventions]: https://opentelemetry.io/docs/specs/semconv/non-normative/k8s-attributes ### `annotation` diff --git a/go.mod b/go.mod index c2eaa9dc0d9..299a1242351 100644 --- a/go.mod +++ b/go.mod @@ -1078,9 +1078,6 @@ replace go.opentelemetry.io/ebpf-profiler => github.com/grafana/opentelemetry-eb // Update openshift/client-go to version compatible with structured-merge-diff v6 replace github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235 -// 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 - // Do not remove until bug in walqueue backwards compatibility is resolved: https://github.com/deneonet/benc/issues/13 replace github.com/deneonet/benc => github.com/deneonet/benc v1.1.7 diff --git a/go.sum b/go.sum index 5f73137fbe5..efb322692dd 100644 --- a/go.sum +++ b/go.sum @@ -1169,8 +1169,6 @@ github.com/grafana/mysqld_exporter v0.17.2-0.20250226152553-be612e3fdedd h1:FW1K github.com/grafana/mysqld_exporter v0.17.2-0.20250226152553-be612e3fdedd/go.mod h1:iEFA+REkm+0WRvVxy0cA1bBhJlFcQB998yymb45TqMU= github.com/grafana/node_exporter v0.18.1-grafana-r01.0.20251024135609-318b01780c89 h1:Ab3Z4AXC1Hffr4NbeYq0vTQhJbiGTTO2xd0ZV0kC1v8= github.com/grafana/node_exporter v0.18.1-grafana-r01.0.20251024135609-318b01780c89/go.mod h1:BUJCdmzfsndvLKeFuONqMPsEA0fkeVuAyt8II4Lk0Dg= -github.com/grafana/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.0.0-20251021125353-73458b01ab23 h1:Im1l5kbKfi61ySivYhUBkyWTqHNyAKiWO6rNKQJoNmU= -github.com/grafana/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.0.0-20251021125353-73458b01ab23/go.mod h1:7+xyIHr2PJNE9kic/D91c9SMxACdGIGCJykzTcqsYv0= github.com/grafana/opentelemetry-collector/featuregate v0.0.0-20240325174506-2fd1623b2ca0 h1:i/Ne0XwoRokYj52ZcSmnvuyID3h/uA91n0Ycg/grHU8= github.com/grafana/opentelemetry-collector/featuregate v0.0.0-20240325174506-2fd1623b2ca0/go.mod h1:mm8+xyQfgDmqhyegZRNIQmoKsNnDTwWKFLsdMoXAb7A= github.com/grafana/opentelemetry-ebpf-instrumentation v1.3.13 h1:za+TpC0g0Iu7UYz0Q7rLbIzhsRLItZCuPr2pFeVhW/U= @@ -1863,8 +1861,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometh github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.139.0/go.mod h1:/NDwJwHP4yBFL4B+vDah49ROKH1cro8BS7ThezFZinA= github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.139.0 h1:ctfs8S1cQuhbXJVqSlAx8SxPmgFq2eOcllc7Pdpr9RE= github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.139.0/go.mod h1:BduGmN98+nV2KObW0woovcuNwkSvSVLiPG6+Ww95uSk= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest v0.138.0 h1:Fec1dyH3wRPjrvGN5qYLwkuXCAk4cAUcS5qGgDmT5OM= -github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest v0.138.0/go.mod h1:o6eRn8JV22jyCPJcZ/NS3IeSB90E+0xBaL9Y/4NtPmY= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest v0.139.0 h1:r2x9V8N8237yRfjqcboHinSQDYyFahQLpVAlrbNyf2Y= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest v0.139.0/go.mod h1:UFk787D+Yk19nIthQqfznRz2tao4YF3WpdZ2+wBMDj0= github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.139.0 h1:dhXq+slRSV2xt3sXA43jQgltM5qYF3vsOJkYyIir8Ws= github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.139.0/go.mod h1:zFDjfoufAQFSxDP4FqY5HJv0xUVIV1sZm0mmfcCkUzY= github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor v0.139.0 h1:Wt1OMsFL4Ts1VoYNKISPsNeTlKsCD2//Fnhbm0oG/tY= @@ -1877,6 +1875,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrs github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.139.0/go.mod h1:G3WduXLMn48lLkO6fNuBPhO3xPkEDJOJXGRcdGDewVM= github.com/open-telemetry/opentelemetry-collector-contrib/processor/intervalprocessor v0.139.0 h1:upeoL/u8sNMv2wILr0tJjS8D10PFbIZXhtmSvcTRzdU= github.com/open-telemetry/opentelemetry-collector-contrib/processor/intervalprocessor v0.139.0/go.mod h1:/YGA2DC8VSLBFAsycUPul9dkL5n8CcGXJ2rkKEyvNVg= +github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.139.0 h1:+/Tn0RTacKwmjtwl+dQiuIeYf3S5g9Aoqcq6u+jxoqY= +github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.139.0/go.mod h1:eaC5oqWFYOe/xDImeJkw3E5NIQ9Uf93wLxqrR7kKHKg= github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor v0.139.0 h1:yMINTAhwrAFBg+4dmR2241egJAdOjD3x9BSnyMkwNiM= github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor v0.139.0/go.mod h1:rZJSbBQCdMjBmxTwTwaXpStHOyB0lWa5nP8JKqD0ME0= github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.139.0 h1:ODYstgINw1NuHiUdUPJOSkRfaJTvRvyqEzCF4m2XGLg= diff --git a/internal/component/otelcol/processor/k8sattributes/k8sattributes_test.go b/internal/component/otelcol/processor/k8sattributes/k8sattributes_test.go index e476ea7e7c3..813d36c761e 100644 --- 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) } func Test_ExtractAnnotations(t *testing.T) { diff --git a/internal/component/otelcol/processor/k8sattributes/types.go b/internal/component/otelcol/processor/k8sattributes/types.go index 1b103f71ab3..0ab175f286c 100644 --- a/internal/component/otelcol/processor/k8sattributes/types.go +++ b/internal/component/otelcol/processor/k8sattributes/types.go @@ -17,10 +17,11 @@ 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{} { @@ -36,10 +37,11 @@ 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, } } diff --git a/internal/converter/internal/otelcolconvert/converter_k8sattributesprocessor.go b/internal/converter/internal/otelcolconvert/converter_k8sattributesprocessor.go index 62a955b0b60..3940521cab4 100644 --- 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,