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

[processor/resourcedetection] Detect Azure Kubernetes Service cluster name #29328

Merged
merged 12 commits into from
Jan 29, 2024

Conversation

jsirianni
Copy link
Member

Description:

Added best effort support for detecting Azure Kubernetes Service cluster name: k8s.cluster.name.

The cluster name can be extracted from the cluster's "resource group name" which is retrieved using existing functionality. The parseClusterName function has comments explaining the limitations.

Link to tracking Issue:

#26794

Testing:

I added unit tests for each scenario, and have tested against live AKS clusters that fit each scenario. I am happy to spin these up if anyone has any questions.

Documentation:

Added k8s.cluster.name to the list of AKS resource attributes.

@jsirianni jsirianni requested a review from mx-psi as a code owner November 17, 2023 14:28
@jsirianni jsirianni requested a review from a team November 17, 2023 14:28
@github-actions github-actions bot added the processor/resourcedetection Resource detection processor label Nov 17, 2023
@mx-psi
Copy link
Member

mx-psi commented Nov 20, 2023

cc @jinja2 @jsirianni. Would also be great if someone from Microsoft reviews this :)

enabled: true
k8s.cluster.name:
description: The k8s.cluster.name
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some details in the description about how the cluster name is detected? The comments in the code are great but a user won't know to refer to them and might assume that this is set to the cluster resource name which might not be the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for taking a look. I added some clarity to the metadata yaml and readme.

@jsirianni jsirianni force-pushed the azure/detect-cluster-name branch from 125db6d to 0065a48 Compare December 4, 2023 19:02
@jsirianni
Copy link
Member Author

@mx-psi Let me know if there is anything else I need to do here 👍


The cluster name is accurately detected if underscores are not present in the resource group name or the cluster name.

If accurate parsing cannot be performed, the infrastructure resource group value is returned. This value can be used to accurately identify the cluster, as Azure will not allow users to create multiple clusters with the same infrastructure resource group.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If accurate parsing cannot be performed, the infrastructure resource group value is returned. This value can be used to accurately identify the cluster, as Azure will not allow users to create multiple clusters with the same infrastructure resource group.
If accurate parsing cannot be performed, the infrastructure resource group value is returned. This value can be used to uniquely identify the cluster, as Azure will not allow users to create multiple clusters with the same infrastructure resource group name.


Azure AKS cluster name is derived from the Azure Instance Metadata Service's (IMDS) infrastructure resource group field. This field contains the resource group and name of the cluster, separated by underscores. e.g: `MC_<resource group>_<cluster name>_<location>`.

The cluster name is accurately detected if underscores are not present in the resource group name or the cluster name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Imo we should clarify that we can only get the correct cluster name if custom resource group name is not used. I still think some users might prefer setting the clusterName themself then defaulting to custom resource group name. So explicitly making a note of what is returned in different scenarios would provide better user experience.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Apologies for the late response.

@mx-psi
Copy link
Member

mx-psi commented Dec 5, 2023

@mx-psi Let me know if there is anything else I need to do here 👍

I was waiting on jinja2 to finish their review before I took a look :)

description: The k8s.cluster.name parsed from the Azure Instance Metadata Service's infrastructure resource group field
type: string
enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
enabled: true
enabled: false

I think we should keep it disabled by default.

@jsirianni jsirianni force-pushed the azure/detect-cluster-name branch from 0065a48 to 030bdc1 Compare December 18, 2023 15:45
@jsirianni jsirianni requested a review from jinja2 December 18, 2023 15:45
Copy link
Contributor

github-actions bot commented Jan 2, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jan 2, 2024
@mx-psi mx-psi removed the Stale label Jan 3, 2024
@mx-psi
Copy link
Member

mx-psi commented Jan 3, 2024

@jinja2 Mind taking another look?

// because Azure will not allow the user to create multiple AKS clusters with the same
// infrastructure resource group name.
func parseClusterName(resourceGroup string) string {
// Code inspired by https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/datadogexporter/internal/hostmetadata/internal/azure/provider.go#L36
Copy link
Member

@dmitryax dmitryax Jan 8, 2024

Choose a reason for hiding this comment

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

Nice description for parseClusterName 👍

Assuming that this code won't be removed from exporter/datadogexporter going forward (cc @mx-psi to confirm), I think we should consolidate it in internal/azure and use it both here and in exporter/datadogexporter. Moving it from exporter/datadogexporter to internal/azure can be done in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

We are not going to remove this from the Datadog exporter in the short term,so I agree we should consolidate this 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, no action needed from me?

Copy link
Contributor

@jinja2 jinja2 Jan 17, 2024

Choose a reason for hiding this comment

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

So we'd like to make it a common utility in internal/azure and update the components, but can be done in a separate PR. @dmitryax if this is not a blocker, I think we are good to merge this needs some testing updates

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me as a follow-up PR. @jsirianni will you have a chance to submit that PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dmitryax I think I can handle that 👍

Copy link
Member

Choose a reason for hiding this comment

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

@jsirianni thanks. Submitted #30834

@jsirianni jsirianni force-pushed the azure/detect-cluster-name branch from 030bdc1 to 197d3d5 Compare January 12, 2024 16:10
@@ -34,6 +34,8 @@ func TestDetector_Detect_K8s_Azure(t *testing.T) {
assert.Equal(t, map[string]any{
"cloud.provider": "azure",
"cloud.platform": "azure_aks",
// Cluster name will not be detected if resource grup is not set
"k8s.cluster.name": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

If the attribute is not enabled, it won't be available in the output, so you want to remove this. See failing test here.
I think it would be better to add another test case with the attribute enabled.

@jsirianni jsirianni force-pushed the azure/detect-cluster-name branch from 18236de to 3f0c0e3 Compare January 25, 2024 21:02
@dmitryax dmitryax merged commit a13a115 into open-telemetry:main Jan 29, 2024
85 checks passed
@github-actions github-actions bot added this to the next release milestone Jan 29, 2024
cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this pull request Feb 1, 2024
… name (open-telemetry#29328)

**Description:**

Added best effort support for detecting Azure Kubernetes Service cluster
name: `k8s.cluster.name`.

The cluster name can be extracted from the cluster's "resource group
name" which is retrieved using existing functionality. The
`parseClusterName` function has comments explaining the limitations.

**Link to tracking Issue:**

open-telemetry#26794

**Testing:**

I added unit tests for each scenario, and have tested against live AKS
clusters that fit each scenario. I am happy to spin these up if anyone
has any questions.

Added `k8s.cluster.name` to the list of AKS resource attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/resourcedetection Resource detection processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants