Skip to content

Commit b0a0878

Browse files
committed
Extract GCPMetadataConfig into support library
1 parent 63bb79f commit b0a0878

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

detectors/resources-support/build.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
plugins {
17-
id 'java'
18-
}
19-
20-
group 'org.example'
21-
22-
repositories {
23-
mavenCentral()
24-
}
16+
description = 'Support library for Google Cloud Resource Detector'
2517

2618
dependencies {
2719
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
2820
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
2921
}
3022

31-
test {
32-
useJUnitPlatform()
23+
afterEvaluate {
24+
tasks.named("compileJava"){
25+
options.release = 8
26+
}
3327
}

detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java renamed to detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ public GCPMetadataConfig(String url) {
4343
this.url = url;
4444
}
4545

46-
boolean isRunningOnGcp() {
46+
public boolean isRunningOnGcp() {
4747
return getProjectId() != null && !getProjectId().isEmpty();
4848
}
4949

5050
// Returns null on failure to retrieve from metadata server
51-
String getProjectId() {
51+
public String getProjectId() {
5252
return getAttribute("project/project-id");
5353
}
5454

5555
// Example response: projects/640212054955/zones/australia-southeast1-a
5656
// Returns null on failure to retrieve from metadata server
57-
String getZone() {
57+
public String getZone() {
5858
String zone = getAttribute("instance/zone");
5959
if (zone != null && zone.contains("/")) {
6060
zone = zone.substring(zone.lastIndexOf('/') + 1);
@@ -66,7 +66,7 @@ String getZone() {
6666
// method involve detecting region in GAE standard environment
6767
// Example response: projects/5689182099321/regions/us-central1
6868
// Returns null on failure to retrieve from metadata server
69-
String getRegion() {
69+
public String getRegion() {
7070
String region = getAttribute("instance/region");
7171
if (region != null && region.contains("/")) {
7272
region = region.substring(region.lastIndexOf('/') + 1);
@@ -75,7 +75,7 @@ String getRegion() {
7575
}
7676

7777
// Example response: projects/640212054955/machineTypes/e2-medium
78-
String getMachineType() {
78+
public String getMachineType() {
7979
String machineType = getAttribute("instance/machine-type");
8080
if (machineType != null && machineType.contains("/")) {
8181
machineType = machineType.substring(machineType.lastIndexOf('/') + 1);
@@ -84,27 +84,27 @@ String getMachineType() {
8484
}
8585

8686
// Returns null on failure to retrieve from metadata server
87-
String getInstanceId() {
87+
public String getInstanceId() {
8888
return getAttribute("instance/id");
8989
}
9090

9191
// Returns null on failure to retrieve from metadata server
92-
String getClusterName() {
92+
public String getClusterName() {
9393
return getAttribute("instance/attributes/cluster-name");
9494
}
9595

9696
// Returns null on failure to retrieve from metadata server
97-
String getClusterLocation() {
97+
public String getClusterLocation() {
9898
return getAttribute("instance/attributes/cluster-location");
9999
}
100100

101101
// Returns null on failure to retrieve from metadata server
102-
String getInstanceHostName() {
102+
public String getInstanceHostName() {
103103
return getAttribute("instance/hostname");
104104
}
105105

106106
// Returns null on failure to retrieve from metadata server
107-
String getInstanceName() {
107+
public String getInstanceName() {
108108
return getAttribute("instance/name");
109109
}
110110

detectors/resources-support/src/main/java/com/google/cloud/opentelemetry/detectors/Main.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

detectors/resources/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727
implementation(libraries.opentelemetry_sdk_autoconf)
2828
implementation(libraries.opentelemetry_semconv)
2929
implementation platform(libraries.opentelemetry_bom)
30+
implementation project(':detector-resources-support')
3031
testImplementation(testLibraries.assertj)
3132
testImplementation(testLibraries.junit)
3233
testImplementation(testLibraries.wiremock)

0 commit comments

Comments
 (0)