Skip to content

Commit 56a6b16

Browse files
authored
Time series tests use random unique name to avoid limits (GoogleCloudPlatform#1776)
* Time series tests use random unique name to avoid limits * Lint wants another blank line here * Use current debian image family * Restore to old state. Work should be on different branch. * Update snippets.py
1 parent 81a8413 commit 56a6b16

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@
1515
import argparse
1616
import os
1717
import pprint
18+
import random
1819
import time
1920

2021
from google.cloud import monitoring_v3
2122

2223

24+
# Avoid collisions with other runs
25+
RANDOM_SUFFIX = str(random.randint(1000, 9999))
26+
27+
2328
def create_metric_descriptor(project_id):
2429
# [START monitoring_create_metric]
2530
client = monitoring_v3.MetricServiceClient()
2631
project_name = client.project_path(project_id)
2732
descriptor = monitoring_v3.types.MetricDescriptor()
28-
descriptor.type = 'custom.googleapis.com/my_metric'
33+
descriptor.type = 'custom.googleapis.com/my_metric' + RANDOM_SUFFIX
2934
descriptor.metric_kind = (
3035
monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGE)
3136
descriptor.value_type = (
@@ -50,7 +55,7 @@ def write_time_series(project_id):
5055
project_name = client.project_path(project_id)
5156

5257
series = monitoring_v3.types.TimeSeries()
53-
series.metric.type = 'custom.googleapis.com/my_metric'
58+
series.metric.type = 'custom.googleapis.com/my_metric' + RANDOM_SUFFIX
5459
series.resource.type = 'gce_instance'
5560
series.resource.labels['instance_id'] = '1234567890123456789'
5661
series.resource.labels['zone'] = 'us-central1-f'

0 commit comments

Comments
 (0)