Skip to content

Commit c9235af

Browse files
committed
Rname GCPResource -> GCPResourceDetector
1 parent 5425525 commit c9235af

File tree

7 files changed

+67
-29
lines changed

7 files changed

+67
-29
lines changed
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
plugins {
2-
id 'java'
17+
id 'java'
318
}
419

520
group 'org.example'
621

722
repositories {
8-
mavenCentral()
23+
mavenCentral()
924
}
1025

1126
dependencies {
12-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
13-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
27+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
28+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
1429
}
1530

1631
test {
17-
useJUnitPlatform()
32+
useJUnitPlatform()
1833
}
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.google.cloud.opentelemetry.detectors;
217

318
public class Main {
4-
public static void main(String[] args) {
5-
System.out.println("Hello world!");
6-
}
7-
}
19+
public static void main(String[] args) {
20+
System.out.println("Hello world!");
21+
}
22+
}

detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPResource.java renamed to detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPResourceDetector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
* Google Compute Engine (GCE), Google Kubernetes Engine (GKE), Google Cloud Functions (GCF), Google
3030
* App Engine (GAE) and Google Cloud Run (GCR).
3131
*/
32-
public class GCPResource implements ResourceProvider {
32+
public class GCPResourceDetector implements ResourceProvider {
3333
private final GCPMetadataConfig metadata;
3434
private final EnvVars envVars;
3535

36-
private static final Logger LOGGER = Logger.getLogger(GCPResource.class.getSimpleName());
36+
private static final Logger LOGGER = Logger.getLogger(GCPResourceDetector.class.getSimpleName());
3737

38-
public GCPResource() {
38+
public GCPResourceDetector() {
3939
this.metadata = GCPMetadataConfig.DEFAULT_INSTANCE;
4040
this.envVars = EnvVars.DEFAULT_INSTANCE;
4141
}
4242

4343
// for testing only
44-
GCPResource(GCPMetadataConfig metadata, EnvVars envVars) {
44+
GCPResourceDetector(GCPMetadataConfig metadata, EnvVars envVars) {
4545
this.metadata = metadata;
4646
this.envVars = envVars;
4747
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
com.google.cloud.opentelemetry.detectors.GCPResource
1+
com.google.cloud.opentelemetry.detectors.GCPResourceDetector

detectors/resources/src/test/java/com/google/cloud/opentelemetry/detectors/GCPResourceTest.java renamed to detectors/resources/src/test/java/com/google/cloud/opentelemetry/detectors/GCPResourceDetectorTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.mockito.Mockito;
3737

3838
@RunWith(JUnit4.class)
39-
public class GCPResourceTest {
39+
public class GCPResourceDetectorTest {
4040
@Rule public final WireMockRule wireMockRule = new WireMockRule(8089);
4141
private final GCPMetadataConfig metadataConfig = new GCPMetadataConfig("http://localhost:8089/");
4242
private static final Map<String, String> envVars = new HashMap<>();
@@ -52,15 +52,16 @@ public void findsWithServiceLoader() {
5252
ServiceLoader.load(ResourceProvider.class, getClass().getClassLoader());
5353
assertTrue(
5454
"Could not load GCP Resource detector using serviceloader, found: " + services,
55-
services.stream().anyMatch(provider -> provider.type().equals(GCPResource.class)));
55+
services.stream().anyMatch(provider -> provider.type().equals(GCPResourceDetector.class)));
5656
}
5757

5858
@Test
5959
public void testGCPComputeResourceNotGCP() {
6060
GCPMetadataConfig mockMetadataConfig = Mockito.mock(GCPMetadataConfig.class);
6161
Mockito.when(mockMetadataConfig.isRunningOnGcp()).thenReturn(false);
6262

63-
GCPResource testResource = new GCPResource(mockMetadataConfig, EnvVars.DEFAULT_INSTANCE);
63+
GCPResourceDetector testResource =
64+
new GCPResourceDetector(mockMetadataConfig, EnvVars.DEFAULT_INSTANCE);
6465
// If GCPMetadataConfig determines that its not running on GCP, then attributes should be empty
6566
assertThat(testResource.getAttributes()).isEmpty();
6667
}
@@ -72,7 +73,8 @@ public void testGCPComputeResourceNonGCPEndpoint() {
7273
stubFor(
7374
get(urlEqualTo("/project/project-id"))
7475
.willReturn(aResponse().withBody("nonGCPendpointTest")));
75-
GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(envVars));
76+
GCPResourceDetector testResource =
77+
new GCPResourceDetector(metadataConfig, new EnvVarMock(envVars));
7678
assertThat(testResource.getAttributes()).isEmpty();
7779
}
7880

@@ -85,7 +87,8 @@ public void testGCEResourceWithGCEAttributesSucceeds() {
8587
stubEndpoint("/instance/name", "GCE-instance-name");
8688
stubEndpoint("/instance/machine-type", "GCE-instance-type");
8789

88-
final GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(envVars));
90+
final GCPResourceDetector testResource =
91+
new GCPResourceDetector(metadataConfig, new EnvVarMock(envVars));
8992
assertThat(testResource.getAttributes())
9093
.hasSize(8)
9194
.containsEntry(
@@ -118,7 +121,8 @@ public void testGKEResourceWithGKEAttributesSucceedsLocationZone() {
118121
stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name");
119122
stubEndpoint("/instance/attributes/cluster-location", "country-region-zone");
120123

121-
GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(envVars));
124+
GCPResourceDetector testResource =
125+
new GCPResourceDetector(metadataConfig, new EnvVarMock(envVars));
122126
assertThat(testResource.getAttributes())
123127
.hasSize(8)
124128
.containsEntry(ResourceAttributes.CLOUD_PROVIDER, "gcp")
@@ -147,7 +151,8 @@ public void testGKEResourceWithGKEAttributesSucceedsLocationRegion() {
147151
stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name");
148152
stubEndpoint("/instance/attributes/cluster-location", "country-region");
149153

150-
GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(envVars));
154+
GCPResourceDetector testResource =
155+
new GCPResourceDetector(metadataConfig, new EnvVarMock(envVars));
151156
assertThat(testResource.getAttributes())
152157
.hasSize(8)
153158
.containsEntry(ResourceAttributes.CLOUD_PROVIDER, "gcp")
@@ -172,7 +177,8 @@ public void testGCFResourceWithCloudFunctionAttributesSucceeds() {
172177
stubEndpoint("/instance/zone", "country-region-zone");
173178
stubEndpoint("/instance/id", "GCF-instance-id");
174179

175-
GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(envVars));
180+
GCPResourceDetector testResource =
181+
new GCPResourceDetector(metadataConfig, new EnvVarMock(envVars));
176182
assertThat(testResource.getAttributes())
177183
.hasSize(7)
178184
.containsEntry(
@@ -200,7 +206,8 @@ public void testGAEResourceWithAppEngineAttributesSucceedsInFlex() {
200206
stubEndpoint("/instance/region", "country-region1");
201207
stubEndpoint("/instance/id", "GAE-instance-id");
202208

203-
GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(envVars));
209+
GCPResourceDetector testResource =
210+
new GCPResourceDetector(metadataConfig, new EnvVarMock(envVars));
204211
assertThat(testResource.getAttributes())
205212
.hasSize(7)
206213
.containsEntry(
@@ -229,7 +236,8 @@ public void testGAEResourceWithAppEngineAttributesSucceedsInStandard() {
229236

230237
Map<String, String> updatedEnvVars = new HashMap<>(envVars);
231238
updatedEnvVars.put("GAE_ENV", "standard");
232-
GCPResource testResource = new GCPResource(metadataConfig, new EnvVarMock(updatedEnvVars));
239+
GCPResourceDetector testResource =
240+
new GCPResourceDetector(metadataConfig, new EnvVarMock(updatedEnvVars));
233241
assertThat(testResource.getAttributes())
234242
.hasSize(7)
235243
.containsEntry(

e2e-test-server/src/main/java/com/google/cloud/opentelemetry/endtoend/ScenarioHandlerManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.cloud.opentelemetry.endtoend;
1717

18-
import com.google.cloud.opentelemetry.detectors.GCPResource;
18+
import com.google.cloud.opentelemetry.detectors.GCPResourceDetector;
1919
import com.google.cloud.opentelemetry.propagators.XCloudTraceContextPropagator;
2020
import com.google.cloud.opentelemetry.trace.TraceConfiguration;
2121
import com.google.cloud.opentelemetry.trace.TraceExporter;
@@ -89,7 +89,7 @@ private Response basicTrace(Request request) {
8989
private Response detectResource(Request request) {
9090
LOGGER.info("Running detectResource test, request: " + request.toString());
9191
Resource gcpResource =
92-
new GCPResource()
92+
new GCPResourceDetector()
9393
.createResource(
9494
DefaultConfigProperties.create(
9595
Map.of("otel.traces.exporter", "none", "otel.metrics.exporter", "none")));

examples/resource/src/main/java/com/google/cloud/opentelemetry/example/resource/ResourceExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.cloud.opentelemetry.example.resource;
1717

18-
import com.google.cloud.opentelemetry.detectors.GCPResource;
18+
import com.google.cloud.opentelemetry.detectors.GCPResourceDetector;
1919
import io.opentelemetry.sdk.autoconfigure.ResourceConfiguration;
2020
import io.opentelemetry.sdk.resources.Resource;
2121

@@ -25,7 +25,7 @@ public static void main(String[] args) {
2525
Resource autoResource = ResourceConfiguration.createEnvironmentResource();
2626
System.out.println(autoResource.getAttributes());
2727
System.out.println("Detecting resource: hardcoded");
28-
GCPResource resource = new GCPResource();
29-
System.out.println(resource.getAttributes());
28+
GCPResourceDetector resourceDetector = new GCPResourceDetector();
29+
System.out.println(resourceDetector.getAttributes());
3030
}
3131
}

0 commit comments

Comments
 (0)