-
Notifications
You must be signed in to change notification settings - Fork 273
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
[Resources.Container] Add Kubernetes support #1699
base: main
Are you sure you want to change the base?
Conversation
src/OpenTelemetry.ResourceDetectors.Container/ContainerResourceDetector.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.ResourceDetectors.Container/ContainerResourceDetector.cs
Outdated
Show resolved
Hide resolved
@@ -18,6 +21,13 @@ public class ContainerResourceDetector : IResourceDetector | |||
private const string Filepath = "/proc/self/cgroup"; | |||
private const string FilepathV2 = "/proc/self/mountinfo"; | |||
private const string Hostname = "hostname"; | |||
private const string K8sServiceHostKey = "KUBERNETES_SERVICE_HOST"; | |||
private const string K8sServicePortKey = "KUBERNETES_SERVICE_PORT_HTTPS"; | |||
private const string K8sNamespaceKey = "KUBERNETES_NAMESPACE"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this environment variable and KUBERNETES_CONTAINER_NAME
available in all Kubernetes environments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I know, KUBERNETES_NAMESPACE
and KUBERNETES_CONTAINER_NAME
are not available by default in Kubernetes. The user will have to provide them using the downward API.
var @namespace = Environment.GetEnvironmentVariable(K8sNamespaceKey); | ||
var hostname = Environment.GetEnvironmentVariable(K8sHostnameKey); | ||
var containerName = Environment.GetEnvironmentVariable(K8sContainerNameKey); | ||
var url = $"https://{host}:{port}/api/v1/namespaces/{@namespace}/pods/{hostname}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the guarantee that this will be a well-formed URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing I think but in this case an exception will be thrown, catched and logged using the EventSource.
private const string K8sServicePortKey = "KUBERNETES_SERVICE_PORT_HTTPS"; | ||
private const string K8sNamespaceKey = "KUBERNETES_NAMESPACE"; | ||
private const string K8sHostnameKey = "HOSTNAME"; | ||
private const string K8sContainerNameKey = "KUBERNETES_CONTAINER_NAME"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tricky part here - k8s doesn't have any standard variable to provide container name. It is entirely based on the user. I don't see any issues that extractor would expect it to be named "KUBERNETES_CONTAINER_NAME" - but probably it may be better to be passed by user to detector as constructor argument.
If it is passed by user, we can also report it as additional attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's the same for KUBERNETES_NAMESPACE
in this case, which is not standard as well. Perhaps we can let the user supply the values via the constructor but also keep automatic detection via the environment variables if they are not supplied. What do you think?
If it is passed by user, we can also report it as additional attribute.
I'm not sure that's the purpose of this detector. From my point of view, the user can already use the env variable OTEL_RESOURCE_ATTRIBUTES
or implement his own detector to add this resource attribute.
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Not stale. I'll try to finish review this week. |
@joegoldman2, I actually don't know what should be the procedure to review/validate a new API. From my point of view (I'm curently codeowner for src/OpenTelemetry.Resources.Container), anything that will give a way to provide required values from code should work, as it will be in compliance with specification. As it will be isolated as arguments of AddContainerDetector method, we probably don't need any wider audience review. Alternatvely we can try to visit Tuesday meeting and seek opinions / advices there. |
BTW, we just finished validation of using k8sattributes processor on collector, and it perfectly solves the problem of resovling container.id for k8s cluster (once |
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
src/OpenTelemetry.Resources.Container/ContainerResourceEventSource.cs
Outdated
Show resolved
Hide resolved
…urce.cs Co-authored-by: Weihan Li <weihanli@outlook.com>
Do you have a link to the related issue? |
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
@joegoldman2, we published instruction how to use K8 attribute processor for resolveing container id in OTEL collector: https://docs.appdynamics.com/observability/cisco-cloud-observability/en/application-performance-monitoring/monitor-applications-in-kubernetes/infrastructure-correlation#InfrastructureCorrelation-KubernetesAttributeProcessorConfiguredontheOpenTelemetryCollector |
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Fixes #1562.
Only tested manually at the moment.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes