From 5e3e396413cae4657a7cc8fd5b4665701d04acc4 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 7 May 2026 20:54:28 +0000 Subject: [PATCH 1/3] Udpate dependencies --- build.gradle | 14 +++++++------- .../endtoend/ScenarioHandlerManager.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index fc307294..5c02f06e 100644 --- a/build.gradle +++ b/build.gradle @@ -162,14 +162,14 @@ subprojects { googleAuthVersion = '1.27.0' googleCloudVersion = '2.44.1' googleTraceVersion = '2.51.0' - googleCloudBomVersion = '26.48.0' + googleCloudBomVersion = '26.80.0' cloudMonitoringVersion = '3.52.0' - openTelemetryBomVersion = '1.49.0' - openTelemetryVersion = '1.49.0' - openTelemetryInstrumentationBomVersion = '2.15.0' - openTelemetryInstrumentationVersion = '2.15.0' - openTelemetrySemconvVersion = '1.32.0' - openTelemetryContribVersion = '1.46.0' + openTelemetryBomVersion = '1.61.0' + openTelemetryVersion = '1.61.0' + openTelemetryInstrumentationBomVersion = '2.27.0' + openTelemetryInstrumentationVersion = '2.27.0' + openTelemetrySemconvVersion = '1.41.0' + openTelemetryContribVersion = '1.56.0' junitVersion = '4.13' junit5Version = '5.10.0' mockitoVersion = '5.2.0' diff --git a/e2e-test-server/src/main/java/com/google/cloud/opentelemetry/endtoend/ScenarioHandlerManager.java b/e2e-test-server/src/main/java/com/google/cloud/opentelemetry/endtoend/ScenarioHandlerManager.java index 1e9fd912..8175c2cb 100644 --- a/e2e-test-server/src/main/java/com/google/cloud/opentelemetry/endtoend/ScenarioHandlerManager.java +++ b/e2e-test-server/src/main/java/com/google/cloud/opentelemetry/endtoend/ScenarioHandlerManager.java @@ -91,7 +91,7 @@ private Response detectResource(Request request) { Resource gcpResource = new GCPResourceProvider() .createResource( - DefaultConfigProperties.create( + DefaultConfigProperties.createFromMap( Map.of("otel.traces.exporter", "none", "otel.metrics.exporter", "none"))); Resource resource = Resource.getDefault() From 85f8dbae7ce3f32950e8b3cb7bb15a8cccb46233 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 7 May 2026 21:01:37 +0000 Subject: [PATCH 2/3] Remove detector-resources-support --- detectors/resources-support/README.md | 14 - detectors/resources-support/build.gradle | 30 -- detectors/resources-support/gradle.properties | 1 - .../detection/AttributeKeys.java | 64 --- .../detection/DetectedPlatform.java | 46 -- .../detection/EnvironmentVariables.java | 33 -- .../detection/GCPMetadataConfig.java | 168 ------- .../detection/GCPPlatformDetector.java | 115 ----- .../detection/GoogleAppEngine.java | 72 --- .../detection/GoogleCloudFunction.java | 27 -- .../detection/GoogleCloudRun.java | 27 -- .../detection/GoogleCloudRunJob.java | 58 --- .../detection/GoogleComputeEngine.java | 63 --- .../detection/GoogleKubernetesEngine.java | 75 ---- .../detection/GoogleServerlessCompute.java | 57 --- .../detection/UnknownPlatform.java | 39 -- .../opentelemetry/detection/EnvVarMock.java | 31 -- .../detection/GCPMetadataConfigTest.java | 151 ------- .../detection/GCPPlatformDetectorTest.java | 413 ------------------ .../opentelemetry/detection/TestUtils.java | 31 -- settings.gradle | 4 - 21 files changed, 1519 deletions(-) delete mode 100644 detectors/resources-support/README.md delete mode 100644 detectors/resources-support/build.gradle delete mode 100644 detectors/resources-support/gradle.properties delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/AttributeKeys.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/DetectedPlatform.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/EnvironmentVariables.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetector.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleAppEngine.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudFunction.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRun.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRunJob.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleComputeEngine.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleKubernetesEngine.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleServerlessCompute.java delete mode 100644 detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/UnknownPlatform.java delete mode 100644 detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/EnvVarMock.java delete mode 100644 detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfigTest.java delete mode 100644 detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetectorTest.java delete mode 100644 detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/TestUtils.java diff --git a/detectors/resources-support/README.md b/detectors/resources-support/README.md deleted file mode 100644 index d1ac8f89..00000000 --- a/detectors/resources-support/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# GCP Resource Detection Support Library - -[![Maven Central][maven-image]][maven-url] - -This library provides detection support for supported GCP environments and is intended to be consumed by the [GCP OpenTelemetry Detector](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/eece7e8ef04170fb463ddf692f61d4527b50febf/gcp-resources). -The GCP environments supported by this library are - -1. [Google Compute Engine](https://cloud.google.com/compute?hl=en) -2. [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine?hl=en) -3. [Google App Engine](https://cloud.google.com/appengine?hl=en) -4. [Google Cloud Functions](https://cloud.google.com/functions?hl=en) -5. [Google Cloud Run](https://cloud.google.com/run?hl=en) - -[maven-image]: https://img.shields.io/maven-central/v/com.google.cloud.opentelemetry/detector-resources-support?color=dark-green -[maven-url]: https://central.sonatype.com/artifact/com.google.cloud.opentelemetry/detector-resources-support diff --git a/detectors/resources-support/build.gradle b/detectors/resources-support/build.gradle deleted file mode 100644 index 29737c2a..00000000 --- a/detectors/resources-support/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -description = 'Support library for Google Cloud Resource Detector' - -dependencies { - testImplementation(testLibraries.assertj) - testImplementation(testLibraries.wiremock) - testImplementation(testLibraries.mockito) - testImplementation(testLibraries.junit5) - testImplementation(testLibraries.junit5_params) - testRuntimeOnly(testLibraries.junit5_runtime) -} - -test { - // required for discovering JUnit 5 tests - useJUnitPlatform() -} diff --git a/detectors/resources-support/gradle.properties b/detectors/resources-support/gradle.properties deleted file mode 100644 index 2f3d80be..00000000 --- a/detectors/resources-support/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -release.enabled=true diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/AttributeKeys.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/AttributeKeys.java deleted file mode 100644 index 3ea75c40..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/AttributeKeys.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -/** - * Contains constants that act as keys for the known attributes for {@link - * GCPPlatformDetector.SupportedPlatform}s. - */ -public final class AttributeKeys { - // GCE Attributes - public static final String GCE_AVAILABILITY_ZONE = AttributeKeys.AVAILABILITY_ZONE; - public static final String GCE_CLOUD_REGION = AttributeKeys.CLOUD_REGION; - public static final String GCE_INSTANCE_ID = AttributeKeys.INSTANCE_ID; - public static final String GCE_INSTANCE_NAME = AttributeKeys.INSTANCE_NAME; - public static final String GCE_MACHINE_TYPE = AttributeKeys.MACHINE_TYPE; - public static final String GCE_INSTANCE_HOSTNAME = "instance_hostname"; - - // GKE Attributes - public static final String GKE_CLUSTER_NAME = "gke_cluster_name"; - public static final String GKE_CLUSTER_LOCATION_TYPE = "gke_cluster_location_type"; - public static final String GKE_CLUSTER_LOCATION = "gke_cluster_location"; - public static final String GKE_HOST_ID = AttributeKeys.INSTANCE_ID; - - // GKE Location Constants - public static final String GKE_LOCATION_TYPE_ZONE = "ZONE"; - public static final String GKE_LOCATION_TYPE_REGION = "REGION"; - - // GAE Attributes - public static final String GAE_MODULE_NAME = "gae_module_name"; - public static final String GAE_APP_VERSION = "gae_app_version"; - public static final String GAE_INSTANCE_ID = AttributeKeys.INSTANCE_ID; - public static final String GAE_AVAILABILITY_ZONE = AttributeKeys.AVAILABILITY_ZONE; - public static final String GAE_CLOUD_REGION = AttributeKeys.CLOUD_REGION; - - // Google Serverless Compute Attributes - public static final String SERVERLESS_COMPUTE_NAME = "serverless_compute_name"; - public static final String SERVERLESS_COMPUTE_REVISION = "serverless_compute_revision"; - public static final String SERVERLESS_COMPUTE_AVAILABILITY_ZONE = AttributeKeys.AVAILABILITY_ZONE; - public static final String SERVERLESS_COMPUTE_CLOUD_REGION = AttributeKeys.CLOUD_REGION; - public static final String SERVERLESS_COMPUTE_INSTANCE_ID = AttributeKeys.INSTANCE_ID; - - // Cloud Run Job Specific Attributes - public static final String GCR_JOB_EXECUTION_KEY = "gcr_job_execution_key"; - public static final String GCR_JOB_TASK_INDEX = "gcr_job_task_index"; - - static final String AVAILABILITY_ZONE = "availability_zone"; - static final String CLOUD_REGION = "cloud_region"; - static final String INSTANCE_ID = "instance_id"; - static final String INSTANCE_NAME = "instance_name"; - static final String MACHINE_TYPE = "machine_type"; -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/DetectedPlatform.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/DetectedPlatform.java deleted file mode 100644 index 019927e3..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/DetectedPlatform.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import java.util.Map; - -/** Represents a GCP specific platform on which a cloud application can run. */ -public interface DetectedPlatform { - /** - * Method to retrieve the underlying compute platform on which application is running. - * - * @return the {@link GCPPlatformDetector.SupportedPlatform} representing the Google Cloud - * platform on which application is running. - */ - GCPPlatformDetector.SupportedPlatform getSupportedPlatform(); - - /** - * Method to retrieve the GCP Project ID in which the GCP specific platform exists. Every valid - * platform must have a GCP Project ID associated with it. - * - * @return the Google Cloud project ID. - */ - String getProjectId(); - - /** - * Method to retrieve the attributes associated with the compute platform on which the application - * is running as key-value pairs. The valid keys to query on this {@link Map} are specified in the - * {@link AttributeKeys}. - * - * @return a {@link Map} of attributes specific to the underlying compute platform. - */ - Map getAttributes(); -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/EnvironmentVariables.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/EnvironmentVariables.java deleted file mode 100644 index e5d643e9..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/EnvironmentVariables.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -/** - * Provides API to fetch environment variables. This is useful in order to create a mock class for - * testing. - */ -interface EnvironmentVariables { - /** Returns the current environment variables of the platform this is running in. */ - EnvironmentVariables DEFAULT_INSTANCE = System::getenv; - - /** - * Grabs the system environment variable. Returns null on failure. - * - * @param key the key of the environment variable in {@code System.getenv()} - * @return the value received by {@code System.getenv(key)} - */ - String get(String key); -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java deleted file mode 100644 index a11384b5..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfig.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Retrieves Google Cloud project-id and a limited set of instance attributes from Metadata server. - * - * @see - * https://cloud.google.com/compute/docs/storing-retrieving-metadata - */ -final class GCPMetadataConfig { - static final GCPMetadataConfig DEFAULT_INSTANCE = new GCPMetadataConfig(); - - private static final String DEFAULT_URL = "http://metadata.google.internal/computeMetadata/v1/"; - private final String url; - private final Map cachedAttributes = new ConcurrentHashMap<>(); - - private GCPMetadataConfig() { - this.url = DEFAULT_URL; - } - - // For testing only - GCPMetadataConfig(String url) { - this.url = url; - } - - // Returns null on failure to retrieve from metadata server - String getProjectId() { - return getAttribute("project/project-id"); - } - - /** - * Method to extract cloud availability zone from the metadata server. - * - *

Example response: projects/640212054955/zones/australia-southeast1-a - * - *

Example zone: australia-southeast1-a - * - * @return the extracted zone from the metadata server response or null in case of failure to - * retrieve from metadata server. - */ - String getZone() { - String zone = getAttribute("instance/zone"); - if (zone != null && zone.contains("/")) { - zone = zone.substring(zone.lastIndexOf('/') + 1); - } - return zone; - } - - /** - * Use this method only when the region cannot be parsed from the zone. Known use-cases of this - * method involve detecting region in GAE standard environment. - * - *

Example response: projects/5689182099321/regions/us-central1. - * - * @return the retrieved region or null in case of failure to retrieve from metadata server - */ - String getRegion() { - String region = getAttribute("instance/region"); - if (region != null && region.contains("/")) { - region = region.substring(region.lastIndexOf('/') + 1); - } - return region; - } - - /** - * Use this method to parse region from zone. - * - *

Example region: australia-southeast1 - * - * @return parsed region from the zone, if zone is not found or is invalid, this method returns - * null. - */ - String getRegionFromZone() { - String region = null; - String zone = getZone(); - if (zone != null && !zone.isEmpty()) { - // Parsing required to scope up to a region - String[] splitArr = zone.split("-"); - if (splitArr.length > 2) { - region = String.join("-", splitArr[0], splitArr[1]); - } - } - return region; - } - - // Example response: projects/640212054955/machineTypes/e2-medium - String getMachineType() { - String machineType = getAttribute("instance/machine-type"); - if (machineType != null && machineType.contains("/")) { - machineType = machineType.substring(machineType.lastIndexOf('/') + 1); - } - return machineType; - } - - // Returns null on failure to retrieve from metadata server - String getInstanceId() { - return getAttribute("instance/id"); - } - - // Returns null on failure to retrieve from metadata server - String getClusterName() { - return getAttribute("instance/attributes/cluster-name"); - } - - // Returns null on failure to retrieve from metadata server - String getClusterLocation() { - return getAttribute("instance/attributes/cluster-location"); - } - - // Returns null on failure to retrieve from metadata server - String getInstanceHostName() { - return getAttribute("instance/hostname"); - } - - // Returns null on failure to retrieve from metadata server - String getInstanceName() { - return getAttribute("instance/name"); - } - - // Returns null on failure to retrieve from metadata server - private String getAttribute(String attributeName) { - return cachedAttributes.computeIfAbsent(attributeName, this::fetchAttribute); - } - - // Return the attribute received at relative path or null on failure - private String fetchAttribute(String attributeName) { - try { - URL url = new URL(this.url + attributeName); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestProperty("Metadata-Flavor", "Google"); - if (connection.getResponseCode() == 200 - && ("Google").equals(connection.getHeaderField("Metadata-Flavor"))) { - InputStream input = connection.getInputStream(); - try (BufferedReader reader = - new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { - return reader.readLine(); - } - } - } catch (IOException ignore) { - // ignore - } - return null; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetector.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetector.java deleted file mode 100644 index 78e10820..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetector.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -public class GCPPlatformDetector { - public static final GCPPlatformDetector DEFAULT_INSTANCE = new GCPPlatformDetector(); - - private final GCPMetadataConfig metadataConfig; - private final EnvironmentVariables environmentVariables; - - // for testing only - GCPPlatformDetector(GCPMetadataConfig metadataConfig, EnvironmentVariables environmentVariables) { - this.metadataConfig = metadataConfig; - this.environmentVariables = environmentVariables; - } - - private GCPPlatformDetector() { - this.metadataConfig = GCPMetadataConfig.DEFAULT_INSTANCE; - this.environmentVariables = EnvironmentVariables.DEFAULT_INSTANCE; - } - - /** - * Detects the GCP platform on which the application is running. - * - * @return the specific GCP platform on which the application is running. - */ - public DetectedPlatform detectPlatform() { - return generateDetectedPlatform(detectSupportedPlatform()); - } - - private SupportedPlatform detectSupportedPlatform() { - if (!isRunningOnGcp()) { - return SupportedPlatform.UNKNOWN_PLATFORM; - } - // Note: Order of detection matters here - if (environmentVariables.get("KUBERNETES_SERVICE_HOST") != null) { - return SupportedPlatform.GOOGLE_KUBERNETES_ENGINE; - } else if (environmentVariables.get("K_CONFIGURATION") != null - && environmentVariables.get("FUNCTION_TARGET") == null) { - return SupportedPlatform.GOOGLE_CLOUD_RUN; - } else if (environmentVariables.get("FUNCTION_TARGET") != null) { - return SupportedPlatform.GOOGLE_CLOUD_FUNCTIONS; - } else if (environmentVariables.get("CLOUD_RUN_JOB") != null) { - return SupportedPlatform.GOOGLE_CLOUD_RUN_JOB; - } else if (environmentVariables.get("GAE_SERVICE") != null) { - return SupportedPlatform.GOOGLE_APP_ENGINE; - } - return SupportedPlatform.GOOGLE_COMPUTE_ENGINE; // default to GCE - } - - private boolean isRunningOnGcp() { - return metadataConfig.getProjectId() != null && !metadataConfig.getProjectId().isEmpty(); - } - - private DetectedPlatform generateDetectedPlatform(SupportedPlatform platform) { - DetectedPlatform detectedPlatform; - switch (platform) { - case GOOGLE_KUBERNETES_ENGINE: - detectedPlatform = new GoogleKubernetesEngine(metadataConfig); - break; - case GOOGLE_CLOUD_RUN: - detectedPlatform = new GoogleCloudRun(environmentVariables, metadataConfig); - break; - case GOOGLE_CLOUD_FUNCTIONS: - detectedPlatform = new GoogleCloudFunction(environmentVariables, metadataConfig); - break; - case GOOGLE_CLOUD_RUN_JOB: - detectedPlatform = new GoogleCloudRunJob(environmentVariables, metadataConfig); - break; - case GOOGLE_APP_ENGINE: - detectedPlatform = new GoogleAppEngine(environmentVariables, metadataConfig); - break; - case GOOGLE_COMPUTE_ENGINE: - detectedPlatform = new GoogleComputeEngine(metadataConfig); - break; - default: - detectedPlatform = new UnknownPlatform(); - } - return detectedPlatform; - } - - /** - * SupportedPlatform represents the GCP platforms that can currently be detected by the - * resource-detector. - */ - public enum SupportedPlatform { - /** Represents the Google Compute Engine platform. */ - GOOGLE_COMPUTE_ENGINE, - /** Represents the Google Kubernetes Engine platform. */ - GOOGLE_KUBERNETES_ENGINE, - /** Represents the Google App Engine platform. Could either be flex or standard. */ - GOOGLE_APP_ENGINE, - /** Represents the Google Cloud Run platform (Service). */ - GOOGLE_CLOUD_RUN, - /** Represents the Google Cloud Run platform (Jobs). */ - GOOGLE_CLOUD_RUN_JOB, - /** Represents the Google Cloud Functions platform. */ - GOOGLE_CLOUD_FUNCTIONS, - /** Represents the case when the application is not running on GCP. */ - UNKNOWN_PLATFORM, - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleAppEngine.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleAppEngine.java deleted file mode 100644 index 64335263..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleAppEngine.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GAE_APP_VERSION; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GAE_AVAILABILITY_ZONE; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GAE_CLOUD_REGION; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GAE_INSTANCE_ID; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GAE_MODULE_NAME; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -final class GoogleAppEngine implements DetectedPlatform { - private final EnvironmentVariables environmentVariables; - private final GCPMetadataConfig metadataConfig; - private final Map availableAttributes; - - GoogleAppEngine(EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) { - this.environmentVariables = environmentVariables; - this.metadataConfig = metadataConfig; - this.availableAttributes = prepareAttributes(); - } - - private Map prepareAttributes() { - Map map = new HashMap<>(); - map.put(GAE_MODULE_NAME, this.environmentVariables.get("GAE_SERVICE")); - map.put(GAE_APP_VERSION, this.environmentVariables.get("GAE_VERSION")); - map.put(GAE_INSTANCE_ID, this.environmentVariables.get("GAE_INSTANCE")); - map.put(GAE_AVAILABILITY_ZONE, this.metadataConfig.getZone()); - map.put(GAE_CLOUD_REGION, getCloudRegion()); - return Collections.unmodifiableMap(map); - } - - private String getCloudRegion() { - if (this.environmentVariables.get("GAE_ENV") != null - && this.environmentVariables.get("GAE_ENV").equals("standard")) { - return this.metadataConfig.getRegion(); - } else { - return this.metadataConfig.getRegionFromZone(); - } - } - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.GOOGLE_APP_ENGINE; - } - - @Override - public String getProjectId() { - return this.metadataConfig.getProjectId(); - } - - @Override - public Map getAttributes() { - return this.availableAttributes; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudFunction.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudFunction.java deleted file mode 100644 index e31df554..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudFunction.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -class GoogleCloudFunction extends GoogleServerlessCompute { - GoogleCloudFunction(EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) { - super(environmentVariables, metadataConfig); - } - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_FUNCTIONS; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRun.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRun.java deleted file mode 100644 index e7988366..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRun.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -class GoogleCloudRun extends GoogleServerlessCompute { - GoogleCloudRun(EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) { - super(environmentVariables, metadataConfig); - } - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_RUN; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRunJob.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRunJob.java deleted file mode 100644 index 08f6a4a7..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleCloudRunJob.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import java.util.HashMap; -import java.util.Map; - -final class GoogleCloudRunJob implements DetectedPlatform { - private final GCPMetadataConfig metadataConfig; - private final EnvironmentVariables environmentVariables; - private final Map availableAttributes; - - GoogleCloudRunJob(EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) { - this.metadataConfig = metadataConfig; - this.environmentVariables = environmentVariables; - this.availableAttributes = prepareAttributes(); - } - - private Map prepareAttributes() { - Map map = new HashMap<>(); - map.put(AttributeKeys.SERVERLESS_COMPUTE_NAME, this.environmentVariables.get("CLOUD_RUN_JOB")); - map.put( - AttributeKeys.GCR_JOB_EXECUTION_KEY, this.environmentVariables.get("CLOUD_RUN_EXECUTION")); - map.put( - AttributeKeys.GCR_JOB_TASK_INDEX, this.environmentVariables.get("CLOUD_RUN_TASK_INDEX")); - map.put(AttributeKeys.SERVERLESS_COMPUTE_INSTANCE_ID, this.metadataConfig.getInstanceId()); - map.put(AttributeKeys.SERVERLESS_COMPUTE_CLOUD_REGION, this.metadataConfig.getRegionFromZone()); - return map; - } - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_RUN_JOB; - } - - @Override - public String getProjectId() { - return metadataConfig.getProjectId(); - } - - @Override - public Map getAttributes() { - return this.availableAttributes; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleComputeEngine.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleComputeEngine.java deleted file mode 100644 index 18bceaef..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleComputeEngine.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_AVAILABILITY_ZONE; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_CLOUD_REGION; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_HOSTNAME; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_ID; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_INSTANCE_NAME; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GCE_MACHINE_TYPE; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -final class GoogleComputeEngine implements DetectedPlatform { - private final GCPMetadataConfig metadataConfig; - private final Map availableAttributes; - - GoogleComputeEngine(GCPMetadataConfig metadataConfig) { - this.metadataConfig = metadataConfig; - this.availableAttributes = prepareAttributes(); - } - - private Map prepareAttributes() { - Map map = new HashMap<>(); - map.put(GCE_AVAILABILITY_ZONE, this.metadataConfig.getZone()); - map.put(GCE_CLOUD_REGION, this.metadataConfig.getRegionFromZone()); - map.put(GCE_INSTANCE_ID, this.metadataConfig.getInstanceId()); - map.put(GCE_INSTANCE_NAME, this.metadataConfig.getInstanceName()); - map.put(GCE_INSTANCE_HOSTNAME, this.metadataConfig.getInstanceHostName()); - map.put(GCE_MACHINE_TYPE, this.metadataConfig.getMachineType()); - return Collections.unmodifiableMap(map); - } - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.GOOGLE_COMPUTE_ENGINE; - } - - @Override - public String getProjectId() { - return this.metadataConfig.getProjectId(); - } - - @Override - public Map getAttributes() { - return this.availableAttributes; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleKubernetesEngine.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleKubernetesEngine.java deleted file mode 100644 index c632623b..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleKubernetesEngine.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_LOCATION; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_LOCATION_TYPE; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_CLUSTER_NAME; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_HOST_ID; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_LOCATION_TYPE_REGION; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.GKE_LOCATION_TYPE_ZONE; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -final class GoogleKubernetesEngine implements DetectedPlatform { - private final GCPMetadataConfig metadataConfig; - private final Map availableAttributes; - - GoogleKubernetesEngine(GCPMetadataConfig metadataConfig) { - this.metadataConfig = metadataConfig; - this.availableAttributes = prepareAttributes(); - } - - private Map prepareAttributes() { - Map map = new HashMap<>(); - map.put(GKE_CLUSTER_NAME, this.metadataConfig.getClusterName()); - map.put(GKE_CLUSTER_LOCATION, this.metadataConfig.getClusterLocation()); - map.put(GKE_CLUSTER_LOCATION_TYPE, this.getClusterLocationType()); - map.put(GKE_HOST_ID, this.metadataConfig.getInstanceId()); - return Collections.unmodifiableMap(map); - } - - private String getClusterLocationType() { - String clusterLocation = this.metadataConfig.getClusterLocation(); - long dashCount = - (clusterLocation == null || clusterLocation.isEmpty()) - ? 0 - : clusterLocation.chars().filter(ch -> ch == '-').count(); - if (dashCount == 1) { - return GKE_LOCATION_TYPE_REGION; - } else if (dashCount == 2) { - return GKE_LOCATION_TYPE_ZONE; - } - return ""; - } - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE; - } - - @Override - public String getProjectId() { - return this.metadataConfig.getProjectId(); - } - - @Override - public Map getAttributes() { - return this.availableAttributes; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleServerlessCompute.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleServerlessCompute.java deleted file mode 100644 index b2fbc6f2..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/GoogleServerlessCompute.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * GoogleServerlessCompute adds attributes applicable to all serverless compute platforms in GCP. - * Currently, this includes Google Cloud Functions & Google Cloud Run. - */ -abstract class GoogleServerlessCompute implements DetectedPlatform { - private final EnvironmentVariables environmentVariables; - private final GCPMetadataConfig metadataConfig; - private final Map availableAttributes; - - GoogleServerlessCompute( - EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) { - this.environmentVariables = environmentVariables; - this.metadataConfig = metadataConfig; - this.availableAttributes = prepareAttributes(); - } - - private Map prepareAttributes() { - Map map = new HashMap<>(); - map.put(AttributeKeys.SERVERLESS_COMPUTE_NAME, this.environmentVariables.get("K_SERVICE")); - map.put(AttributeKeys.SERVERLESS_COMPUTE_REVISION, this.environmentVariables.get("K_REVISION")); - map.put(AttributeKeys.SERVERLESS_COMPUTE_AVAILABILITY_ZONE, this.metadataConfig.getZone()); - map.put(AttributeKeys.SERVERLESS_COMPUTE_CLOUD_REGION, this.metadataConfig.getRegionFromZone()); - map.put(AttributeKeys.SERVERLESS_COMPUTE_INSTANCE_ID, this.metadataConfig.getInstanceId()); - return Collections.unmodifiableMap(map); - } - - @Override - public String getProjectId() { - return this.metadataConfig.getProjectId(); - } - - @Override - public Map getAttributes() { - return this.availableAttributes; - } -} diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/UnknownPlatform.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/UnknownPlatform.java deleted file mode 100644 index 7de1bff5..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detection/UnknownPlatform.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import java.util.Collections; -import java.util.Map; - -class UnknownPlatform implements DetectedPlatform { - - UnknownPlatform() {} - - @Override - public GCPPlatformDetector.SupportedPlatform getSupportedPlatform() { - return GCPPlatformDetector.SupportedPlatform.UNKNOWN_PLATFORM; - } - - @Override - public String getProjectId() { - return ""; - } - - @Override - public Map getAttributes() { - return Collections.emptyMap(); - } -} diff --git a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/EnvVarMock.java b/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/EnvVarMock.java deleted file mode 100644 index 2806948a..00000000 --- a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/EnvVarMock.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import java.util.Map; - -class EnvVarMock implements EnvironmentVariables { - private final Map mock; - - public EnvVarMock(Map mock) { - this.mock = mock; - } - - @Override - public String get(String key) { - return mock.get(key); - } -} diff --git a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfigTest.java b/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfigTest.java deleted file mode 100644 index 4d1f3ab7..00000000 --- a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPMetadataConfigTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.junit5.WireMockTest; -import java.util.stream.Stream; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -@WireMockTest(httpPort = 8090) -class GCPMetadataConfigTest { - private static final String mockProjectId = "pid"; - private static final String mockZone = "country-region-zone"; - private static final String mockRegion = "country-region1"; - private static final String mockInstanceId = "instance-id"; - private static final String mockInstanceName = "instance-name"; - private static final String mockInstanceType = "instance-type"; - private static final String mockClusterName = "cluster-name"; - private static final String mockClusterLocation = "cluster-location"; - private static final String mockHostname = "hostname"; - - private final GCPMetadataConfig mockMetadataConfig = - new GCPMetadataConfig("http://localhost:8090/"); - - @BeforeEach - public void setupMockMetadataConfig() { - TestUtils.stubEndpoint("/project/project-id", mockProjectId); - TestUtils.stubEndpoint("/instance/zone", mockZone); - TestUtils.stubEndpoint("/instance/region", mockRegion); - TestUtils.stubEndpoint("/instance/id", mockInstanceId); - TestUtils.stubEndpoint("/instance/name", mockInstanceName); - TestUtils.stubEndpoint("/instance/machine-type", mockInstanceType); - TestUtils.stubEndpoint("/instance/attributes/cluster-name", mockClusterName); - TestUtils.stubEndpoint("/instance/attributes/cluster-location", mockClusterLocation); - TestUtils.stubEndpoint("/instance/hostname", mockHostname); - } - - @Test - void testGetProjectId() { - assertEquals(mockProjectId, mockMetadataConfig.getProjectId()); - } - - /** Test Zone Retrieval */ - @ParameterizedTest - @MethodSource("provideZoneRetrievalArguments") - void testGetZone(String stubbedMockZone, String expectedMockZone) { - TestUtils.stubEndpoint("/instance/zone", stubbedMockZone); - assertEquals(expectedMockZone, mockMetadataConfig.getZone()); - } - - private static Stream provideZoneRetrievalArguments() { - return Stream.of( - Arguments.of(mockZone, mockZone), - Arguments.of( - "projects/640212054955/zones/australia-southeast1-a", "australia-southeast1-a"), - Arguments.of("", null), - Arguments.of(null, null)); - } - - /** Test Region Retrieval */ - @ParameterizedTest - @MethodSource("provideRegionRetrievalArguments") - void testGetRegion(String stubbedMockRegion, String expectedMockRegion) { - TestUtils.stubEndpoint("/instance/region", stubbedMockRegion); - assertEquals(expectedMockRegion, mockMetadataConfig.getRegion()); - } - - private static Stream provideRegionRetrievalArguments() { - return Stream.of( - Arguments.of(mockRegion, mockRegion), - Arguments.of("projects/640212054955/regions/us-central1", "us-central1"), - Arguments.of("", null), - Arguments.of(null, null)); - } - - /** Test Region Retrieval from Zone */ - @ParameterizedTest - @MethodSource("provideZoneArguments") - void testGetRegionFromZone(String stubbedMockZone, String expectedRegion) { - TestUtils.stubEndpoint("/instance/zone", stubbedMockZone); - assertEquals(expectedRegion, mockMetadataConfig.getRegionFromZone()); - } - - private static Stream provideZoneArguments() { - return Stream.of( - Arguments.of(mockZone, "country-region"), - Arguments.of("projects/640212054955/zones/australia-southeast1-a", "australia-southeast1"), - Arguments.of("country-region", null), - Arguments.of("", null), - Arguments.of(null, null)); - } - - /** Test Machine Type Retrieval */ - @ParameterizedTest - @MethodSource("provideMachineTypeRetrievalArguments") - void testGetMachineType(String stubbedMockMachineType, String expectedMockMachineType) { - TestUtils.stubEndpoint("/instance/machine-type", stubbedMockMachineType); - assertEquals(expectedMockMachineType, mockMetadataConfig.getMachineType()); - } - - private static Stream provideMachineTypeRetrievalArguments() { - return Stream.of( - Arguments.of(mockInstanceType, mockInstanceType), - Arguments.of("projects/640212054955/machineTypes/e2-medium", "e2-medium"), - Arguments.of("", null), - Arguments.of(null, null)); - } - - @Test - void testGetInstanceId() { - assertEquals(mockInstanceId, mockMetadataConfig.getInstanceId()); - } - - @Test - void testGetClusterName() { - assertEquals(mockClusterName, mockMetadataConfig.getClusterName()); - } - - @Test - void testGetClusterLocation() { - assertEquals(mockClusterLocation, mockMetadataConfig.getClusterLocation()); - } - - @Test - void testGetInstanceHostName() { - assertEquals(mockHostname, mockMetadataConfig.getInstanceHostName()); - } - - @Test - void testGetInstanceName() { - assertEquals(mockInstanceName, mockMetadataConfig.getInstanceName()); - } -} diff --git a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetectorTest.java b/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetectorTest.java deleted file mode 100644 index 2cdaf112..00000000 --- a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/GCPPlatformDetectorTest.java +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.google.cloud.opentelemetry.detection.AttributeKeys.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import com.github.tomakehurst.wiremock.junit5.WireMockTest; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Stream; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.NullSource; -import org.junit.jupiter.params.provider.ValueSource; -import org.mockito.Mockito; - -@WireMockTest(httpPort = 8089) -public class GCPPlatformDetectorTest { - private final GCPMetadataConfig mockMetadataConfig = - new GCPMetadataConfig("http://localhost:8089/"); - private static final Map envVars = new HashMap<>(); - - @BeforeEach - public void setup() { - envVars.clear(); - } - - @ParameterizedTest - @NullSource - @ValueSource(strings = {""}) - public void testGCPComputeResourceNotGCP(String projectId) { - GCPMetadataConfig mockMetadataConfig = Mockito.mock(GCPMetadataConfig.class); - Mockito.when(mockMetadataConfig.getProjectId()).thenReturn(projectId); - - GCPPlatformDetector detector = - new GCPPlatformDetector(mockMetadataConfig, EnvironmentVariables.DEFAULT_INSTANCE); - // If GCPMetadataConfig cannot find ProjectId, then the platform should be unsupported - assertEquals( - GCPPlatformDetector.SupportedPlatform.UNKNOWN_PLATFORM, - detector.detectPlatform().getSupportedPlatform()); - assertEquals(Collections.emptyMap(), detector.detectPlatform().getAttributes()); - } - - @Test - public void testGCPComputeResourceNonGCPEndpoint() { - // intentionally not providing the required Metadata-Flavor header with the - // request to mimic non GCP endpoint - stubFor( - get(urlEqualTo("/project/project-id")) - .willReturn(aResponse().withBody("nonGCPEndpointTest"))); - GCPPlatformDetector detector = - new GCPPlatformDetector(mockMetadataConfig, EnvironmentVariables.DEFAULT_INSTANCE); - assertEquals( - GCPPlatformDetector.SupportedPlatform.UNKNOWN_PLATFORM, - detector.detectPlatform().getSupportedPlatform()); - assertEquals(Collections.emptyMap(), detector.detectPlatform().getAttributes()); - } - - /** Google Compute Engine Tests * */ - @Test - public void testGCEResourceWithGCEAttributesSucceeds() { - TestUtils.stubEndpoint("/project/project-id", "GCE-pid"); - TestUtils.stubEndpoint("/instance/zone", "country-gce_region-gce_zone"); - TestUtils.stubEndpoint("/instance/id", "GCE-instance-id"); - TestUtils.stubEndpoint("/instance/name", "GCE-instance-name"); - TestUtils.stubEndpoint("/instance/machine-type", "GCE-instance-type"); - TestUtils.stubEndpoint("/instance/hostname", "GCE-instance-hostname"); - - GCPPlatformDetector detector = - new GCPPlatformDetector(mockMetadataConfig, new EnvVarMock(envVars)); - - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_COMPUTE_ENGINE, - detector.detectPlatform().getSupportedPlatform()); - assertEquals("GCE-pid", detector.detectPlatform().getProjectId()); - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals(new GoogleComputeEngine(mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals(6, detectedAttributes.size()); - - assertEquals("country-gce_region-gce_zone", detectedAttributes.get(GCE_AVAILABILITY_ZONE)); - assertEquals("country-gce_region", detectedAttributes.get(GCE_CLOUD_REGION)); - assertEquals("GCE-instance-id", detectedAttributes.get(GCE_INSTANCE_ID)); - assertEquals("GCE-instance-name", detectedAttributes.get(GCE_INSTANCE_NAME)); - assertEquals("GCE-instance-type", detectedAttributes.get(GCE_MACHINE_TYPE)); - assertEquals("GCE-instance-hostname", detectedAttributes.get(GCE_INSTANCE_HOSTNAME)); - } - - /** Google Kubernetes Engine Tests * */ - @Test - public void testGKEResourceWithGKEAttributesSucceedsLocationZone() { - envVars.put("KUBERNETES_SERVICE_HOST", "GKE-testHost"); - envVars.put("NAMESPACE", "GKE-testNameSpace"); - // Hostname can truncate pod name, so we test downward API override. - envVars.put("HOSTNAME", "GKE-testHostName"); - envVars.put("POD_NAME", "GKE-testHostName-full-1234"); - envVars.put("CONTAINER_NAME", "GKE-testContainerName"); - - TestUtils.stubEndpoint("/project/project-id", "GKE-pid"); - TestUtils.stubEndpoint("/instance/id", "GKE-instance-id"); - TestUtils.stubEndpoint("/instance/name", "instance-name"); - TestUtils.stubEndpoint("/instance/machine-type", "instance-type"); - TestUtils.stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name"); - TestUtils.stubEndpoint("/instance/attributes/cluster-location", "country-region-zone"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleKubernetesEngine(mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GKE-pid", detector.detectPlatform().getProjectId()); - assertEquals(4, detectedAttributes.size()); - - assertEquals(GKE_LOCATION_TYPE_ZONE, detectedAttributes.get(GKE_CLUSTER_LOCATION_TYPE)); - assertEquals("country-region-zone", detectedAttributes.get(GKE_CLUSTER_LOCATION)); - assertEquals("GKE-cluster-name", detectedAttributes.get(GKE_CLUSTER_NAME)); - assertEquals("GKE-instance-id", detectedAttributes.get(GKE_HOST_ID)); - } - - @Test - public void testGKEResourceWithGKEAttributesSucceedsLocationRegion() { - envVars.put("KUBERNETES_SERVICE_HOST", "GKE-testHost"); - envVars.put("NAMESPACE", "GKE-testNameSpace"); - // Hostname can truncate pod name, so we test downward API override. - envVars.put("HOSTNAME", "GKE-testHostName"); - envVars.put("POD_NAME", "GKE-testHostName-full-1234"); - envVars.put("CONTAINER_NAME", "GKE-testContainerName"); - - TestUtils.stubEndpoint("/project/project-id", "GKE-pid"); - TestUtils.stubEndpoint("/instance/id", "GKE-instance-id"); - TestUtils.stubEndpoint("/instance/name", "GCE-instance-name"); - TestUtils.stubEndpoint("/instance/machine-type", "GKE-instance-type"); - TestUtils.stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name"); - TestUtils.stubEndpoint("/instance/attributes/cluster-location", "country-region"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleKubernetesEngine(mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GKE-pid", detector.detectPlatform().getProjectId()); - assertEquals(4, detectedAttributes.size()); - - assertEquals(GKE_LOCATION_TYPE_REGION, detectedAttributes.get(GKE_CLUSTER_LOCATION_TYPE)); - assertEquals("country-region", detectedAttributes.get(GKE_CLUSTER_LOCATION)); - assertEquals("GKE-cluster-name", detectedAttributes.get(GKE_CLUSTER_NAME)); - assertEquals("GKE-instance-id", detectedAttributes.get(GKE_HOST_ID)); - } - - @ParameterizedTest - @NullSource - @ValueSource(strings = {"", "country", "country-region-zone-invalid"}) - public void testGKEResourceDetectionWithInvalidLocations(String clusterLocation) { - envVars.put("KUBERNETES_SERVICE_HOST", "GKE-testHost"); - envVars.put("NAMESPACE", "GKE-testNameSpace"); - // Hostname can truncate pod name, so we test downward API override. - envVars.put("HOSTNAME", "GKE-testHostName"); - envVars.put("POD_NAME", "GKE-testHostName-full-1234"); - envVars.put("CONTAINER_NAME", "GKE-testContainerName"); - - TestUtils.stubEndpoint("/project/project-id", "GKE-pid"); - TestUtils.stubEndpoint("/instance/id", "GKE-instance-id"); - TestUtils.stubEndpoint("/instance/name", "GKE-instance-name"); - TestUtils.stubEndpoint("/instance/machine-type", "GKE-instance-type"); - TestUtils.stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name"); - TestUtils.stubEndpoint("/instance/attributes/cluster-location", clusterLocation); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleKubernetesEngine(mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GKE-pid", detector.detectPlatform().getProjectId()); - assertEquals(4, detectedAttributes.size()); - - assertEquals("", detector.detectPlatform().getAttributes().get(GKE_CLUSTER_LOCATION_TYPE)); - if (clusterLocation == null || clusterLocation.isEmpty()) { - assertNull(detectedAttributes.get(GKE_CLUSTER_LOCATION)); - } else { - assertEquals(clusterLocation, detectedAttributes.get(GKE_CLUSTER_LOCATION)); - } - assertEquals("GKE-cluster-name", detectedAttributes.get(GKE_CLUSTER_NAME)); - assertEquals("GKE-instance-id", detectedAttributes.get(GKE_HOST_ID)); - } - - /** Google Cloud Functions Tests * */ - @Test - public void testGCFResourceWithCloudFunctionAttributesSucceeds() { - // Setup GCF required env vars - envVars.put("K_SERVICE", "cloud-function-hello"); - envVars.put("K_REVISION", "cloud-function-hello.1"); - envVars.put("FUNCTION_TARGET", "cloud-function-hello"); - - TestUtils.stubEndpoint("/project/project-id", "GCF-pid"); - TestUtils.stubEndpoint("/instance/zone", "country-region-zone"); - TestUtils.stubEndpoint("/instance/id", "GCF-instance-id"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_FUNCTIONS, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleCloudFunction(mockEnv, mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GCF-pid", detector.detectPlatform().getProjectId()); - assertEquals(5, detectedAttributes.size()); - - assertEquals("cloud-function-hello", detectedAttributes.get(SERVERLESS_COMPUTE_NAME)); - assertEquals("cloud-function-hello.1", detectedAttributes.get(SERVERLESS_COMPUTE_REVISION)); - assertEquals( - "country-region-zone", detectedAttributes.get(SERVERLESS_COMPUTE_AVAILABILITY_ZONE)); - assertEquals("country-region", detectedAttributes.get(SERVERLESS_COMPUTE_CLOUD_REGION)); - assertEquals("GCF-instance-id", detectedAttributes.get(SERVERLESS_COMPUTE_INSTANCE_ID)); - } - - @Test - public void testGCFDetectionWhenGCRAttributesPresent() { - // Setup GCF required env vars - envVars.put("K_SERVICE", "cloud-function-hello"); - envVars.put("K_REVISION", "cloud-function-hello.1"); - envVars.put("FUNCTION_TARGET", "cloud-function-hello"); - // This should be ignored and detected platform should still be GCF - envVars.put("K_CONFIGURATION", "cloud-run-hello"); - - TestUtils.stubEndpoint("/project/project-id", "GCF-pid"); - TestUtils.stubEndpoint("/instance/zone", "country-region-zone"); - TestUtils.stubEndpoint("/instance/id", "GCF-instance-id"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_FUNCTIONS, - detector.detectPlatform().getSupportedPlatform()); - assertEquals("GCF-pid", detector.detectPlatform().getProjectId()); - assertEquals( - new GoogleCloudFunction(mockEnv, mockMetadataConfig).getAttributes(), - detector.detectPlatform().getAttributes()); - } - - /** Google Cloud Run Tests (Service) * */ - @Test - public void testGCFResourceWithCloudRunAttributesSucceeds() { - // Setup GCR service required env vars - envVars.put("K_SERVICE", "cloud-run-hello"); - envVars.put("K_REVISION", "cloud-run-hello.1"); - envVars.put("K_CONFIGURATION", "cloud-run-hello"); - - TestUtils.stubEndpoint("/project/project-id", "GCR-pid"); - TestUtils.stubEndpoint("/instance/zone", "country-region-zone"); - TestUtils.stubEndpoint("/instance/id", "GCR-instance-id"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_RUN, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleCloudFunction(mockEnv, mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GCR-pid", detector.detectPlatform().getProjectId()); - assertEquals(5, detectedAttributes.size()); - - assertEquals("cloud-run-hello", detectedAttributes.get(SERVERLESS_COMPUTE_NAME)); - assertEquals("cloud-run-hello.1", detectedAttributes.get(SERVERLESS_COMPUTE_REVISION)); - assertEquals( - "country-region-zone", detectedAttributes.get(SERVERLESS_COMPUTE_AVAILABILITY_ZONE)); - assertEquals("country-region", detectedAttributes.get(SERVERLESS_COMPUTE_CLOUD_REGION)); - assertEquals("GCR-instance-id", detectedAttributes.get(SERVERLESS_COMPUTE_INSTANCE_ID)); - } - - /** Google Cloud Run Tests (Jobs) * */ - @Test - public void testCloudRunJobResourceWithAttributesSucceeds() { - // Setup GCR Job required env vars - envVars.put("CLOUD_RUN_JOB", "cloud-run-hello-job"); - envVars.put("CLOUD_RUN_EXECUTION", "cloud-run-hello-job-1a2b3c"); - envVars.put("CLOUD_RUN_TASK_INDEX", "0"); - - TestUtils.stubEndpoint("/project/project-id", "GCR-pid"); - TestUtils.stubEndpoint("/instance/zone", "country-region-zone"); - TestUtils.stubEndpoint("/instance/id", "GCR-job-instance-id"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_CLOUD_RUN_JOB, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleCloudRunJob(mockEnv, mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GCR-pid", detector.detectPlatform().getProjectId()); - assertEquals(5, detectedAttributes.size()); - - assertEquals("cloud-run-hello-job-1a2b3c", detectedAttributes.get(GCR_JOB_EXECUTION_KEY)); - assertEquals("0", detectedAttributes.get(GCR_JOB_TASK_INDEX)); - assertEquals("cloud-run-hello-job", detectedAttributes.get(SERVERLESS_COMPUTE_NAME)); - assertEquals("country-region", detectedAttributes.get(SERVERLESS_COMPUTE_CLOUD_REGION)); - assertEquals("GCR-job-instance-id", detectedAttributes.get(SERVERLESS_COMPUTE_INSTANCE_ID)); - } - - /** Google App Engine Tests * */ - @ParameterizedTest - @MethodSource("provideGAEVariantEnvironmentVariable") - public void testGAEResourceWithAppEngineAttributesSucceeds( - String gaeEnvironmentVar, - String metadataZone, - String expectedZone, - String metadataRegion, - String expectedRegion) { - envVars.put("GAE_SERVICE", "app-engine-hello"); - envVars.put("GAE_VERSION", "app-engine-hello-v1"); - envVars.put("GAE_INSTANCE", "app-engine-hello-f236d"); - envVars.put("GAE_ENV", gaeEnvironmentVar); - - TestUtils.stubEndpoint("/project/project-id", "GAE-pid"); - TestUtils.stubEndpoint("/instance/zone", metadataZone); - TestUtils.stubEndpoint("/instance/region", metadataRegion); - TestUtils.stubEndpoint("/instance/id", "GAE-instance-id"); - - EnvironmentVariables mockEnv = new EnvVarMock(envVars); - GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv); - - Map detectedAttributes = detector.detectPlatform().getAttributes(); - assertEquals( - GCPPlatformDetector.SupportedPlatform.GOOGLE_APP_ENGINE, - detector.detectPlatform().getSupportedPlatform()); - assertEquals( - new GoogleAppEngine(mockEnv, mockMetadataConfig).getAttributes(), detectedAttributes); - assertEquals("GAE-pid", detector.detectPlatform().getProjectId()); - assertEquals(5, detectedAttributes.size()); - assertEquals(expectedRegion, detector.detectPlatform().getAttributes().get(GAE_CLOUD_REGION)); - assertEquals("app-engine-hello", detectedAttributes.get(GAE_MODULE_NAME)); - assertEquals("app-engine-hello-v1", detectedAttributes.get(GAE_APP_VERSION)); - assertEquals("app-engine-hello-f236d", detectedAttributes.get(GAE_INSTANCE_ID)); - assertEquals(expectedZone, detectedAttributes.get(GAE_AVAILABILITY_ZONE)); - } - - private static Arguments gaeTestArguments( - String gaeEnvironmentVar, - String metadataZone, - String expectedZone, - String metadataRegion, - String expectedRegion) { - return Arguments.of( - gaeEnvironmentVar, metadataZone, expectedZone, metadataRegion, expectedRegion); - } - - // Provides parameterized arguments for testGAEResourceWithAppEngineAttributesSucceeds - private static Stream provideGAEVariantEnvironmentVariable() { - - return Stream.of( - // GAE standard - gaeTestArguments( - "standard", - // the zone should be extracted from the zone attribute - "projects/233510669999/zones/us15", - "us15", - // the region should be extracted from region attribute - "projects/233510669999/regions/us-central1", - "us-central1"), - - // GAE flex - gaeTestArguments( - (String) null, - "country-region-zone", - "country-region-zone", - // the region should be extracted from the zone attribute - "", - "country-region"), - gaeTestArguments( - "flex", "country-region-zone", "country-region-zone", "", "country-region"), - gaeTestArguments("", "country-region-zone", "country-region-zone", "", "country-region")); - } -} diff --git a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/TestUtils.java b/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/TestUtils.java deleted file mode 100644 index bef3a53c..00000000 --- a/detectors/resources-support/src/test/java/com/google/cloud/opentelemetry/detection/TestUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.opentelemetry.detection; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; - -public final class TestUtils { - // Helper method to help stub endpoints - public static void stubEndpoint(String endpointPath, String responseBody) { - stubFor( - get(urlEqualTo(endpointPath)) - .willReturn( - aResponse().withHeader("Metadata-Flavor", "Google").withBody(responseBody))); - } -} diff --git a/settings.gradle b/settings.gradle index 3511b8e8..43d85e45 100644 --- a/settings.gradle +++ b/settings.gradle @@ -37,7 +37,6 @@ include ":exporter-auto" include ":examples-autoconf" include ":examples-autoinstrument" include ":examples-resource" -include ":detector-resources-support" include ":e2e-test-server" include ":examples-spring-sleuth" include ":examples-spring" @@ -73,9 +72,6 @@ project(':examples-metrics').projectDir = project(':exporter-auto').projectDir = "$rootDir/exporters/auto" as File -project(':detector-resources-support').projectDir = - "$rootDir/detectors/resources-support" as File - project(':examples-resource').projectDir = "$rootDir/examples/resource" as File From b5081b2c7e6a78a5b9b7dd6a5e48aad7f8cd34f8 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Thu, 7 May 2026 21:17:41 +0000 Subject: [PATCH 3/3] Update test runner image --- cloudbuild-e2e-cloud-functions-gen2.yaml | 2 +- cloudbuild-e2e-cloud-run.yaml | 2 +- cloudbuild-e2e-gae.yaml | 2 +- cloudbuild-e2e-gce.yaml | 2 +- cloudbuild-e2e-gke.yaml | 2 +- cloudbuild-e2e-local.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cloudbuild-e2e-cloud-functions-gen2.yaml b/cloudbuild-e2e-cloud-functions-gen2.yaml index d81023ae..041e623c 100644 --- a/cloudbuild-e2e-cloud-functions-gen2.yaml +++ b/cloudbuild-e2e-cloud-functions-gen2.yaml @@ -44,5 +44,5 @@ steps: logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs substitutions: - _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.20.1 + _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.21.0 _TEST_SERVER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-java-e2e-test-server:${SHORT_SHA} diff --git a/cloudbuild-e2e-cloud-run.yaml b/cloudbuild-e2e-cloud-run.yaml index df609056..b791005b 100644 --- a/cloudbuild-e2e-cloud-run.yaml +++ b/cloudbuild-e2e-cloud-run.yaml @@ -32,5 +32,5 @@ steps: logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs substitutions: - _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.20.1 + _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.21.0 _TEST_SERVER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-java-e2e-test-server:${SHORT_SHA} diff --git a/cloudbuild-e2e-gae.yaml b/cloudbuild-e2e-gae.yaml index 0f299582..210d76f4 100644 --- a/cloudbuild-e2e-gae.yaml +++ b/cloudbuild-e2e-gae.yaml @@ -33,5 +33,5 @@ steps: logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs substitutions: - _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.20.1 + _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.21.0 _TEST_SERVER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-java-e2e-test-server:${SHORT_SHA} diff --git a/cloudbuild-e2e-gce.yaml b/cloudbuild-e2e-gce.yaml index 1fc255a4..1ff3d3e7 100644 --- a/cloudbuild-e2e-gce.yaml +++ b/cloudbuild-e2e-gce.yaml @@ -32,5 +32,5 @@ steps: logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs substitutions: - _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.20.1 + _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.21.0 _TEST_SERVER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-java-e2e-test-server:${SHORT_SHA} diff --git a/cloudbuild-e2e-gke.yaml b/cloudbuild-e2e-gke.yaml index f3aa0d2c..57fd66d2 100644 --- a/cloudbuild-e2e-gke.yaml +++ b/cloudbuild-e2e-gke.yaml @@ -32,5 +32,5 @@ steps: logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs substitutions: - _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.20.1 + _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.21.0 _TEST_SERVER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-java-e2e-test-server:${SHORT_SHA} diff --git a/cloudbuild-e2e-local.yaml b/cloudbuild-e2e-local.yaml index 79d12f3a..a5e2cf7d 100644 --- a/cloudbuild-e2e-local.yaml +++ b/cloudbuild-e2e-local.yaml @@ -39,5 +39,5 @@ steps: logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs substitutions: - _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.20.1 + _TEST_RUNNER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing:0.21.0 _TEST_SERVER_IMAGE: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-java-e2e-test-server:${SHORT_SHA}