-
Notifications
You must be signed in to change notification settings - Fork 47
support GKE resource detection #24
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
support GKE resource detection #24
Conversation
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/exporter/cloud_trace/__init__.py
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/tests/test_gcp_resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/tests/test_gcp_resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/tests/test_gcp_resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/tests/test_gcp_resource_detector.py
Outdated
Show resolved
Hide resolved
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.
Awesome! I added some general comments, but I can't comment on the k8s stuff.
opentelemetry-exporter-cloud-monitoring/src/opentelemetry/exporter/cloud_monitoring/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Outdated
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Show resolved
Hide resolved
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Show resolved
Hide resolved
], | ||
"k8s.namespace.name": pod_namespace, | ||
"host.id": all_metadata["instance"]["id"], | ||
"k8s.pod.name": os.getenv("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.
Apparently GKE supports windows, idk if this will work there, unless k8s injects the envar. You might want platform.node()
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.
It's being set by Kubernetes I believe, but it doesn't always 100% match the pod name due to trimming: kubernetes/kubernetes#4825 (comment)
So I think it would be safer to read a separate environment variable by default, e.g. POD_NAME
, and possibly fallback to HOSTNAME
as a best guess.
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.
Though this behavior does match the OpenCensus implementation: https://github.com/census-ecosystem/opencensus-go-resource/blob/87ca538ec76b3961839940406845ef624d794fa8/gke/gke.go#L48
/cc @rghetia see the issue above about trimming the pod name to 63 characters. Shall we introduce a separate environment variable to be passed via https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables ?
opentelemetry-exporter-cloud-trace/tests/test_gcp_resource_detector.py
Outdated
Show resolved
Hide resolved
@nilebox could you take a look at the kubernetes specific stuff here? |
], | ||
"k8s.namespace.name": pod_namespace, | ||
"host.id": all_metadata["instance"]["id"], | ||
"k8s.pod.name": os.getenv("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.
It's being set by Kubernetes I believe, but it doesn't always 100% match the pod name due to trimming: kubernetes/kubernetes#4825 (comment)
So I think it would be safer to read a separate environment variable by default, e.g. POD_NAME
, and possibly fallback to HOSTNAME
as a best guess.
], | ||
"k8s.namespace.name": pod_namespace, | ||
"host.id": all_metadata["instance"]["id"], | ||
"k8s.pod.name": os.getenv("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.
Though this behavior does match the OpenCensus implementation: https://github.com/census-ecosystem/opencensus-go-resource/blob/87ca538ec76b3961839940406845ef624d794fa8/gke/gke.go#L48
/cc @rghetia see the issue above about trimming the pod name to 63 characters. Shall we introduce a separate environment variable to be passed via https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables ?
opentelemetry-exporter-cloud-trace/src/opentelemetry/tools/resource_detector.py
Outdated
Show resolved
Hide resolved
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.
Looks good! If you addressed all of Nail's comments, please merge 😃
Add the ability to detect GKE resources in the Google Cloud Resource Detector and to export this info to Cloud Trace and Cloud Monitoring