This repository was archived by the owner on Dec 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 194
Deprecate MonitoredResource and change to use Resource. #1718
Merged
bogdandrutu
merged 4 commits into
census-instrumentation:master
from
bogdandrutu:monitored
Jan 30, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
890f141
Deprecate MonitoredResource and change to use Resource.
bogdandrutu a53aa5b
Fix deprecated usages and imports.
bogdandrutu 91f8e45
Resolve more deprecation usage warnings.
bogdandrutu 53cf379
Use full class names for deprecated classes
bogdandrutu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...il/src/main/java/io/opencensus/contrib/monitoredresource/util/AwsEc2InstanceResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Copyright 2019, OpenCensus Authors | ||
| * | ||
| * 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 io.opencensus.contrib.monitoredresource.util; | ||
|
|
||
| import static com.google.common.base.MoreObjects.firstNonNull; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import io.opencensus.resource.Resource; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Helper class for AWS EC2 instances {@code Resource}. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public final class AwsEc2InstanceResource { | ||
| private static final String ACCOUNT_ID = | ||
| firstNonNull(AwsIdentityDocUtils.getValueFromAwsIdentityDocument("accountId"), ""); | ||
| private static final String INSTANCE_ID = | ||
| firstNonNull(AwsIdentityDocUtils.getValueFromAwsIdentityDocument("instanceId"), ""); | ||
| private static final String REGION = | ||
| firstNonNull(AwsIdentityDocUtils.getValueFromAwsIdentityDocument("region"), ""); | ||
|
|
||
| /** | ||
| * AWS key that represents a type of the resource. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String TYPE = "aws.com/ec2/instance"; | ||
|
|
||
| /** | ||
| * AWS key that represents the AWS account number for the VM. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String ACCOUNT_ID_KEY = "aws.com/ec2/account_id"; | ||
|
|
||
| /** | ||
| * AWS key that represents the VM instance identifier assigned by AWS. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String INSTANCE_ID_KEY = "aws.com/ec2/instance_id"; | ||
|
|
||
| /** | ||
| * AWS key that represents a region for the VM. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String REGION_KEY = "aws.com/ec2/region"; | ||
|
|
||
| /** | ||
| * Returns a {@link Resource} that describes a aws ec2 instance. | ||
| * | ||
| * @param accountId the AWS account ID. | ||
| * @param region the AWS region. | ||
| * @param instanceId the AWS EC2 instance ID. | ||
| * @return a {@link Resource} that describes a aws ec2 instance. | ||
| * @since 0.20 | ||
| */ | ||
| public static Resource create(String accountId, String region, String instanceId) { | ||
| Map<String, String> mutableLabels = new LinkedHashMap<String, String>(); | ||
| mutableLabels.put(ACCOUNT_ID_KEY, checkNotNull(accountId, "accountId")); | ||
| mutableLabels.put(REGION_KEY, checkNotNull(region, "region")); | ||
| mutableLabels.put(INSTANCE_ID_KEY, checkNotNull(instanceId, "instanceId")); | ||
| return Resource.create(TYPE, Collections.unmodifiableMap(mutableLabels)); | ||
| } | ||
|
|
||
| static Resource detect() { | ||
| return create(ACCOUNT_ID, REGION, INSTANCE_ID); | ||
| } | ||
|
|
||
| private AwsEc2InstanceResource() {} | ||
| } |
87 changes: 87 additions & 0 deletions
87
...il/src/main/java/io/opencensus/contrib/monitoredresource/util/GcpGceInstanceResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Copyright 2019, OpenCensus Authors | ||
| * | ||
| * 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 io.opencensus.contrib.monitoredresource.util; | ||
|
|
||
| import static com.google.common.base.MoreObjects.firstNonNull; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import io.opencensus.resource.Resource; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Helper class for GCP GCE instance {@code Resource}. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public final class GcpGceInstanceResource { | ||
| private static final String PROJECT_ID = firstNonNull(GcpMetadataConfig.getProjectId(), ""); | ||
| private static final String INSTANCE_ID = firstNonNull(GcpMetadataConfig.getInstanceId(), ""); | ||
| private static final String ZONE = firstNonNull(GcpMetadataConfig.getZone(), ""); | ||
|
|
||
| /** | ||
| * GCP GCE key that represents a type of the resource. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String TYPE = "cloud.google.com/gce/instance"; | ||
|
|
||
| /** | ||
| * GCP GCE key that represents the GCP account number for the instance. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String PROJECT_ID_KEY = "cloud.google.com/gce/project_id"; | ||
|
|
||
| /** | ||
| * GCP GCE key that represents the numeric VM instance identifier assigned by GCE. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String INSTANCE_ID_KEY = "cloud.google.com/gce/instance_id"; | ||
|
|
||
| /** | ||
| * GCP GCE key that represents the GCE zone in which the VM is running. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String ZONE_KEY = "cloud.google.com/gce/zone"; | ||
|
|
||
| /** | ||
| * Returns a {@link Resource} that describes a k8s container. | ||
| * | ||
| * @param projectId the GCP project number. | ||
| * @param zone the GCP zone. | ||
| * @param instanceId the GCP GCE instance ID. | ||
| * @return a {@link Resource} that describes a k8s container. | ||
| * @since 0.20 | ||
| */ | ||
| public static Resource create(String projectId, String zone, String instanceId) { | ||
| Map<String, String> mutableLabels = new LinkedHashMap<String, String>(); | ||
| mutableLabels.put(PROJECT_ID_KEY, checkNotNull(projectId, "projectId")); | ||
| mutableLabels.put(ZONE_KEY, checkNotNull(zone, "zone")); | ||
| mutableLabels.put(INSTANCE_ID_KEY, checkNotNull(instanceId, "instanceId")); | ||
| return Resource.create(TYPE, Collections.unmodifiableMap(mutableLabels)); | ||
| } | ||
|
|
||
| static Resource detect() { | ||
| return create(PROJECT_ID, ZONE, INSTANCE_ID); | ||
| } | ||
|
|
||
| private GcpGceInstanceResource() {} | ||
| } |
100 changes: 100 additions & 0 deletions
100
...util/src/main/java/io/opencensus/contrib/monitoredresource/util/K8sContainerResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright 2019, OpenCensus Authors | ||
| * | ||
| * 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 io.opencensus.contrib.monitoredresource.util; | ||
|
|
||
| import static com.google.common.base.MoreObjects.firstNonNull; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import io.opencensus.resource.Resource; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Helper class for K8S container {@code Resource}. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public class K8sContainerResource { | ||
| private static final String CLUSTER_NAME = firstNonNull(GcpMetadataConfig.getClusterName(), ""); | ||
| private static final String CONTAINER_NAME = firstNonNull(System.getenv("CONTAINER_NAME"), ""); | ||
| private static final String NAMESPACE_NAME = firstNonNull(System.getenv("NAMESPACE"), ""); | ||
| private static final String POD_NAME = firstNonNull(System.getenv("HOSTNAME"), ""); | ||
|
|
||
| /** | ||
| * Kubernetes resources key that represents a type of the resource. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String TYPE = "k8s.io/container"; | ||
|
|
||
| /** | ||
| * Kubernetes resources key that represents the name for the cluster the container is running in. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String CLUSTER_NAME_KEY = "k8s.io/cluster/name"; | ||
|
|
||
| /** | ||
| * Kubernetes resources key that represents the identifier for the GCE instance the container is | ||
| * running in. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String NAMESPACE_NAME_KEY = "k8s.io/namespace/name"; | ||
|
|
||
| /** | ||
| * Kubernetes resources key that represents the identifier for the pod the container is running | ||
| * in. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String POD_NAME_KEY = "k8s.io/pod/name"; | ||
|
|
||
| /** | ||
| * Kubernetes resources key that represents the name of the container. | ||
| * | ||
| * @since 0.20 | ||
| */ | ||
| public static final String CONTAINER_NAME_KEY = "k8s.io/container/name"; | ||
|
|
||
| /** | ||
| * Returns a {@link Resource} that describes a k8s container. | ||
| * | ||
| * @param clusterName the k8s cluster name. | ||
| * @param namespace the k8s namespace. | ||
| * @param podName the k8s pod name. | ||
| * @param containerName the k8s container name. | ||
| * @return a {@link Resource} that describes a k8s container. | ||
| * @since 0.20 | ||
| */ | ||
| public static Resource create( | ||
| String clusterName, String namespace, String podName, String containerName) { | ||
| Map<String, String> mutableLabels = new LinkedHashMap<String, String>(); | ||
| mutableLabels.put(CLUSTER_NAME_KEY, checkNotNull(clusterName, "clusterName")); | ||
| mutableLabels.put(NAMESPACE_NAME_KEY, checkNotNull(namespace, "namespace")); | ||
| mutableLabels.put(POD_NAME_KEY, checkNotNull(podName, "podName")); | ||
| mutableLabels.put(CONTAINER_NAME_KEY, checkNotNull(containerName, "containerName")); | ||
| return Resource.create(TYPE, Collections.unmodifiableMap(mutableLabels)); | ||
| } | ||
|
|
||
| static Resource detect() { | ||
| return create(CLUSTER_NAME, NAMESPACE_NAME, POD_NAME, CONTAINER_NAME); | ||
| } | ||
|
|
||
| private K8sContainerResource() {} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
project,instance-idandzonedo not apply to the k8s resource?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not related to k8s resource, but when we do autodetection if the pod/container runs on a GCE instance they will be added in the resource merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, make sense.