From d0bc7a94f7214c507996085b88c5dd44caa299f2 Mon Sep 17 00:00:00 2001 From: tkmsaaaam <59013192+tkmsaaaam@users.noreply.github.com> Date: Sat, 11 May 2024 15:47:22 +0900 Subject: [PATCH 1/2] Fix #340 bug --- .../resource/ResourceTranslator.java | 34 ++++--- .../resource/ResourceTranslatorTest.java | 92 +++++++++++++------ 2 files changed, 84 insertions(+), 42 deletions(-) diff --git a/shared/resourcemapping/src/main/java/com/google/cloud/opentelemetry/resource/ResourceTranslator.java b/shared/resourcemapping/src/main/java/com/google/cloud/opentelemetry/resource/ResourceTranslator.java index f1e84ec6..e891637c 100644 --- a/shared/resourcemapping/src/main/java/com/google/cloud/opentelemetry/resource/ResourceTranslator.java +++ b/shared/resourcemapping/src/main/java/com/google/cloud/opentelemetry/resource/ResourceTranslator.java @@ -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: @@ -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); + 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) { diff --git a/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java b/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java index 806e3407..fe8c50cd 100644 --- a/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java +++ b/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java @@ -88,6 +88,60 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc Map.ofEntries( new SimpleEntry<>( ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + new SimpleEntry<>( + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "GKE-testNameSpace"), + new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "GKE-testHostName")), + "k8s_pod", + Map.ofEntries( + new SimpleEntry<>("location", "country-region-zone"), + new SimpleEntry<>("cluster_name", "GKE-cluster-name"), + new SimpleEntry<>("namespace_name", "GKE-testNameSpace"), + new SimpleEntry<>("pod_name", "GKE-testHostName"))), + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + new SimpleEntry<>( + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NODE_NAME, "GKE-node-name")), + "k8s_node", + Map.ofEntries( + new SimpleEntry<>("location", "country-region-zone"), + new SimpleEntry<>("node_name", "GKE-node-name"), + new SimpleEntry<>("cluster_name", "GKE-cluster-name"))), + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + new SimpleEntry<>( + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name")), + "k8s_cluster", + Map.ofEntries( + new SimpleEntry<>("location", "country-region-zone"), + new SimpleEntry<>("cluster_name", "GKE-cluster-name"))), + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS), @@ -101,7 +155,8 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, + ResourceAttributes.CloudProviderValues.AZURE), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AZURE_AKS), @@ -115,7 +170,7 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS), @@ -133,7 +188,8 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, + ResourceAttributes.CloudProviderValues.AZURE), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AZURE_AKS), @@ -151,7 +207,7 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS), @@ -167,7 +223,8 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, + ResourceAttributes.CloudProviderValues.AZURE), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AZURE_AKS), @@ -183,7 +240,7 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EKS), @@ -203,7 +260,8 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, + ResourceAttributes.CloudProviderValues.AZURE), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AZURE_AKS), @@ -222,11 +280,6 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), - new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AWS_EKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name")), @@ -236,11 +289,6 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), - new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AWS_EKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), @@ -255,11 +303,6 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), - new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AZURE_AKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), @@ -271,11 +314,6 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), - new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AZURE_AKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), From 1eb9ba10135b6bd5f851e1363c59400ed137bb60 Mon Sep 17 00:00:00 2001 From: tkmsaaaam <59013192+tkmsaaaam@users.noreply.github.com> Date: Wed, 15 May 2024 21:48:59 +0900 Subject: [PATCH 2/2] Fixed the order about test cases & added comments Fixed for more readable. --- .../resource/ResourceTranslatorTest.java | 251 +++++++++--------- 1 file changed, 130 insertions(+), 121 deletions(-) diff --git a/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java b/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java index fe8c50cd..95cd9efd 100644 --- a/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java +++ b/shared/resourcemapping/src/test/java/com/google/cloud/opentelemetry/resource/ResourceTranslatorTest.java @@ -41,24 +41,8 @@ private static Arguments generateOTelResourceMappingTestArgs( private static Stream provideOTelResourceAttributesToMonitoredResourceMapping() { return Stream.of( - generateOTelResourceMappingTestArgs( - Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), - new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE), - new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), - new SimpleEntry<>( - ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), - new SimpleEntry<>(ResourceAttributes.HOST_ID, "GCE-instance-id"), - new SimpleEntry<>(ResourceAttributes.HOST_NAME, "GCE-instance-name"), - new SimpleEntry<>(ResourceAttributes.HOST_TYPE, "GCE-instance-type")), - "gce_instance", - Map.ofEntries( - new SimpleEntry<>("instance_id", "GCE-instance-id"), - new SimpleEntry<>("zone", "country-region-zone"))), + // test cases for k8s + // test cases for k8s_container on [GCP, AWS, Azure, non-cloud] generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( @@ -87,86 +71,82 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), - new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + ResourceAttributes.CloudPlatformValues.AWS_EKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name"), - new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "GKE-testNameSpace"), - new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "GKE-testHostName")), - "k8s_pod", + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "EKS-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "EKS-namespace-name"), + new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "EKS-pod-name"), + new SimpleEntry<>(ResourceAttributes.K8S_CONTAINER_NAME, "EKS-container-name")), + "k8s_container", Map.ofEntries( - new SimpleEntry<>("location", "country-region-zone"), - new SimpleEntry<>("cluster_name", "GKE-cluster-name"), - new SimpleEntry<>("namespace_name", "GKE-testNameSpace"), - new SimpleEntry<>("pod_name", "GKE-testHostName"))), + new SimpleEntry<>("cluster_name", "EKS-cluster-name"), + new SimpleEntry<>("namespace_name", "EKS-namespace-name"), + new SimpleEntry<>("pod_name", "EKS-pod-name"), + new SimpleEntry<>("container_name", "EKS-container-name"), + new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, + ResourceAttributes.CloudProviderValues.AZURE), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), - new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + ResourceAttributes.CloudPlatformValues.AZURE_AKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name"), - new SimpleEntry<>(ResourceAttributes.K8S_NODE_NAME, "GKE-node-name")), - "k8s_node", + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "AKS-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "AKS-namespace-name"), + new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "AKS-pod-name"), + new SimpleEntry<>(ResourceAttributes.K8S_CONTAINER_NAME, "AKS-container-name")), + "k8s_container", Map.ofEntries( - new SimpleEntry<>("location", "country-region-zone"), - new SimpleEntry<>("node_name", "GKE-node-name"), - new SimpleEntry<>("cluster_name", "GKE-cluster-name"))), + new SimpleEntry<>("cluster_name", "AKS-cluster-name"), + new SimpleEntry<>("namespace_name", "AKS-namespace-name"), + new SimpleEntry<>("pod_name", "AKS-pod-name"), + new SimpleEntry<>("container_name", "AKS-container-name"), + new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), - new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), - new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name")), - "k8s_cluster", - Map.ofEntries( - new SimpleEntry<>("location", "country-region-zone"), - new SimpleEntry<>("cluster_name", "GKE-cluster-name"))), - generateOTelResourceMappingTestArgs( - Map.ofEntries( - new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), new SimpleEntry<>( - ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AWS_EKS), + ResourceAttributes.K8S_NAMESPACE_NAME, "non-cloud-namespace-name"), + new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "non-cloud-pod-name"), new SimpleEntry<>( - ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "EKS-cluster-name")), - "k8s_cluster", + ResourceAttributes.K8S_CONTAINER_NAME, "non-cloud-container-name")), + "k8s_container", Map.ofEntries( - new SimpleEntry<>("cluster_name", "EKS-cluster-name"), + new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), + new SimpleEntry<>("namespace_name", "non-cloud-namespace-name"), + new SimpleEntry<>("pod_name", "non-cloud-pod-name"), + new SimpleEntry<>("container_name", "non-cloud-container-name"), new SimpleEntry<>("location", "country-region-zone"))), + // test cases for k8s_pod on [GCP, AWS, Azure, non-cloud] generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, - ResourceAttributes.CloudProviderValues.AZURE), + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, - ResourceAttributes.CloudPlatformValues.AZURE_AKS), + ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "AKS-cluster-name")), - "k8s_cluster", + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "GKE-testNameSpace"), + new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "GKE-testHostName")), + "k8s_pod", Map.ofEntries( - new SimpleEntry<>("cluster_name", "AKS-cluster-name"), - new SimpleEntry<>("location", "country-region-zone"))), + new SimpleEntry<>("location", "country-region-zone"), + new SimpleEntry<>("cluster_name", "GKE-cluster-name"), + new SimpleEntry<>("namespace_name", "GKE-testNameSpace"), + new SimpleEntry<>("pod_name", "GKE-testHostName"))), generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( @@ -204,6 +184,39 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("pod_name", "AKS-pod-name"), new SimpleEntry<>("namespace_name", "AKS-namespace-name"), new SimpleEntry<>("location", "country-region-zone"))), + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), + new SimpleEntry<>( + ResourceAttributes.K8S_NAMESPACE_NAME, "non-cloud-namespace-name"), + new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "non-cloud-pod-name")), + "k8s_pod", + Map.ofEntries( + new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), + new SimpleEntry<>("pod_name", "non-cloud-pod-name"), + new SimpleEntry<>("namespace_name", "non-cloud-namespace-name"), + new SimpleEntry<>("location", "country-region-zone"))), + // test cases for k8s_node on [GCP, AWS, Azure, non-cloud] + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + new SimpleEntry<>( + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NODE_NAME, "GKE-node-name")), + "k8s_node", + Map.ofEntries( + new SimpleEntry<>("location", "country-region-zone"), + new SimpleEntry<>("node_name", "GKE-node-name"), + new SimpleEntry<>("cluster_name", "GKE-cluster-name"))), generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( @@ -237,6 +250,34 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("cluster_name", "AKS-cluster-name"), new SimpleEntry<>("node_name", "AKS-node-name"), new SimpleEntry<>("location", "country-region-zone"))), + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), + new SimpleEntry<>(ResourceAttributes.K8S_NODE_NAME, "non-cloud-node-name")), + "k8s_node", + Map.ofEntries( + new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), + new SimpleEntry<>("node_name", "non-cloud-node-name"), + new SimpleEntry<>("location", "country-region-zone"))), + // test cases for k8s_cluster on [GCP, AWS, Azure, non-cloud] + generateOTelResourceMappingTestArgs( + Map.ofEntries( + new SimpleEntry<>( + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + new SimpleEntry<>( + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), + new SimpleEntry<>( + ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "GKE-cluster-name")), + "k8s_cluster", + Map.ofEntries( + new SimpleEntry<>("location", "country-region-zone"), + new SimpleEntry<>("cluster_name", "GKE-cluster-name"))), generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( @@ -246,16 +287,10 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc ResourceAttributes.CloudPlatformValues.AWS_EKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "EKS-cluster-name"), - new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "EKS-namespace-name"), - new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "EKS-pod-name"), - new SimpleEntry<>(ResourceAttributes.K8S_CONTAINER_NAME, "EKS-container-name")), - "k8s_container", + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "EKS-cluster-name")), + "k8s_cluster", Map.ofEntries( new SimpleEntry<>("cluster_name", "EKS-cluster-name"), - new SimpleEntry<>("namespace_name", "EKS-namespace-name"), - new SimpleEntry<>("pod_name", "EKS-pod-name"), - new SimpleEntry<>("container_name", "EKS-container-name"), new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( @@ -267,16 +302,10 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc ResourceAttributes.CloudPlatformValues.AZURE_AKS), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "AKS-cluster-name"), - new SimpleEntry<>(ResourceAttributes.K8S_NAMESPACE_NAME, "AKS-namespace-name"), - new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "AKS-pod-name"), - new SimpleEntry<>(ResourceAttributes.K8S_CONTAINER_NAME, "AKS-container-name")), - "k8s_container", + new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "AKS-cluster-name")), + "k8s_cluster", Map.ofEntries( new SimpleEntry<>("cluster_name", "AKS-cluster-name"), - new SimpleEntry<>("namespace_name", "AKS-namespace-name"), - new SimpleEntry<>("pod_name", "AKS-pod-name"), - new SimpleEntry<>("container_name", "AKS-container-name"), new SimpleEntry<>("location", "country-region-zone"))), generateOTelResourceMappingTestArgs( Map.ofEntries( @@ -287,52 +316,30 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc Map.ofEntries( new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), new SimpleEntry<>("location", "country-region-zone"))), + // test case for GCE Instance generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), - new SimpleEntry<>( - ResourceAttributes.K8S_NAMESPACE_NAME, "non-cloud-namespace-name"), - new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "non-cloud-pod-name")), - "k8s_pod", - Map.ofEntries( - new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), - new SimpleEntry<>("pod_name", "non-cloud-pod-name"), - new SimpleEntry<>("namespace_name", "non-cloud-namespace-name"), - new SimpleEntry<>("location", "country-region-zone"))), - generateOTelResourceMappingTestArgs( - Map.ofEntries( + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), new SimpleEntry<>( - ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), - new SimpleEntry<>(ResourceAttributes.K8S_NODE_NAME, "non-cloud-node-name")), - "k8s_node", - Map.ofEntries( - new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), - new SimpleEntry<>("node_name", "non-cloud-node-name"), - new SimpleEntry<>("location", "country-region-zone"))), - generateOTelResourceMappingTestArgs( - Map.ofEntries( + ResourceAttributes.CLOUD_PLATFORM, + ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE), + new SimpleEntry<>(ResourceAttributes.CLOUD_ACCOUNT_ID, "GCE-pid"), new SimpleEntry<>( ResourceAttributes.CLOUD_AVAILABILITY_ZONE, "country-region-zone"), - new SimpleEntry<>(ResourceAttributes.K8S_CLUSTER_NAME, "non-cloud-cluster-name"), - new SimpleEntry<>( - ResourceAttributes.K8S_NAMESPACE_NAME, "non-cloud-namespace-name"), - new SimpleEntry<>(ResourceAttributes.K8S_POD_NAME, "non-cloud-pod-name"), - new SimpleEntry<>( - ResourceAttributes.K8S_CONTAINER_NAME, "non-cloud-container-name")), - "k8s_container", + new SimpleEntry<>(ResourceAttributes.CLOUD_REGION, "country-region"), + new SimpleEntry<>(ResourceAttributes.HOST_ID, "GCE-instance-id"), + new SimpleEntry<>(ResourceAttributes.HOST_NAME, "GCE-instance-name"), + new SimpleEntry<>(ResourceAttributes.HOST_TYPE, "GCE-instance-type")), + "gce_instance", Map.ofEntries( - new SimpleEntry<>("cluster_name", "non-cloud-cluster-name"), - new SimpleEntry<>("namespace_name", "non-cloud-namespace-name"), - new SimpleEntry<>("pod_name", "non-cloud-pod-name"), - new SimpleEntry<>("container_name", "non-cloud-container-name"), - new SimpleEntry<>("location", "country-region-zone"))), + new SimpleEntry<>("instance_id", "GCE-instance-id"), + new SimpleEntry<>("zone", "country-region-zone"))), + // test case for EC2 Instance generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>( - ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.GCP), + ResourceAttributes.CLOUD_PROVIDER, ResourceAttributes.CloudProviderValues.AWS), new SimpleEntry<>( ResourceAttributes.CLOUD_PLATFORM, ResourceAttributes.CloudPlatformValues.AWS_EC2), @@ -346,6 +353,7 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("region", "country-region-zone"), new SimpleEntry<>("instance_id", "aws-instance-id"), new SimpleEntry<>("aws_account", "aws-id"))), + // test cases for generic_task generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>(ResourceAttributes.SERVICE_NAME, "my-service-prevailed"), @@ -392,6 +400,7 @@ private static Stream provideOTelResourceAttributesToMonitoredResourc new SimpleEntry<>("namespace", "prod"), new SimpleEntry<>("task_id", "1234"), new SimpleEntry<>("location", "global"))), + // test cases for generic_node generateOTelResourceMappingTestArgs( Map.ofEntries( new SimpleEntry<>(ResourceAttributes.SERVICE_NAME, "unknown_service"),