From 811f9aa409ec922402cb83a6753812518b7a0d4b Mon Sep 17 00:00:00 2001 From: Vinay B S Date: Tue, 2 Mar 2021 16:12:04 -0500 Subject: [PATCH] feat: Adding labels to the metric descriptor in the snippets.py (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps understand how to add labels for custom metrics [1]. [1] https://cloud.google.com/monitoring/custom-metrics/creating-metrics#create-metric-desc Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-monitoring/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #86 🦕 --- samples/snippets/v3/cloud-client/snippets.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/snippets/v3/cloud-client/snippets.py b/samples/snippets/v3/cloud-client/snippets.py index 1c0407a2..19654e32 100644 --- a/samples/snippets/v3/cloud-client/snippets.py +++ b/samples/snippets/v3/cloud-client/snippets.py @@ -19,6 +19,7 @@ import uuid from google.api import metric_pb2 as ga_metric +from google.api import label_pb2 as ga_label from google.cloud import monitoring_v3 @@ -34,6 +35,13 @@ def create_metric_descriptor(project_id): descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE descriptor.value_type = ga_metric.MetricDescriptor.ValueType.DOUBLE descriptor.description = "This is a simple example of a custom metric." + + labels = ga_label.LabelDescriptor() + labels.key = "TestLabel" + labels.value_type = ga_label.LabelDescriptor.ValueType.STRING + labels.description = "This is a test label" + descriptor.labels.append(labels) + descriptor = client.create_metric_descriptor( name=project_name, metric_descriptor=descriptor )