@@ -103,6 +103,30 @@ public static AttributeMapping create(
103103 AttributeMapping .create ("namespace_name" , ResourceAttributes .K8S_NAMESPACE_NAME ),
104104 AttributeMapping .create ("container_name" , ResourceAttributes .K8S_CONTAINER_NAME ),
105105 AttributeMapping .create ("pod_name" , ResourceAttributes .K8S_POD_NAME ));
106+ private static List <AttributeMapping > K8S_POD_LABELS =
107+ Arrays .asList (
108+ AttributeMapping .create (
109+ "location" ,
110+ Arrays .asList (
111+ ResourceAttributes .CLOUD_AVAILABILITY_ZONE , ResourceAttributes .CLOUD_REGION )),
112+ AttributeMapping .create ("cluster_name" , ResourceAttributes .K8S_CLUSTER_NAME ),
113+ AttributeMapping .create ("namespace_name" , ResourceAttributes .K8S_NAMESPACE_NAME ),
114+ AttributeMapping .create ("pod_name" , ResourceAttributes .K8S_POD_NAME ));
115+ private static List <AttributeMapping > K8S_NODE_LABELS =
116+ Arrays .asList (
117+ AttributeMapping .create (
118+ "location" ,
119+ Arrays .asList (
120+ ResourceAttributes .CLOUD_AVAILABILITY_ZONE , ResourceAttributes .CLOUD_REGION )),
121+ AttributeMapping .create ("cluster_name" , ResourceAttributes .K8S_CLUSTER_NAME ),
122+ AttributeMapping .create ("node_name" , ResourceAttributes .K8S_NODE_NAME ));
123+ private static List <AttributeMapping > K8S_CLUSTER_LABELS =
124+ Arrays .asList (
125+ AttributeMapping .create (
126+ "location" ,
127+ Arrays .asList (
128+ ResourceAttributes .CLOUD_AVAILABILITY_ZONE , ResourceAttributes .CLOUD_REGION )),
129+ AttributeMapping .create ("cluster_name" , ResourceAttributes .K8S_CLUSTER_NAME ));
106130 private static List <AttributeMapping > AWS_EC2_INSTANCE_LABELS =
107131 Arrays .asList (
108132 AttributeMapping .create ("instance_id" , ResourceAttributes .HOST_ID ),
@@ -153,13 +177,24 @@ public static GcpResource mapResource(Resource resource) {
153177 switch (platform ) {
154178 case ResourceAttributes .CloudPlatformValues .GCP_COMPUTE_ENGINE :
155179 return mapBase (resource , "gce_instance" , GCE_INSTANCE_LABELS );
156- case ResourceAttributes .CloudPlatformValues .GCP_KUBERNETES_ENGINE :
157- return mapBase (resource , "k8s_container" , K8S_CONTAINER_LABELS );
158180 case ResourceAttributes .CloudPlatformValues .AWS_EC2 :
159181 return mapBase (resource , "aws_ec2_instance" , AWS_EC2_INSTANCE_LABELS );
160182 case ResourceAttributes .CloudPlatformValues .GCP_APP_ENGINE :
161183 return mapBase (resource , "gae_instance" , GOOGLE_CLOUD_APP_ENGINE_INSTANCE_LABELS );
162184 default :
185+ // if k8s.cluster.name is set, pattern match for various k8s resources.
186+ // this will also match non-cloud k8s platforms like minikube.
187+ if (resource .getAttribute (ResourceAttributes .K8S_CLUSTER_NAME ) != null ) {
188+ if (resource .getAttribute (ResourceAttributes .K8S_CONTAINER_NAME ) != null ) {
189+ return mapBase (resource , "k8s_container" , K8S_CONTAINER_LABELS );
190+ } else if (resource .getAttribute (ResourceAttributes .K8S_POD_NAME ) != null ) {
191+ return mapBase (resource , "k8s_pod" , K8S_POD_LABELS );
192+ } else if (resource .getAttribute (ResourceAttributes .K8S_NODE_NAME ) != null ) {
193+ return mapBase (resource , "k8s_node" , K8S_NODE_LABELS );
194+ } else {
195+ return mapBase (resource , "k8s_cluster" , K8S_CLUSTER_LABELS );
196+ }
197+ }
163198 return genericTaskOrNode (resource );
164199 }
165200 }
0 commit comments