Skip to content

Commit

Permalink
Add missing attribute in GKE mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed Jan 8, 2024
1 parent 249d2d7 commit f4577d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private void addGKEAttributes(AttributesBuilder attrBuilder, Map<String, String>
Optional.ofNullable(attributesMap.get(GKE_CLUSTER_NAME))
.ifPresent(
clusterName -> attrBuilder.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName));
Optional.ofNullable(attributesMap.get(GKE_HOST_ID))
.ifPresent(hostId -> attrBuilder.put(ResourceAttributes.HOST_ID, hostId));
Optional.ofNullable(attributesMap.get(GKE_CLUSTER_LOCATION_TYPE))
.ifPresent(
locationType -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.opentelemetry.detectors;

import static com.google.cloud.opentelemetry.detectors.AttributeKeys.*;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class GCPResourceProviderTest {
put(GKE_NAMESPACE, "gke-namespace-default");
put(GKE_CONTAINER_NAME, "gke-container-2");
put(GKE_CLUSTER_NAME, "gke-cluster");
put(GKE_HOST_ID, "host1");
}
};

Expand Down Expand Up @@ -174,6 +176,7 @@ public void testGCEResourceAttributesMapping() {
assertEquals(
mockPlatform.getAttributes().get(GCE_CLOUD_REGION),
gotResource.getAttributes().get(ResourceAttributes.CLOUD_REGION));
assertThat(gotResource.getAttributes()).hasSize(8);
}

@Test
Expand All @@ -189,6 +192,7 @@ public void testGKEResourceAttributesMapping_LocationTypeRegion() {
assertEquals(
mockPlatform.getAttributes().get(GKE_CLUSTER_LOCATION),
gotResource.getAttributes().get(ResourceAttributes.CLOUD_REGION));
assertThat(gotResource.getAttributes()).hasSize(8);
}

@Test
Expand All @@ -204,6 +208,7 @@ public void testGKEResourceAttributesMapping_LocationTypeZone() {
assertEquals(
mockPlatform.getAttributes().get(GKE_CLUSTER_LOCATION),
gotResource.getAttributes().get(ResourceAttributes.CLOUD_AVAILABILITY_ZONE));
assertThat(gotResource.getAttributes()).hasSize(8);
}

@Test
Expand All @@ -224,6 +229,7 @@ public void testGKEResourceAttributesMapping_LocationTypeInvalid() {
verifyGKEMapping(gotResource, mockPlatform);
assertNull(gotResource.getAttributes().get(ResourceAttributes.CLOUD_REGION));
assertNull(gotResource.getAttributes().get(ResourceAttributes.CLOUD_AVAILABILITY_ZONE));
assertThat(gotResource.getAttributes()).hasSize(7);
}

@Test
Expand All @@ -237,6 +243,7 @@ public void testGKEResourceAttributesMapping_LocationMissing() {
verifyGKEMapping(gotResource, mockPlatform);
assertNull(gotResource.getAttributes().get(ResourceAttributes.CLOUD_REGION));
assertNull(gotResource.getAttributes().get(ResourceAttributes.CLOUD_AVAILABILITY_ZONE));
assertThat(gotResource.getAttributes()).hasSize(7);
}

private void verifyGKEMapping(Resource gotResource, DetectedPlatform detectedPlatform) {
Expand All @@ -255,6 +262,12 @@ private void verifyGKEMapping(Resource gotResource, DetectedPlatform detectedPla
assertEquals(
detectedPlatform.getAttributes().get(GKE_CONTAINER_NAME),
gotResource.getAttributes().get(ResourceAttributes.K8S_CONTAINER_NAME));
assertEquals(
detectedPlatform.getAttributes().get(GKE_HOST_ID),
gotResource.getAttributes().get(ResourceAttributes.HOST_ID));
assertEquals(
detectedPlatform.getAttributes().get(GKE_CLUSTER_NAME),
gotResource.getAttributes().get(ResourceAttributes.K8S_CLUSTER_NAME));
}

@Test
Expand All @@ -269,6 +282,7 @@ public void testGCRResourceAttributesMapping() {
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_RUN,
gotResource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM));
verifyServerlessMapping(gotResource, mockPlatform);
assertThat(gotResource.getAttributes()).hasSize(7);
}

@Test
Expand All @@ -284,6 +298,7 @@ public void testGCFResourceAttributeMapping() {
ResourceAttributes.CloudPlatformValues.GCP_CLOUD_FUNCTIONS,
gotResource.getAttributes().get(ResourceAttributes.CLOUD_PLATFORM));
verifyServerlessMapping(gotResource, mockPlatform);
assertThat(gotResource.getAttributes()).hasSize(7);
}

private void verifyServerlessMapping(Resource gotResource, DetectedPlatform detectedPlatform) {
Expand Down Expand Up @@ -335,6 +350,7 @@ public void testGAEResourceAttributeMapping() {
assertEquals(
mockPlatform.getAttributes().get(GAE_CLOUD_REGION),
gotResource.getAttributes().get(ResourceAttributes.CLOUD_REGION));
assertThat(gotResource.getAttributes()).hasSize(7);
}

@Test
Expand Down

0 comments on commit f4577d0

Please sign in to comment.