Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 830f133

Browse filesBrowse files
waprinJon Wayne Parrott
authored andcommitted
Cleanup metric descriptors (GoogleCloudPlatform#776)
1 parent a656105 commit 830f133
Copy full SHA for 830f133

File tree

Expand file treeCollapse file tree

2 files changed

+17
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-4
lines changed

‎monitoring/api/v3/custom_metric.py

Copy file name to clipboardExpand all lines: monitoring/api/v3/custom_metric.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,17 @@ def create_custom_metric(client, project_id,
7474
"displayName": "Custom Metric"
7575
}
7676

77-
client.projects().metricDescriptors().create(
77+
return client.projects().metricDescriptors().create(
7878
name=project_id, body=metrics_descriptor).execute()
7979

8080

81+
def delete_metric_descriptor(
82+
client, custom_metric_name):
83+
"""Delete a custom metric descriptor."""
84+
client.projects().metricDescriptors().delete(
85+
name=custom_metric_name).execute()
86+
87+
8188
def get_custom_metric(client, project_id, custom_metric_type):
8289
"""Retrieve the custom metric we created"""
8390
request = client.projects().metricDescriptors().list(

‎monitoring/api/v3/custom_metric_test.py

Copy file name to clipboardExpand all lines: monitoring/api/v3/custom_metric_test.py
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
from gcp.testing import eventually_consistent
2727
from gcp.testing.flaky import flaky
2828

29-
from custom_metric import create_custom_metric, get_custom_metric
30-
from custom_metric import read_timeseries, write_timeseries_value
29+
from custom_metric import create_custom_metric
30+
from custom_metric import delete_metric_descriptor
31+
from custom_metric import get_custom_metric
32+
from custom_metric import read_timeseries
33+
from custom_metric import write_timeseries_value
34+
3135
import list_resources
3236

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

56-
create_custom_metric(
60+
custom_metric_descriptor = create_custom_metric(
5761
client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
5862

5963
# wait until metric has been created, use the get call to wait until
@@ -77,3 +81,5 @@ def _():
7781
response['timeSeries'][0]['points'][0]['value']['int64Value'])
7882
# using seed of 1 will create a value of 1
7983
assert value == pseudo_random_value
84+
85+
delete_metric_descriptor(client, custom_metric_descriptor['name'])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.