Skip to content

Commit

Permalink
feat: Adding labels to the metric descriptor in the snippets.py (#88)
Browse files Browse the repository at this point in the history
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  🦕
  • Loading branch information
vinbs authored and dandhlee committed Nov 9, 2022
1 parent 4f15714 commit 6765b35
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions monitoring/snippets/v3/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
)
Expand Down

0 comments on commit 6765b35

Please sign in to comment.