Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup metric descriptors in tests #776

Merged
merged 1 commit into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion monitoring/api/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 monitoring/api/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'])