|
16 | 16 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_ID; |
17 | 17 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_NAME; |
18 | 18 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_MACHINE_TYPE; |
| 19 | +import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCR_JOB_EXECUTION_KEY; |
| 20 | +import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCR_JOB_TASK_INDEX; |
19 | 21 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_LOCATION; |
20 | 22 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_LOCATION_TYPE; |
21 | 23 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_NAME; |
|
27 | 29 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.SERVERLESS_COMPUTE_INSTANCE_ID; |
28 | 30 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.SERVERLESS_COMPUTE_NAME; |
29 | 31 | import static com.google.cloud.opentelemetry.detection.AttributeKeys.SERVERLESS_COMPUTE_REVISION; |
| 32 | +import static io.opentelemetry.contrib.gcp.resource.IncubatingAttributes.GCP_CLOUD_RUN_JOB_TASK_INDEX; |
30 | 33 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
31 | 34 | import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_ACCOUNT_ID; |
32 | 35 | import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_AVAILABILITY_ZONE; |
|
42 | 45 | import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INSTANCE; |
43 | 46 | import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_NAME; |
44 | 47 | import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_VERSION; |
| 48 | +import static io.opentelemetry.semconv.incubating.GcpIncubatingAttributes.GCP_CLOUD_RUN_JOB_EXECUTION; |
45 | 49 | import static io.opentelemetry.semconv.incubating.GcpIncubatingAttributes.GCP_GCE_INSTANCE_HOSTNAME; |
46 | 50 | import static io.opentelemetry.semconv.incubating.GcpIncubatingAttributes.GCP_GCE_INSTANCE_NAME; |
47 | 51 | import static io.opentelemetry.semconv.incubating.HostIncubatingAttributes.HOST_ID; |
@@ -133,6 +137,23 @@ private static DetectedPlatform generateMockServerlessPlatform( |
133 | 137 | return mockServerlessPlatform; |
134 | 138 | } |
135 | 139 |
|
| 140 | + private static DetectedPlatform generateMockGcrJobPlatform() { |
| 141 | + Map<String, String> mockAttributes = |
| 142 | + new HashMap<>( |
| 143 | + ImmutableMap.of( |
| 144 | + SERVERLESS_COMPUTE_NAME, "serverless-job", |
| 145 | + SERVERLESS_COMPUTE_INSTANCE_ID, "serverless-instance-id", |
| 146 | + SERVERLESS_COMPUTE_CLOUD_REGION, "us-central1", |
| 147 | + GCR_JOB_TASK_INDEX, "1", |
| 148 | + GCR_JOB_EXECUTION_KEY, "serverless-job-a1b2c3")); |
| 149 | + DetectedPlatform mockServerlessPlatform = Mockito.mock(DetectedPlatform.class); |
| 150 | + Mockito.when(mockServerlessPlatform.getSupportedPlatform()) |
| 151 | + .thenReturn(GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_RUN_JOB); |
| 152 | + Mockito.when(mockServerlessPlatform.getAttributes()).thenReturn(mockAttributes); |
| 153 | + Mockito.when(mockServerlessPlatform.getProjectId()).thenReturn(DUMMY_PROJECT_ID); |
| 154 | + return mockServerlessPlatform; |
| 155 | + } |
| 156 | + |
136 | 157 | private static DetectedPlatform generateMockGaePlatform() { |
137 | 158 | Map<String, String> mockAttributes = |
138 | 159 | new HashMap<>( |
@@ -274,7 +295,7 @@ private static void verifyGkeMapping(Resource gotResource, DetectedPlatform dete |
274 | 295 | } |
275 | 296 |
|
276 | 297 | @Test |
277 | | - public void testGcrResourceAttributesMapping() { |
| 298 | + public void testGcrServiceResourceAttributesMapping() { |
278 | 299 | GCPPlatformDetector mockDetector = Mockito.mock(GCPPlatformDetector.class); |
279 | 300 | DetectedPlatform mockPlatform = |
280 | 301 | generateMockServerlessPlatform(GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_RUN); |
@@ -321,6 +342,31 @@ private static void verifyServerlessMapping( |
321 | 342 | .containsEntry(CLOUD_REGION, detectedAttributes.get(SERVERLESS_COMPUTE_CLOUD_REGION)); |
322 | 343 | } |
323 | 344 |
|
| 345 | + @Test |
| 346 | + public void testGcrJobResourceAttributesMapping() { |
| 347 | + GCPPlatformDetector mockDetector = Mockito.mock(GCPPlatformDetector.class); |
| 348 | + DetectedPlatform mockPlatform = generateMockGcrJobPlatform(); |
| 349 | + Mockito.when(mockDetector.detectPlatform()).thenReturn(mockPlatform); |
| 350 | + Map<String, String> detectedAttributes = mockPlatform.getAttributes(); |
| 351 | + |
| 352 | + Resource gotResource = new GCPResourceProvider(mockDetector).createResource(mockConfigProps); |
| 353 | + verify(mockPlatform, Mockito.times(1)).getProjectId(); |
| 354 | + |
| 355 | + assertThat(gotResource.getAttributes()) |
| 356 | + .hasSize(8) |
| 357 | + .containsEntry(CLOUD_PROVIDER, GCP) |
| 358 | + .containsEntry(CLOUD_PLATFORM, GCP_CLOUD_RUN) |
| 359 | + .containsEntry(CLOUD_ACCOUNT_ID, DUMMY_PROJECT_ID) |
| 360 | + .containsEntry(FAAS_NAME, detectedAttributes.get(SERVERLESS_COMPUTE_NAME)) |
| 361 | + .containsEntry(FAAS_NAME, detectedAttributes.get(SERVERLESS_COMPUTE_NAME)) |
| 362 | + .containsEntry(FAAS_INSTANCE, detectedAttributes.get(SERVERLESS_COMPUTE_INSTANCE_ID)) |
| 363 | + .containsEntry(GCP_CLOUD_RUN_JOB_EXECUTION, detectedAttributes.get(GCR_JOB_EXECUTION_KEY)) |
| 364 | + .containsEntry( |
| 365 | + GCP_CLOUD_RUN_JOB_TASK_INDEX, |
| 366 | + Integer.parseInt(detectedAttributes.get(GCR_JOB_TASK_INDEX))) |
| 367 | + .containsEntry(CLOUD_REGION, detectedAttributes.get(SERVERLESS_COMPUTE_CLOUD_REGION)); |
| 368 | + } |
| 369 | + |
324 | 370 | @Test |
325 | 371 | public void testGaeResourceAttributeMapping() { |
326 | 372 | GCPPlatformDetector mockDetector = Mockito.mock(GCPPlatformDetector.class); |
|
0 commit comments