Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .chloggen/43919.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
component: processor/k8sattributes

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "`k8sattributesprocessor` now respects semantic convention resolution order for `service.namespace`"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [43919]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Previously, when `service.namespace` was included in the extract metadata configuration, the processor
would incorrectly allow `k8s.namespace.name` to override explicitly configured service namespace values
from OpenTelemetry annotations (e.g., `resource.opentelemetry.io/service.namespace`). Now the processor
correctly follows the semantic convention resolution order, where annotation values take precedence over
inferred Kubernetes namespace names.
# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion processor/k8sattributesprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (kp *kubernetesprocessor) processResource(ctx context.Context, resource pco
}

if kp.rules.ServiceNamespace {
resource.Attributes().PutStr(string(conventions.ServiceNamespaceKey), namespace)
setResourceAttribute(resource.Attributes(), string(conventions.ServiceNamespaceKey), namespace)
}
}

Expand Down
65 changes: 65 additions & 0 deletions processor/k8sattributesprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,71 @@ func TestAddNamespaceLabels(t *testing.T) {
})
}

func TestServiceNamespaceAnnotationTakesPrecedence(t *testing.T) {
// This test verifies that when a pod has an explicit service.namespace attribute
// (e.g., from resource.opentelemetry.io/service.namespace annotation),
// it should take precedence over the k8s.namespace.name value as per semantic conventions
m := newMultiTest(
t,
func() component.Config {
cfg := createDefaultConfig().(*Config)
cfg.Extract.Metadata = []string{string(conventions.ServiceNamespaceKey), "k8s.pod.ip"}
return cfg
}(),
nil,
)

podIP := "1.1.1.1"
m.kubernetesProcessorOperation(func(kp *kubernetesprocessor) {
kp.podAssociations = []kube.Association{
{
Sources: []kube.AssociationSource{
{
From: "connection",
},
},
},
}
})

m.kubernetesProcessorOperation(func(kp *kubernetesprocessor) {
pi := kube.PodIdentifier{
kube.PodIdentifierAttributeFromConnection(podIP),
}
// Pod is in kubernetes namespace "default" but has explicit service.namespace="agent" from annotation
kp.kc.(*fakeClient).Pods[pi] = &kube.Pod{
Name: "test-pod",
Namespace: "default",
Attributes: map[string]string{
string(conventions.ServiceNamespaceKey): "agent", // from resource.opentelemetry.io/service.namespace annotation
},
}
})

ctx := client.NewContext(t.Context(), client.Info{
Addr: &net.IPAddr{
IP: net.ParseIP(podIP),
},
})
m.testConsume(
ctx,
generateTraces(),
generateMetrics(),
generateLogs(),
generateProfiles(),
func(err error) {
assert.NoError(t, err)
})

m.assertBatchesLen(1)
m.assertResourceObjectLen(0)
m.assertResource(0, func(res pcommon.Resource) {
// service.namespace should be "agent" from the annotation, NOT "default" from k8s.namespace.name
assertResourceHasStringAttribute(t, res, "service.namespace", "agent")
assertResourceHasStringAttribute(t, res, "k8s.pod.ip", podIP)
})
}

func TestAddNodeLabels(t *testing.T) {
m := newMultiTest(
t,
Expand Down
Loading