diff --git a/detectors/resources-support/build.gradle b/detectors/resources-support/build.gradle index 9af95e18..d4b32587 100644 --- a/detectors/resources-support/build.gradle +++ b/detectors/resources-support/build.gradle @@ -13,21 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -plugins { - id 'java' -} - -group 'org.example' - -repositories { - mavenCentral() -} +description = 'Support library for Google Cloud Resource Detector' dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' } -test { - useJUnitPlatform() +afterEvaluate { + tasks.named("compileJava"){ + options.release = 8 + } } \ No newline at end of file diff --git a/detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java similarity index 92% rename from detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java rename to detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java index ab57dcf8..a1943ed2 100644 --- a/detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java +++ b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java @@ -43,18 +43,18 @@ public GCPMetadataConfig(String url) { this.url = url; } - boolean isRunningOnGcp() { + public boolean isRunningOnGcp() { return getProjectId() != null && !getProjectId().isEmpty(); } // Returns null on failure to retrieve from metadata server - String getProjectId() { + public String getProjectId() { return getAttribute("project/project-id"); } // Example response: projects/640212054955/zones/australia-southeast1-a // Returns null on failure to retrieve from metadata server - String getZone() { + public String getZone() { String zone = getAttribute("instance/zone"); if (zone != null && zone.contains("/")) { zone = zone.substring(zone.lastIndexOf('/') + 1); @@ -66,7 +66,7 @@ String getZone() { // method involve detecting region in GAE standard environment // Example response: projects/5689182099321/regions/us-central1 // Returns null on failure to retrieve from metadata server - String getRegion() { + public String getRegion() { String region = getAttribute("instance/region"); if (region != null && region.contains("/")) { region = region.substring(region.lastIndexOf('/') + 1); @@ -75,7 +75,7 @@ String getRegion() { } // Example response: projects/640212054955/machineTypes/e2-medium - String getMachineType() { + public String getMachineType() { String machineType = getAttribute("instance/machine-type"); if (machineType != null && machineType.contains("/")) { machineType = machineType.substring(machineType.lastIndexOf('/') + 1); @@ -84,27 +84,27 @@ String getMachineType() { } // Returns null on failure to retrieve from metadata server - String getInstanceId() { + public String getInstanceId() { return getAttribute("instance/id"); } // Returns null on failure to retrieve from metadata server - String getClusterName() { + public String getClusterName() { return getAttribute("instance/attributes/cluster-name"); } // Returns null on failure to retrieve from metadata server - String getClusterLocation() { + public String getClusterLocation() { return getAttribute("instance/attributes/cluster-location"); } // Returns null on failure to retrieve from metadata server - String getInstanceHostName() { + public String getInstanceHostName() { return getAttribute("instance/hostname"); } // Returns null on failure to retrieve from metadata server - String getInstanceName() { + public String getInstanceName() { return getAttribute("instance/name"); } diff --git a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/Main.java b/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/Main.java deleted file mode 100644 index 6412167c..00000000 --- a/detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/Main.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2023 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.detectors; - -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} diff --git a/detectors/resources/build.gradle b/detectors/resources/build.gradle index 2d086614..77e603a0 100644 --- a/detectors/resources/build.gradle +++ b/detectors/resources/build.gradle @@ -27,6 +27,7 @@ dependencies { implementation(libraries.opentelemetry_sdk_autoconf) implementation(libraries.opentelemetry_semconv) implementation platform(libraries.opentelemetry_bom) + implementation project(':detector-resources-support') testImplementation(testLibraries.assertj) testImplementation(testLibraries.junit) testImplementation(testLibraries.wiremock)