From a7dd6708441275c6a8059248ccd0e894685d1b17 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Wed, 19 Sep 2018 11:50:02 -0700 Subject: [PATCH 1/3] Monitored Resource: replace gke_container with k8s_container in SD exporter --- .../stats/stackdriver/StackdriverExportUtils.java | 8 ++++---- .../trace/stackdriver/StackdriverV2ExporterHandler.java | 8 ++++---- .../StackdriverV2ExporterHandlerProtoTest.java | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java index 93f287c6d8..5827e2b516 100644 --- a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java +++ b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java @@ -81,7 +81,7 @@ final class StackdriverExportUtils { @VisibleForTesting static final String LABEL_DESCRIPTION = "OpenCensus TagKey"; @VisibleForTesting static final String OPENCENSUS_TASK = "opencensus_task"; @VisibleForTesting static final String OPENCENSUS_TASK_DESCRIPTION = "Opencensus task identifier"; - private static final String GCP_GKE_CONTAINER = "gke_container"; + private static final String GCP_GKE_CONTAINER = "k8s_container"; private static final String GCP_GCE_INSTANCE = "gce_instance"; private static final String AWS_EC2_INSTANCE = "aws_ec2_instance"; private static final String GLOBAL = "global"; @@ -499,10 +499,10 @@ private static void setMonitoredResourceLabelsForBuilder( builder.putLabels(PROJECT_ID_LABEL_KEY, gcpGkeContainerMonitoredResource.getAccount()); builder.putLabels("cluster_name", gcpGkeContainerMonitoredResource.getClusterName()); builder.putLabels("container_name", gcpGkeContainerMonitoredResource.getContainerName()); - builder.putLabels("namespace_id", gcpGkeContainerMonitoredResource.getNamespaceId()); + builder.putLabels("namespace_name", gcpGkeContainerMonitoredResource.getNamespaceId()); builder.putLabels("instance_id", gcpGkeContainerMonitoredResource.getInstanceId()); - builder.putLabels("pod_id", gcpGkeContainerMonitoredResource.getPodId()); - builder.putLabels("zone", gcpGkeContainerMonitoredResource.getZone()); + builder.putLabels("pod_name", gcpGkeContainerMonitoredResource.getPodId()); + builder.putLabels("location", gcpGkeContainerMonitoredResource.getZone()); return; case AWS_EC2_INSTANCE: AwsEc2InstanceMonitoredResource awsEc2InstanceMonitoredResource = diff --git a/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java b/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java index 9237ded598..acaeef8037 100644 --- a/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java +++ b/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java @@ -348,7 +348,7 @@ static Map getResourceLabels( "instance_id", gcpGkeContainerMonitoredResource.getInstanceId()); putToResourceAttributeMap( - resourceLabels, resourceType, "zone", gcpGkeContainerMonitoredResource.getZone()); + resourceLabels, resourceType, "location", gcpGkeContainerMonitoredResource.getZone()); putToResourceAttributeMap( resourceLabels, resourceType, @@ -362,10 +362,10 @@ static Map getResourceLabels( putToResourceAttributeMap( resourceLabels, resourceType, - "namespace_id", + "namespace_name", gcpGkeContainerMonitoredResource.getNamespaceId()); putToResourceAttributeMap( - resourceLabels, resourceType, "pod_id", gcpGkeContainerMonitoredResource.getPodId()); + resourceLabels, resourceType, "pod_name", gcpGkeContainerMonitoredResource.getPodId()); return Collections.unmodifiableMap(resourceLabels); } return Collections.emptyMap(); @@ -391,7 +391,7 @@ private static String mapToStringResourceType(ResourceType resourceType) { case GCP_GCE_INSTANCE: return "gce_instance"; case GCP_GKE_CONTAINER: - return "gke_container"; + return "k8s_container"; case AWS_EC2_INSTANCE: return "aws_ec2_instance"; } diff --git a/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java b/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java index bb0ba07228..ef03e27d51 100644 --- a/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java +++ b/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java @@ -166,16 +166,16 @@ public final class StackdriverV2ExporterHandlerProtoTest { createResourceLabelKey(GCP_GKE_CONTAINER, "container_name"), toStringAttributeValueProto("container")) .put( - createResourceLabelKey(GCP_GKE_CONTAINER, "namespace_id"), + createResourceLabelKey(GCP_GKE_CONTAINER, "namespace_name"), toStringAttributeValueProto("namespace")) .put( createResourceLabelKey(GCP_GKE_CONTAINER, "instance_id"), toStringAttributeValueProto("my-instance")) .put( - createResourceLabelKey(GCP_GKE_CONTAINER, "pod_id"), + createResourceLabelKey(GCP_GKE_CONTAINER, "pod_name"), toStringAttributeValueProto("pod")) .put( - createResourceLabelKey(GCP_GKE_CONTAINER, "zone"), + createResourceLabelKey(GCP_GKE_CONTAINER, "location"), toStringAttributeValueProto("us-east1")) .build(); From a3dd70616bb8c02a750190dcbae6a377966d22ae Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Thu, 20 Sep 2018 10:35:11 -0700 Subject: [PATCH 2/3] remove instance_id from trace k8s_container --- .../exporter/stats/stackdriver/StackdriverExportUtils.java | 1 - .../trace/stackdriver/StackdriverV2ExporterHandler.java | 5 ----- .../stackdriver/StackdriverV2ExporterHandlerProtoTest.java | 3 --- 3 files changed, 9 deletions(-) diff --git a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java index 5827e2b516..4f8715b0b1 100644 --- a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java +++ b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java @@ -500,7 +500,6 @@ private static void setMonitoredResourceLabelsForBuilder( builder.putLabels("cluster_name", gcpGkeContainerMonitoredResource.getClusterName()); builder.putLabels("container_name", gcpGkeContainerMonitoredResource.getContainerName()); builder.putLabels("namespace_name", gcpGkeContainerMonitoredResource.getNamespaceId()); - builder.putLabels("instance_id", gcpGkeContainerMonitoredResource.getInstanceId()); builder.putLabels("pod_name", gcpGkeContainerMonitoredResource.getPodId()); builder.putLabels("location", gcpGkeContainerMonitoredResource.getZone()); return; diff --git a/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java b/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java index acaeef8037..de022c3fb9 100644 --- a/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java +++ b/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandler.java @@ -342,11 +342,6 @@ static Map getResourceLabels( resourceType, "project_id", gcpGkeContainerMonitoredResource.getAccount()); - putToResourceAttributeMap( - resourceLabels, - resourceType, - "instance_id", - gcpGkeContainerMonitoredResource.getInstanceId()); putToResourceAttributeMap( resourceLabels, resourceType, "location", gcpGkeContainerMonitoredResource.getZone()); putToResourceAttributeMap( diff --git a/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java b/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java index ef03e27d51..8b28dc06ef 100644 --- a/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java +++ b/exporters/trace/stackdriver/src/test/java/io/opencensus/exporter/trace/stackdriver/StackdriverV2ExporterHandlerProtoTest.java @@ -168,9 +168,6 @@ public final class StackdriverV2ExporterHandlerProtoTest { .put( createResourceLabelKey(GCP_GKE_CONTAINER, "namespace_name"), toStringAttributeValueProto("namespace")) - .put( - createResourceLabelKey(GCP_GKE_CONTAINER, "instance_id"), - toStringAttributeValueProto("my-instance")) .put( createResourceLabelKey(GCP_GKE_CONTAINER, "pod_name"), toStringAttributeValueProto("pod")) From 64a20cea9ba013419c6d57b0612541f68e7a908c Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Fri, 21 Sep 2018 15:28:18 -0700 Subject: [PATCH 3/3] Add CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be1ad8be14..4e4d3af90d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - Add an API `Functions.returnToString()`. - Add `opencensus-contrib-opencensus-proto-util` that has helper utilities to convert between Java data models and protos. +- Migrate to new Stackdriver Kubernetes monitored resource. This could be a breaking change + if you are using `gke_container` resources. For more info, + https://cloud.google.com/monitoring/kubernetes-engine/migration#incompatible ## 0.16.1 - 2018-09-18 - Fix ClassCastException in Log4j log correlation