From 3812ee347cf4f24a202ec33b25c1bdf41ac89136 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 19 Oct 2018 10:17:51 -0700 Subject: [PATCH 1/5] Time series tests use random unique name to avoid limits --- monitoring/api/v3/cloud-client/snippets.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/monitoring/api/v3/cloud-client/snippets.py b/monitoring/api/v3/cloud-client/snippets.py index 2cb47f7f3afe..2849a0e14640 100644 --- a/monitoring/api/v3/cloud-client/snippets.py +++ b/monitoring/api/v3/cloud-client/snippets.py @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. + # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,17 +15,21 @@ 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 +54,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' From 0b5f20370a1e79a98788b7a773b14fb0945271b9 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 19 Oct 2018 10:28:34 -0700 Subject: [PATCH 2/5] Lint wants another blank line here --- monitoring/api/v3/cloud-client/snippets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monitoring/api/v3/cloud-client/snippets.py b/monitoring/api/v3/cloud-client/snippets.py index 2849a0e14640..48e0f067219b 100644 --- a/monitoring/api/v3/cloud-client/snippets.py +++ b/monitoring/api/v3/cloud-client/snippets.py @@ -24,6 +24,7 @@ # 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() From 5dd636efe762422aa912524d3f471966b39f08ab Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 19 Oct 2018 12:14:46 -0700 Subject: [PATCH 3/5] Use current debian image family --- compute/api/create_instance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compute/api/create_instance.py b/compute/api/create_instance.py index e55866a4487d..46418d6f6fb6 100644 --- a/compute/api/create_instance.py +++ b/compute/api/create_instance.py @@ -35,7 +35,7 @@ # [START list_instances] def list_instances(compute, project, zone): result = compute.instances().list(project=project, zone=zone).execute() - return result['items'] + return result['items'] if 'items' in result else None # [END list_instances] @@ -43,7 +43,7 @@ def list_instances(compute, project, zone): def create_instance(compute, project, zone, name, bucket): # Get the latest Debian Jessie image. image_response = compute.images().getFromFamily( - project='debian-cloud', family='debian-8').execute() + project='debian-cloud', family='debian-9').execute() source_disk_image = image_response['selfLink'] # Configure the machine From b655d34f63124b6a2c15c8a65d450c8962ae892b Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 19 Oct 2018 12:20:13 -0700 Subject: [PATCH 4/5] Restore to old state. Work should be on different branch. --- compute/api/create_instance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compute/api/create_instance.py b/compute/api/create_instance.py index 46418d6f6fb6..e55866a4487d 100644 --- a/compute/api/create_instance.py +++ b/compute/api/create_instance.py @@ -35,7 +35,7 @@ # [START list_instances] def list_instances(compute, project, zone): result = compute.instances().list(project=project, zone=zone).execute() - return result['items'] if 'items' in result else None + return result['items'] # [END list_instances] @@ -43,7 +43,7 @@ def list_instances(compute, project, zone): def create_instance(compute, project, zone, name, bucket): # Get the latest Debian Jessie image. image_response = compute.images().getFromFamily( - project='debian-cloud', family='debian-9').execute() + project='debian-cloud', family='debian-8').execute() source_disk_image = image_response['selfLink'] # Configure the machine From 9f6476636469ee2c23c8af56cf5155f0460a25bc Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Fri, 19 Oct 2018 15:35:41 -0700 Subject: [PATCH 5/5] Update snippets.py --- monitoring/api/v3/cloud-client/snippets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/api/v3/cloud-client/snippets.py b/monitoring/api/v3/cloud-client/snippets.py index 48e0f067219b..7bfd829d7bc7 100644 --- a/monitoring/api/v3/cloud-client/snippets.py +++ b/monitoring/api/v3/cloud-client/snippets.py @@ -1,4 +1,4 @@ - +# Copyright 2017 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.