Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Cleanup metric descriptors [(#776)](GoogleCloudPlatform/python-docs-s…
Browse files Browse the repository at this point in the history
  • Loading branch information
waprin authored and Jon Wayne Parrott committed Feb 1, 2017
1 parent 468504f commit 414b609
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion samples/snippets/v3/custom_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ def create_custom_metric(client, project_id,
"displayName": "Custom Metric"
}

client.projects().metricDescriptors().create(
return client.projects().metricDescriptors().create(
name=project_id, body=metrics_descriptor).execute()


def delete_metric_descriptor(
client, custom_metric_name):
"""Delete a custom metric descriptor."""
client.projects().metricDescriptors().delete(
name=custom_metric_name).execute()


def get_custom_metric(client, project_id, custom_metric_type):
"""Retrieve the custom metric we created"""
request = client.projects().metricDescriptors().list(
Expand Down
12 changes: 9 additions & 3 deletions samples/snippets/v3/custom_metric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
from gcp.testing import eventually_consistent
from gcp.testing.flaky import flaky

from custom_metric import create_custom_metric, get_custom_metric
from custom_metric import read_timeseries, write_timeseries_value
from custom_metric import create_custom_metric
from custom_metric import delete_metric_descriptor
from custom_metric import get_custom_metric
from custom_metric import read_timeseries
from custom_metric import write_timeseries_value

import list_resources

""" Custom metric domain for all custom metrics"""
Expand All @@ -53,7 +57,7 @@ def test_custom_metric(cloud_config):
INSTANCE_ID = "test_instance"
METRIC_KIND = "GAUGE"

create_custom_metric(
custom_metric_descriptor = create_custom_metric(
client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)

# wait until metric has been created, use the get call to wait until
Expand All @@ -77,3 +81,5 @@ def _():
response['timeSeries'][0]['points'][0]['value']['int64Value'])
# using seed of 1 will create a value of 1
assert value == pseudo_random_value

delete_metric_descriptor(client, custom_metric_descriptor['name'])

0 comments on commit 414b609

Please sign in to comment.