From 56a6b16fa1a8fa70df7b5018b12de815e1b504dd Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 19 Oct 2018 16:23:18 -0700 Subject: [PATCH] Time series tests use random unique name to avoid limits (#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 --- monitoring/api/v3/cloud-client/snippets.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/monitoring/api/v3/cloud-client/snippets.py b/monitoring/api/v3/cloud-client/snippets.py index 2cb47f7f3afe..7bfd829d7bc7 100644 --- a/monitoring/api/v3/cloud-client/snippets.py +++ b/monitoring/api/v3/cloud-client/snippets.py @@ -15,17 +15,22 @@ import argparse import os import pprint +import random import time from google.cloud import monitoring_v3 +# Avoid collisions with other runs +RANDOM_SUFFIX = str(random.randint(1000, 9999)) + + def create_metric_descriptor(project_id): # [START monitoring_create_metric] client = monitoring_v3.MetricServiceClient() project_name = client.project_path(project_id) descriptor = monitoring_v3.types.MetricDescriptor() - descriptor.type = 'custom.googleapis.com/my_metric' + descriptor.type = 'custom.googleapis.com/my_metric' + RANDOM_SUFFIX descriptor.metric_kind = ( monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGE) descriptor.value_type = ( @@ -50,7 +55,7 @@ def write_time_series(project_id): project_name = client.project_path(project_id) series = monitoring_v3.types.TimeSeries() - series.metric.type = 'custom.googleapis.com/my_metric' + series.metric.type = 'custom.googleapis.com/my_metric' + RANDOM_SUFFIX series.resource.type = 'gce_instance' series.resource.labels['instance_id'] = '1234567890123456789' series.resource.labels['zone'] = 'us-central1-f'