Skip to content

Commit 7003c86

Browse files
authored
---
yaml --- r: 9029 b: refs/heads/lesv-patch-1 c: 6c773d2 h: refs/heads/master i: 9027: d5f3dbd
1 parent 22ff16c commit 7003c86

3 files changed

Lines changed: 24 additions & 30 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ refs/tags/v0.22.0: 18b298fe4bfe8ec2f20b0e0bf7ffdcce5cc3c5fe
6666
refs/heads/vam-google-patch-1: d0c8fee3a4074d0bf7360ce8c4f7f7223d0ee7b9
6767
refs/heads/vam-google-patch-CODEOWNERS: 2ac1616e25229e51d08a984708ef1918f91a35ee
6868
refs/heads/danoscarmike-patch-1: 7342a9916bce4ed00002c7202e2a16c5d46afaea
69-
refs/heads/lesv-patch-1: 8bb2a593f2d4f77647cd7115ec6319ed15e7be41
69+
refs/heads/lesv-patch-1: 6c773d28a6419a90ef44de72fda7dae8e855a711
7070
refs/heads/ml-update-branch: 079dd6610017f5c51b9d1938c12d6d55b61513cf
7171
refs/heads/vkedia-patch-2: 7d8241388a9769a5c069334761b06c7012c878e7
7272
refs/heads/vkedia-patch-3: 4d128043acaa7db9160faf439d2ca6104e8a88cb

branches/lesv-patch-1/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static String getInstanceId() {
5454
}
5555

5656
public static String getClusterName() {
57-
return getAttribute("instance/cluster-name");
57+
return getAttribute("instance/attributes/cluster-name");
5858
}
5959

6060
private static String getAttribute(String attributeName) {

branches/lesv-patch-1/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import com.google.cloud.ServiceOptions;
2222
import com.google.cloud.logging.LogEntry.Builder;
2323
import com.google.common.base.Strings;
24-
import com.google.common.collect.ImmutableMap;
25-
24+
import com.google.common.collect.ImmutableMultimap;
2625
import java.util.ArrayList;
2726
import java.util.Collections;
2827
import java.util.HashMap;
@@ -42,6 +41,7 @@ private enum Label {
4241
InstanceId("instance_id"),
4342
InstanceName("instance_name"),
4443
ModuleId("module_id"),
44+
PodId("pod_id"),
4545
ProjectId("project_id"),
4646
VersionId("version_id"),
4747
Zone("zone");
@@ -77,25 +77,18 @@ String getKey() {
7777

7878
private static final String APPENGINE_LABEL_PREFIX = "appengine.googleapis.com/";
7979

80-
private static Map<String, Label[]> resourceTypeWithLabels;
81-
82-
static {
83-
resourceTypeWithLabels =
84-
new ImmutableMap.Builder<String, Label[]>()
85-
.put(
86-
Resource.GaeAppFlex.getKey(),
87-
new Label[] {
88-
Label.ModuleId,
89-
Label.VersionId,
90-
Label.Zone
91-
})
92-
.put(
93-
Resource.GaeAppStandard.getKey(),
94-
new Label[] {Label.ModuleId, Label.VersionId})
95-
.put(Resource.Container.getKey(), new Label[] {Label.ClusterName, Label.Zone})
96-
.put(Resource.GceInstance.getKey(), new Label[] {Label.InstanceId, Label.Zone})
97-
.build();
98-
}
80+
private static ImmutableMultimap<String, Label> resourceTypeWithLabels =
81+
ImmutableMultimap.<String, Label>builder()
82+
.putAll(Resource.GaeAppFlex.getKey(), Label.ModuleId, Label.VersionId, Label.Zone)
83+
.putAll(Resource.GaeAppStandard.getKey(), Label.ModuleId, Label.VersionId)
84+
.putAll(
85+
Resource.Container.getKey(),
86+
Label.ClusterName,
87+
Label.InstanceId,
88+
Label.PodId,
89+
Label.Zone)
90+
.putAll(Resource.GceInstance.getKey(), Label.InstanceId, Label.Zone)
91+
.build();
9992

10093
private MonitoredResourceUtil() {
10194
}
@@ -113,13 +106,11 @@ public static MonitoredResource getResource(String projectId, String resourceTyp
113106
String resourceName = resourceType.startsWith("gae_app") ? "gae_app" : resourceType;
114107
MonitoredResource.Builder builder =
115108
MonitoredResource.newBuilder(resourceName).addLabel(Label.ProjectId.getKey(), projectId);
116-
Label[] resourceLabels = resourceTypeWithLabels.get(resourceType);
117-
if (resourceLabels != null) {
118-
for (Label label : resourceLabels) {
119-
String value = getValue(label);
120-
if (value != null) {
121-
builder.addLabel(label.getKey(), value);
122-
}
109+
110+
for (Label label : resourceTypeWithLabels.get(resourceType)) {
111+
String value = getValue(label);
112+
if (value != null) {
113+
builder.addLabel(label.getKey(), value);
123114
}
124115
}
125116
return builder.build();
@@ -153,6 +144,9 @@ private static String getValue(Label label) {
153144
case ModuleId:
154145
value = getAppEngineModuleId();
155146
break;
147+
case PodId:
148+
value = System.getenv("HOSTNAME");
149+
break;
156150
case VersionId:
157151
value = getAppEngineVersionId();
158152
break;

0 commit comments

Comments
 (0)