diff --git a/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java b/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java index 9b1ee3ffc635..85d2418455ca 100644 --- a/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java +++ b/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java @@ -57,6 +57,14 @@ public static String getClusterName() { return getAttribute("instance/attributes/cluster-name"); } + public static String getContainerName(){ + return getAttribute("instance/attributes/container-name"); + } + + public static String getNamespaceId(){ + return getAttribute("instance/attributes/namespace-id"); + } + public static String getAttribute(String attributeName) { try { URL url = new URL(METADATA_URL + attributeName); diff --git a/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java b/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java index 5af50769ec20..e8f52f633181 100644 --- a/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java +++ b/google-cloud-clients/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java @@ -38,9 +38,11 @@ public class MonitoredResourceUtil { private enum Label { AppId("app_id"), ClusterName("cluster_name"), + ContainerName("container_name"), InstanceId("instance_id"), InstanceName("instance_name"), ModuleId("module_id"), + NamespaceId("namespace_id"), PodId("pod_id"), ProjectId("project_id"), VersionId("version_id"), @@ -84,7 +86,9 @@ String getKey() { .putAll( Resource.Container.getKey(), Label.ClusterName, + Label.ContainerName, Label.InstanceId, + Label.NamespaceId, Label.PodId, Label.Zone) .putAll(Resource.GceInstance.getKey(), Label.InstanceId, Label.Zone) @@ -135,6 +139,9 @@ private static String getValue(Label label) { case ClusterName: value = MetadataConfig.getClusterName(); break; + case ContainerName: + value = MetadataConfig.getContainerName(); + break; case InstanceId: value = MetadataConfig.getInstanceId(); break; @@ -144,6 +151,9 @@ private static String getValue(Label label) { case ModuleId: value = getAppEngineModuleId(); break; + case NamespaceId: + value = MetadataConfig.getNamespaceId(); + break; case PodId: value = System.getenv("HOSTNAME"); break;