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

Fix #340 bug #342

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static AttributeMapping create(
public static GcpResource mapResource(Resource resource) {
String platform = resource.getAttribute(ResourceAttributes.CLOUD_PLATFORM);
if (platform == null) {
return genericTaskOrNode(resource);
return mapK8sResourceOrGenericTaskOrNode(resource);
}
switch (platform) {
case ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE:
Expand All @@ -182,21 +182,25 @@ public static GcpResource mapResource(Resource resource) {
case ResourceAttributes.CloudPlatformValues.GCP_APP_ENGINE:
return mapBase(resource, "gae_instance", GOOGLE_CLOUD_APP_ENGINE_INSTANCE_LABELS);
default:
// if k8s.cluster.name is set, pattern match for various k8s resources.
// this will also match non-cloud k8s platforms like minikube.
if (resource.getAttribute(ResourceAttributes.K8S_CLUSTER_NAME) != null) {
if (resource.getAttribute(ResourceAttributes.K8S_CONTAINER_NAME) != null) {
return mapBase(resource, "k8s_container", K8S_CONTAINER_LABELS);
} else if (resource.getAttribute(ResourceAttributes.K8S_POD_NAME) != null) {
return mapBase(resource, "k8s_pod", K8S_POD_LABELS);
} else if (resource.getAttribute(ResourceAttributes.K8S_NODE_NAME) != null) {
return mapBase(resource, "k8s_node", K8S_NODE_LABELS);
} else {
return mapBase(resource, "k8s_cluster", K8S_CLUSTER_LABELS);
}
}
return genericTaskOrNode(resource);
psx95 marked this conversation as resolved.
Show resolved Hide resolved
return mapK8sResourceOrGenericTaskOrNode(resource);
}
}

private static GcpResource mapK8sResourceOrGenericTaskOrNode(Resource resource) {
// if k8s.cluster.name is set, pattern match for various k8s resources.
// this will also match non-cloud k8s platforms like minikube.
if (resource.getAttribute(ResourceAttributes.K8S_CLUSTER_NAME) != null) {
if (resource.getAttribute(ResourceAttributes.K8S_CONTAINER_NAME) != null) {
return mapBase(resource, "k8s_container", K8S_CONTAINER_LABELS);
} else if (resource.getAttribute(ResourceAttributes.K8S_POD_NAME) != null) {
return mapBase(resource, "k8s_pod", K8S_POD_LABELS);
} else if (resource.getAttribute(ResourceAttributes.K8S_NODE_NAME) != null) {
return mapBase(resource, "k8s_node", K8S_NODE_LABELS);
} else {
return mapBase(resource, "k8s_cluster", K8S_CLUSTER_LABELS);
}
}
return genericTaskOrNode(resource);
}

private static GcpResource genericTaskOrNode(Resource resource) {
Expand Down
Loading
Loading