Skip to content
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

Update language around setting Kubernetes pod name in container info #701

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

estolfo
Copy link
Contributor

@estolfo estolfo commented Oct 6, 2022

Most agents already set the Kubernetes pod name correctly but the spec language was a bit misleading. This PR makes it more precise how the pod name should be set.

@estolfo estolfo requested review from a team as code owners October 6, 2022 10:20
@apmmachine
Copy link

apmmachine commented Oct 6, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-03-31T04:32:00.031+0000

  • Duration: 3 min 2 sec

@@ -108,7 +107,9 @@ On Linux, the container ID and some of the Kubernetes metadata can be extracted

If we match, then the basename is assumed to be a container ID.

If the Kubernetes pod name is not the hostname, it can be overridden by the `KUBERNETES_POD_NAME` environment variable, using the [Downward API](https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/). In a similar manner, you can inform the agent of the node name and namespace, using the environment variables `KUBERNETES_NODE_NAME` and `KUBERNETES_NAMESPACE`.
Sometimes the `KUBERNETES_POD_NAME` is set using the [Downward API](https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/),
so we set the pod name to its value if it exists. Otherwise, we set the pod name to the hostname, because by default, Kubernetes will set the hostname to the pod name.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
so we set the pod name to its value if it exists. Otherwise, we set the pod name to the hostname, because by default, Kubernetes will set the hostname to the pod name.
so we set the pod name to its value if it exists. Otherwise, we set the pod name to the hostname, because that's the default value Kubernetes uses.

@estolfo estolfo force-pushed the kubernetes-pod-name branch from 4d82638 to 1a82dcb Compare October 12, 2022 12:32
If the Kubernetes pod name is not the hostname, it can be overridden by the `KUBERNETES_POD_NAME` environment variable, using the [Downward API](https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/). In a similar manner, you can inform the agent of the node name and namespace, using the environment variables `KUBERNETES_NODE_NAME` and `KUBERNETES_NAMESPACE`.
Sometimes the `KUBERNETES_POD_NAME` is set using the [Downward API](https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/),
so we set the pod name to its value if it exists.
In a similar manner, you can inform the agent of the node name and namespace, using the environment variables `KUBERNETES_NODE_NAME` and `KUBERNETES_NAMESPACE`.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Perhaps also mention KUBERNETES_POD_UID to set/override metadata.system.kubernetes.pid.uid? Though that's adding scope. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the KUBERNETES_POD_UID to the spec. I don't know why it wasn't mentioned, unless I'm missing some special logic?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know why it wasn't mentioned, unless I'm missing some special logic?

I think it was just overlooked when added. AFAICT all the agents implement reading KUBERNETES_POD_UID.

@estolfo estolfo requested review from a team as code owners October 14, 2022 10:47
@estolfo estolfo force-pushed the kubernetes-pod-name branch from b4ac13c to 924c2ff Compare December 4, 2023 16:50
@estolfo estolfo merged commit e1564e3 into elastic:main Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants