Fix shared pidns disambiguation#1875
Fix shared pidns disambiguation#1875NimrodAvni78 wants to merge 7 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1875 +/- ##
==========================================
- Coverage 69.40% 69.32% -0.08%
==========================================
Files 277 277
Lines 32992 33280 +288
==========================================
+ Hits 22897 23072 +175
- Misses 8882 8972 +90
- Partials 1213 1236 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes Kubernetes metadata misattribution when multiple containers share the same PID namespace (notably hostPID: true pods mapping to the host init_pid_ns) by disambiguating via host PID, and adds coverage for the shared-PID-namespace scenario.
Changes:
- Update
PodContainerByPIDNsto prefer an exact host-PID match and avoid nondeterministic selection when PID namespaces are shared. - Propagate host PID into call sites that decorate spans and process events.
- Add unit + integration tests covering shared PID namespace attribution (Deployment + hostPID DaemonSet).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/transform/k8s.go | Passes host PID into PodContainerByPIDNs for correct disambiguation during decoration. |
| pkg/kube/store.go | Implements deterministic PID-namespace lookup with host-PID-based disambiguation and safe fallback behavior. |
| pkg/kube/store_test.go | Adds unit tests for exact-match, unambiguous fallback, and ambiguous shared-namespace behavior. |
| internal/test/integration/k8s/sharedpidns/k8s_sharedpidns_test.go | Adds integration assertions ensuring no cross-pod metadata leakage under shared PID namespaces. |
| internal/test/integration/k8s/sharedpidns/k8s_sharedpidns_main_test.go | Sets up a dedicated Kind-based integration scenario for shared PID namespaces. |
| internal/test/integration/k8s/manifests/05-hostpid-daemonset.yml | Introduces a hostPID DaemonSet workload to reproduce the shared PID namespace condition. |
| internal/test/integration/k8s/manifests/06-obi-daemonset-sharedpidns.yml | Adds an OBI config/DaemonSet manifest to instrument both workloads in the shared-PIDNS test. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| continue | ||
| } | ||
| if info.ContainerID != pick.ContainerID { | ||
| s.log.Debug("cannot disambiguate shared PID namespace without matching host PID; skipping k8s decoration", |
There was a problem hiding this comment.
should we increase log verbosity here? not sure between info/warn
rafaelroquetto
left a comment
There was a problem hiding this comment.
Non-rhetorical question: why can't we just rely on the host pid?
I think it might work, i can try it out and test myself Edit: not sure we can only rely on hostPID, we do register child processes to the map, but it is done via polling, if an event from a child process of a normal pod (no hostPID:true) comes without the childPID being registered yet we wont find it, right now we will find the correct pidNs and attribute it to the correct pod i think the only situation where there will be a problem with the newly implemented solution is for hostPID:true pods with child processes, and they have yet to be registered via the polling cycle. in that case we will hit the case where we see multiple processes from multiple containers under the same pidNS, we will see multiple infos from multiple containers without an exact hostPID match, so we decide to not enrich the span instead of picking a random container (what the previous solution has done) tbh not sure how to fix that, unless we move to monitoring fork/exec via eBPF to not allow for periods where pids are not registred |
|
SIG meeting: this may be specific to deployment difference between sidecar and daemonset |
Summary
PodContainerByPIDNsto use the host PID for disambiguation when multiple containers share a PID namespace (e.g.hostPID: truepods all map to the hostinit_pid_nsinode)Resolves #1871
Testing
Validation