Skip to content

Commit

Permalink
Rename support package: detectors -> detection
Browse files Browse the repository at this point in the history
Support library was using the same package as the detectors library.
This rename would avoid potential conflicts and import issues.
  • Loading branch information
psx95 committed Jan 11, 2024
1 parent 4d577f0 commit d529469
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

/**
* Contains constants that act as keys for the known attributes for {@link
* com.google.cloud.opentelemetry.detectors.GCPPlatformDetector.SupportedPlatform}s.
* GCPPlatformDetector.SupportedPlatform}s.
*/
public final class AttributeKeys {
// GCE Attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

/**
* Provides API to fetch environment variables. This is useful in order to create a mock class for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

public class GCPPlatformDetector {
public static final GCPPlatformDetector DEFAULT_INSTANCE = new GCPPlatformDetector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GAE_APP_VERSION;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GAE_AVAILABILITY_ZONE;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GAE_CLOUD_REGION;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GAE_INSTANCE_ID;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GAE_MODULE_NAME;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

class GoogleCloudFunction extends GoogleServerlessCompute {
GoogleCloudFunction(EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

class GoogleCloudRun extends GoogleServerlessCompute {
GoogleCloudRun(EnvironmentVariables environmentVariables, GCPMetadataConfig metadataConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;

import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GCE_AVAILABILITY_ZONE;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GCE_CLOUD_REGION;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GCE_INSTANCE_HOSTNAME;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GCE_INSTANCE_ID;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GCE_INSTANCE_NAME;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GCE_MACHINE_TYPE;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GKE_CLUSTER_LOCATION;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GKE_CLUSTER_LOCATION_TYPE;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GKE_CLUSTER_NAME;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GKE_HOST_ID;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GKE_LOCATION_TYPE_REGION;
import static com.google.cloud.opentelemetry.detectors.AttributeKeys.GKE_LOCATION_TYPE_ZONE;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import java.util.Collections;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import java.util.Collections;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import static com.google.cloud.opentelemetry.detectors.TestUtils.stubEndpoint;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.github.tomakehurst.wiremock.junit5.WireMockTest;
Expand Down Expand Up @@ -43,15 +42,15 @@ class GCPMetadataConfigTest {

@BeforeEach
public void setupMockMetadataConfig() {
stubEndpoint("/project/project-id", mockProjectId);
stubEndpoint("/instance/zone", mockZone);
stubEndpoint("/instance/region", mockRegion);
stubEndpoint("/instance/id", mockInstanceId);
stubEndpoint("/instance/name", mockInstanceName);
stubEndpoint("/instance/machine-type", mockInstanceType);
stubEndpoint("/instance/attributes/cluster-name", mockClusterName);
stubEndpoint("/instance/attributes/cluster-location", mockClusterLocation);
stubEndpoint("/instance/hostname", mockHostname);
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
Expand All @@ -63,7 +62,7 @@ void testGetProjectId() {
@ParameterizedTest
@MethodSource("provideZoneRetrievalArguments")
void testGetZone(String stubbedMockZone, String expectedMockZone) {
stubEndpoint("/instance/zone", stubbedMockZone);
TestUtils.stubEndpoint("/instance/zone", stubbedMockZone);
assertEquals(expectedMockZone, mockMetadataConfig.getZone());
}

Expand All @@ -80,7 +79,7 @@ private static Stream<Arguments> provideZoneRetrievalArguments() {
@ParameterizedTest
@MethodSource("provideRegionRetrievalArguments")
void testGetRegion(String stubbedMockRegion, String expectedMockRegion) {
stubEndpoint("/instance/region", stubbedMockRegion);
TestUtils.stubEndpoint("/instance/region", stubbedMockRegion);
assertEquals(expectedMockRegion, mockMetadataConfig.getRegion());
}

Expand All @@ -96,7 +95,7 @@ private static Stream<Arguments> provideRegionRetrievalArguments() {
@ParameterizedTest
@MethodSource("provideZoneArguments")
void testGetRegionFromZone(String stubbedMockZone, String expectedRegion) {
stubEndpoint("/instance/zone", stubbedMockZone);
TestUtils.stubEndpoint("/instance/zone", stubbedMockZone);
assertEquals(expectedRegion, mockMetadataConfig.getRegionFromZone());
}

Expand All @@ -113,7 +112,7 @@ private static Stream<Arguments> provideZoneArguments() {
@ParameterizedTest
@MethodSource("provideMachineTypeRetrievalArguments")
void testGetMachineType(String stubbedMockMachineType, String expectedMockMachineType) {
stubEndpoint("/instance/machine-type", stubbedMockMachineType);
TestUtils.stubEndpoint("/instance/machine-type", stubbedMockMachineType);
assertEquals(expectedMockMachineType, mockMetadataConfig.getMachineType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
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.detectors.AttributeKeys.*;
import static com.google.cloud.opentelemetry.detectors.TestUtils.stubEndpoint;
import static com.google.cloud.opentelemetry.detection.AttributeKeys.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

Expand Down Expand Up @@ -83,12 +82,12 @@ public void testGCPComputeResourceNonGCPEndpoint() {
/** Google Compute Engine Tests * */
@Test
public void testGCEResourceWithGCEAttributesSucceeds() {
stubEndpoint("/project/project-id", "GCE-pid");
stubEndpoint("/instance/zone", "country-gce_region-gce_zone");
stubEndpoint("/instance/id", "GCE-instance-id");
stubEndpoint("/instance/name", "GCE-instance-name");
stubEndpoint("/instance/machine-type", "GCE-instance-type");
stubEndpoint("/instance/hostname", "GCE-instance-hostname");
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));
Expand Down Expand Up @@ -119,12 +118,12 @@ public void testGKEResourceWithGKEAttributesSucceedsLocationZone() {
envVars.put("POD_NAME", "GKE-testHostName-full-1234");
envVars.put("CONTAINER_NAME", "GKE-testContainerName");

stubEndpoint("/project/project-id", "GKE-pid");
stubEndpoint("/instance/id", "GKE-instance-id");
stubEndpoint("/instance/name", "instance-name");
stubEndpoint("/instance/machine-type", "instance-type");
stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name");
stubEndpoint("/instance/attributes/cluster-location", "country-region-zone");
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);
Expand Down Expand Up @@ -153,12 +152,12 @@ public void testGKEResourceWithGKEAttributesSucceedsLocationRegion() {
envVars.put("POD_NAME", "GKE-testHostName-full-1234");
envVars.put("CONTAINER_NAME", "GKE-testContainerName");

stubEndpoint("/project/project-id", "GKE-pid");
stubEndpoint("/instance/id", "GKE-instance-id");
stubEndpoint("/instance/name", "GCE-instance-name");
stubEndpoint("/instance/machine-type", "GKE-instance-type");
stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name");
stubEndpoint("/instance/attributes/cluster-location", "country-region");
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);
Expand Down Expand Up @@ -189,12 +188,12 @@ public void testGKEResourceDetectionWithInvalidLocations(String clusterLocation)
envVars.put("POD_NAME", "GKE-testHostName-full-1234");
envVars.put("CONTAINER_NAME", "GKE-testContainerName");

stubEndpoint("/project/project-id", "GKE-pid");
stubEndpoint("/instance/id", "GKE-instance-id");
stubEndpoint("/instance/name", "GKE-instance-name");
stubEndpoint("/instance/machine-type", "GKE-instance-type");
stubEndpoint("/instance/attributes/cluster-name", "GKE-cluster-name");
stubEndpoint("/instance/attributes/cluster-location", clusterLocation);
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);
Expand Down Expand Up @@ -226,9 +225,9 @@ public void testGCFResourceWithCloudFunctionAttributesSucceeds() {
envVars.put("K_REVISION", "cloud-function-hello.1");
envVars.put("FUNCTION_TARGET", "cloud-function-hello");

stubEndpoint("/project/project-id", "GCF-pid");
stubEndpoint("/instance/zone", "country-region-zone");
stubEndpoint("/instance/id", "GCF-instance-id");
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);
Expand Down Expand Up @@ -259,9 +258,9 @@ public void testGCFDetectionWhenGCRAttributesPresent() {
// This should be ignored and detected platform should still be GCF
envVars.put("K_CONFIGURATION", "cloud-run-hello");

stubEndpoint("/project/project-id", "GCF-pid");
stubEndpoint("/instance/zone", "country-region-zone");
stubEndpoint("/instance/id", "GCF-instance-id");
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);
Expand All @@ -283,9 +282,9 @@ public void testGCFResourceWithCloudRunAttributesSucceeds() {
envVars.put("K_REVISION", "cloud-run-hello.1");
envVars.put("K_CONFIGURATION", "cloud-run-hello");

stubEndpoint("/project/project-id", "GCR-pid");
stubEndpoint("/instance/zone", "country-region-zone");
stubEndpoint("/instance/id", "GCR-instance-id");
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);
Expand Down Expand Up @@ -316,11 +315,11 @@ public void testGAEResourceWithAppEngineAttributesSucceeds(String gaeEnvironment
envVars.put("GAE_INSTANCE", "app-engine-hello-f236d");
envVars.put("GAE_ENV", gaeEnvironmentVar);

stubEndpoint("/project/project-id", "GAE-pid");
TestUtils.stubEndpoint("/project/project-id", "GAE-pid");
// for standard, the region should be extracted from region attribute
stubEndpoint("/instance/zone", "country-region-zone");
stubEndpoint("/instance/region", "country-region1");
stubEndpoint("/instance/id", "GAE-instance-id");
TestUtils.stubEndpoint("/instance/zone", "country-region-zone");
TestUtils.stubEndpoint("/instance/region", "country-region1");
TestUtils.stubEndpoint("/instance/id", "GAE-instance-id");

EnvironmentVariables mockEnv = new EnvVarMock(envVars);
GCPPlatformDetector detector = new GCPPlatformDetector(mockMetadataConfig, mockEnv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.opentelemetry.detectors;
package com.google.cloud.opentelemetry.detection;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
Expand Down
Loading

0 comments on commit d529469

Please sign in to comment.