New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Kubernetes metadata #342
Conversation
Codecov Report
@@ Coverage Diff @@
## master #342 +/- ##
=========================================
+ Coverage 81.14% 83.54% +2.4%
=========================================
Files 98 98
Lines 5891 6009 +118
=========================================
+ Hits 4780 5020 +240
- Misses 840 923 +83
+ Partials 271 66 -205
Continue to review full report at Codecov.
|
While testing, I realised that the container.id wasn't being populated. That's because the cgroup paths are different under k8s. They look like this:
The last segment is the Docker container ID. Obviously only holds if Docker is the container runtime being used. The second-to-last segment is the pod UID, prefixed with "pod". I also realised we can get the pod name just from the hostname. Need to run some more tests, with the following variables:
|
4a23929
to
9615697
Compare
cb27f5b
to
3cd3fa4
Compare
We sniff kubernetes pod metadata from /proc/self/cgroup, and add or override any values specified through the environment variables KUBERNETES_{NAMESPACE,NODE_NAME,POD_NAME,POD_UID}. Also, stop checking for "docker" in the cgroup path. The 64-bit hex ID check should be sufficient to avoid false positives. We only do this check for non-k8s environments.
…pm-agent-go#342 (as in, pretty much copied from elastic/apm-agent-go#342)
…pm-agent-go#342 (as in, pretty much copied from elastic/apm-agent-go#342)
parsing uses regexes heavily inspired by elastic/apm-agent-go#342 (as in, pretty much copied from elastic/apm-agent-go#342) closes #352 fixes #346 fixes #347
Add Kubernetes metadata. We sniff pod metadata from
/proc/self/cgroup
, and then add or override any values specified through the environment variablesKUBERNETES_NAMESPACE
,KUBERNETES_NODE_NAME
,KUBERNETES_POD_NAME
, andKUBERNETES_POD_UID
. These can be populated using the Kubernetes Downward API.Through
/proc/self/cgroup
we are able to sniff the container ID and pod UID. We also assume that the hostname is the pod name, which is the default. If the hostname has been explicitly set, then the user can use the Downward API as mentioned above to set the correct pod name.Closes #329