Skip to content

Commit 6da517f

Browse files
author
Takashi Matsuo
committed
[monitoring] chore: remove gcp-devrel-py-tools
1 parent 578ece4 commit 6da517f

File tree

5 files changed

+49
-42
lines changed

5 files changed

+49
-42
lines changed

monitoring/api/v3/api-client/custom_metric_test.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
import random
2525
import time
2626

27-
from gcp_devrel.testing import eventually_consistent
28-
from flaky import flaky
27+
import backoff
2928
import googleapiclient.discovery
3029
import pytest
3130

@@ -35,6 +34,7 @@
3534
from custom_metric import read_timeseries
3635
from custom_metric import write_timeseries_value
3736

37+
3838
PROJECT = os.environ['GCLOUD_PROJECT']
3939

4040
""" Custom metric domain for all custom metrics"""
@@ -52,7 +52,7 @@ def client():
5252
return googleapiclient.discovery.build('monitoring', 'v3')
5353

5454

55-
@flaky
55+
@pytest.mark.flaky
5656
def test_custom_metric(client):
5757
PROJECT_RESOURCE = "projects/{}".format(PROJECT)
5858
# Use a constant seed so psuedo random number is known ahead of time
@@ -64,29 +64,35 @@ def test_custom_metric(client):
6464
INSTANCE_ID = "test_instance"
6565
METRIC_KIND = "GAUGE"
6666

67-
custom_metric_descriptor = create_custom_metric(
68-
client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
69-
70-
# wait until metric has been created, use the get call to wait until
71-
# a response comes back with the new metric
72-
custom_metric = None
73-
while not custom_metric:
74-
time.sleep(1)
75-
custom_metric = get_custom_metric(
76-
client, PROJECT_RESOURCE, METRIC_RESOURCE)
77-
78-
write_timeseries_value(client, PROJECT_RESOURCE,
79-
METRIC_RESOURCE, INSTANCE_ID,
80-
METRIC_KIND)
81-
82-
# Sometimes on new metric descriptors, writes have a delay in being
83-
# read back. Use eventually_consistent to account for this.
84-
@eventually_consistent.call
85-
def _():
86-
response = read_timeseries(client, PROJECT_RESOURCE, METRIC_RESOURCE)
87-
value = int(
88-
response['timeSeries'][0]['points'][0]['value']['int64Value'])
89-
# using seed of 1 will create a value of 1
90-
assert value == pseudo_random_value
91-
92-
delete_metric_descriptor(client, custom_metric_descriptor['name'])
67+
try:
68+
custom_metric_descriptor = create_custom_metric(
69+
client, PROJECT_RESOURCE, METRIC_RESOURCE, METRIC_KIND)
70+
71+
# wait until metric has been created, use the get call to wait until
72+
# a response comes back with the new metric
73+
custom_metric = None
74+
while not custom_metric:
75+
time.sleep(1)
76+
custom_metric = get_custom_metric(
77+
client, PROJECT_RESOURCE, METRIC_RESOURCE)
78+
79+
write_timeseries_value(client, PROJECT_RESOURCE,
80+
METRIC_RESOURCE, INSTANCE_ID,
81+
METRIC_KIND)
82+
83+
# Sometimes on new metric descriptors, writes have a delay in being
84+
# read back. Use eventually_consistent to account for this.
85+
@backoff.on_exception(backoff.expo, AssertionError, max_time=120)
86+
def eventually_consistent_test():
87+
response = read_timeseries(
88+
client, PROJECT_RESOURCE, METRIC_RESOURCE)
89+
value = int(
90+
response['timeSeries'][0]['points'][0]['value']['int64Value'])
91+
# using seed of 1 will create a value of 1
92+
assert value == pseudo_random_value
93+
94+
eventually_consistent_test()
95+
96+
finally:
97+
# cleanup
98+
delete_metric_descriptor(client, custom_metric_descriptor['name'])
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1+
backoff==1.10.0
12
pytest==5.3.2
2-
gcp-devrel-py-tools==0.0.15
3-
google-cloud-core==1.3.0
43
flaky==3.6.1

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import os
1616

17+
import backoff
1718
import mock
1819
import pytest
19-
from gcp_devrel.testing import eventually_consistent
2020

2121
import quickstart
2222

@@ -37,8 +37,10 @@ def mock_project_path():
3737

3838

3939
def test_quickstart(capsys, mock_project_path):
40-
@eventually_consistent.call
41-
def _():
40+
@backoff.on_exception(backoff.expo, AssertionError, max_time=60)
41+
def eventually_consistent_test():
4242
quickstart.run_quickstart()
4343
out, _ = capsys.readouterr()
4444
assert 'wrote' in out
45+
46+
eventually_consistent_test()
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1+
backoff==1.10.0
12
pytest==5.3.2
23
mock==3.0.5
3-
gcp-devrel-py-tools==0.0.15
4-
google-cloud-core==1.3.0

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
import re
1717
import pytest
1818

19-
from gcp_devrel.testing import eventually_consistent
19+
import backoff
2020
from google.api_core.exceptions import NotFound
2121

22-
2322
import snippets
2423

24+
2525
PROJECT_ID = os.environ['GCLOUD_PROJECT']
2626

2727

@@ -48,12 +48,13 @@ def write_time_series():
4848

4949
def test_get_delete_metric_descriptor(capsys, custom_metric_descriptor):
5050
try:
51-
@eventually_consistent.call
52-
def __():
51+
@backoff.on_exception(backoff.expo, AssertionError, max_time=60)
52+
def eventually_consistent_test():
5353
snippets.get_metric_descriptor(custom_metric_descriptor)
54+
out, _ = capsys.readouterr()
55+
assert 'DOUBLE' in out
5456

55-
out, _ = capsys.readouterr()
56-
assert 'DOUBLE' in out
57+
eventually_consistent_test()
5758
finally:
5859
snippets.delete_metric_descriptor(custom_metric_descriptor)
5960
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)