Skip to content

Commit 6765b35

Browse files
vinbsdandhlee
authored andcommitted
feat: Adding labels to the metric descriptor in the snippets.py (#88)
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 🦕
1 parent 4f15714 commit 6765b35

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

monitoring/snippets/v3/cloud-client/snippets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import uuid
2020

2121
from google.api import metric_pb2 as ga_metric
22+
from google.api import label_pb2 as ga_label
2223
from google.cloud import monitoring_v3
2324

2425

@@ -34,6 +35,13 @@ def create_metric_descriptor(project_id):
3435
descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE
3536
descriptor.value_type = ga_metric.MetricDescriptor.ValueType.DOUBLE
3637
descriptor.description = "This is a simple example of a custom metric."
38+
39+
labels = ga_label.LabelDescriptor()
40+
labels.key = "TestLabel"
41+
labels.value_type = ga_label.LabelDescriptor.ValueType.STRING
42+
labels.description = "This is a test label"
43+
descriptor.labels.append(labels)
44+
3745
descriptor = client.create_metric_descriptor(
3846
name=project_name, metric_descriptor=descriptor
3947
)

0 commit comments

Comments
 (0)