use of io.opencensus.resource.Resource in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method setResourceForBuilder_GcpInstanceType.
@Test
public void setResourceForBuilder_GcpInstanceType() {
MonitoredResource.Builder monitoredResourceBuilder = DEFAULT_RESOURCE_WITH_PROJECT_ID.clone();
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put(CloudResource.ACCOUNT_ID_KEY, "proj1");
resourceLabels.put(CloudResource.PROVIDER_KEY, CloudResource.PROVIDER_GCP);
resourceLabels.put(HostResource.ID_KEY, "inst1");
resourceLabels.put(CloudResource.ZONE_KEY, "zone1");
resourceLabels.put("extra_key", "must be ignored");
Map<String, String> expectedResourceLabels = new HashMap<String, String>();
expectedResourceLabels.put("project_id", "proj1");
expectedResourceLabels.put("instance_id", "inst1");
expectedResourceLabels.put("zone", "zone1");
Resource resource = Resource.create(HostResource.TYPE, resourceLabels);
StackdriverExportUtils.setResourceForBuilder(monitoredResourceBuilder, resource);
assertThat(monitoredResourceBuilder.getType()).isNotNull();
assertThat(monitoredResourceBuilder.getLabelsMap()).isNotEmpty();
assertThat(monitoredResourceBuilder.getType()).isEqualTo("gce_instance");
assertThat(monitoredResourceBuilder.getLabelsMap().size()).isEqualTo(3);
assertThat(monitoredResourceBuilder.getLabelsMap()).containsExactlyEntriesIn(expectedResourceLabels);
}
use of io.opencensus.resource.Resource in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method setResourceForBuilder_K8sInstanceType.
@Test
public void setResourceForBuilder_K8sInstanceType() {
MonitoredResource.Builder monitoredResourceBuilder = DEFAULT_RESOURCE_WITH_PROJECT_ID.clone();
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put(CloudResource.ZONE_KEY, "zone1");
resourceLabels.put(HostResource.ID_KEY, "instance1");
resourceLabels.put(K8sResource.CLUSTER_NAME_KEY, "cluster1");
resourceLabels.put(ContainerResource.NAME_KEY, "container1");
resourceLabels.put(K8sResource.NAMESPACE_NAME_KEY, "namespace1");
resourceLabels.put(K8sResource.POD_NAME_KEY, "pod1");
resourceLabels.put("extra_key", "must be ignored");
Map<String, String> expectedResourceLabels = new HashMap<String, String>();
expectedResourceLabels.put("project_id", "proj1");
expectedResourceLabels.put("location", "zone1");
expectedResourceLabels.put("cluster_name", "cluster1");
expectedResourceLabels.put("namespace_name", "namespace1");
expectedResourceLabels.put("pod_name", "pod1");
expectedResourceLabels.put("container_name", "container1");
Resource resource = Resource.create(ContainerResource.TYPE, resourceLabels);
StackdriverExportUtils.setResourceForBuilder(monitoredResourceBuilder, resource);
assertThat(monitoredResourceBuilder.getType()).isNotNull();
assertThat(monitoredResourceBuilder.getLabelsMap()).isNotEmpty();
assertThat(monitoredResourceBuilder.getType()).isEqualTo("k8s_container");
assertThat(monitoredResourceBuilder.getLabelsMap().size()).isEqualTo(6);
assertThat(monitoredResourceBuilder.getLabelsMap()).containsExactlyEntriesIn(expectedResourceLabels);
}
use of io.opencensus.resource.Resource in project instrumentation-java by census-instrumentation.
the class ResourceUtilsTest method testDetectResource.
@Test
public void testDetectResource() {
Resource resource = ResourceUtils.detectResource();
if (System.getenv("KUBERNETES_SERVICE_HOST") != null) {
assertThat(resource.getType()).isEqualTo(K8sResource.TYPE);
} else if (GcpMetadataConfig.isRunningOnGcp()) {
assertThat(resource.getType()).isEqualTo(HostResource.TYPE);
assertThat(resource.getLabels().get(CloudResource.PROVIDER_KEY)).isEqualTo(CloudResource.PROVIDER_GCP);
} else if (AwsIdentityDocUtils.isRunningOnAws()) {
assertThat(resource.getType()).isEqualTo(HostResource.TYPE);
assertThat(resource.getLabels().get(CloudResource.PROVIDER_KEY)).isEqualTo(CloudResource.PROVIDER_AWS);
} else {
assertThat(resource).isNotNull();
assertThat(resource.getType()).isNull();
assertThat(resource.getLabels()).isEmpty();
}
}
use of io.opencensus.resource.Resource in project instrumentation-java by census-instrumentation.
the class ContainerResourceTest method create_ContainerResourceTest.
@Test
public void create_ContainerResourceTest() {
Resource resource = ContainerResource.create(NAME, IMAGE_NAME, IMAGE_TAG);
assertThat(resource.getType()).isEqualTo(ContainerResource.TYPE);
assertThat(resource.getLabels()).containsExactly(ContainerResource.NAME_KEY, NAME, ContainerResource.IMAGE_NAME_KEY, IMAGE_NAME, ContainerResource.IMAGE_TAG_KEY, IMAGE_TAG);
}
use of io.opencensus.resource.Resource in project instrumentation-java by census-instrumentation.
the class StackdriverExportUtilsTest method setResourceForBuilder_AwsInstanceType.
@Test
public void setResourceForBuilder_AwsInstanceType() {
MonitoredResource.Builder monitoredResourceBuilder = DEFAULT_RESOURCE_WITH_PROJECT_ID.clone();
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put(CloudResource.REGION_KEY, "region1");
resourceLabels.put(CloudResource.PROVIDER_KEY, CloudResource.PROVIDER_AWS);
resourceLabels.put(CloudResource.ACCOUNT_ID_KEY, "account1");
resourceLabels.put(HostResource.ID_KEY, "instance1");
resourceLabels.put("extra_key", "must be ignored");
Map<String, String> expectedResourceLabels = new HashMap<String, String>();
expectedResourceLabels.put("project_id", "proj1");
expectedResourceLabels.put("instance_id", "instance1");
expectedResourceLabels.put("region", StackdriverExportUtils.AWS_REGION_VALUE_PREFIX + "region1");
expectedResourceLabels.put("aws_account", "account1");
Resource resource = Resource.create(HostResource.TYPE, resourceLabels);
StackdriverExportUtils.setResourceForBuilder(monitoredResourceBuilder, resource);
assertThat(monitoredResourceBuilder.getType()).isNotNull();
assertThat(monitoredResourceBuilder.getLabelsMap()).isNotEmpty();
assertThat(monitoredResourceBuilder.getType()).isEqualTo("aws_ec2_instance");
assertThat(monitoredResourceBuilder.getLabelsMap().size()).isEqualTo(4);
assertThat(monitoredResourceBuilder.getLabelsMap()).containsExactlyEntriesIn(expectedResourceLabels);
}
Aggregations