27
27
import backoff
28
28
import googleapiclient .discovery
29
29
import pytest
30
+ from googleapiclient .errors import HttpError
30
31
31
32
from custom_metric import create_custom_metric
32
33
from custom_metric import delete_metric_descriptor
@@ -52,7 +53,6 @@ def client():
52
53
return googleapiclient .discovery .build ('monitoring' , 'v3' )
53
54
54
55
55
- @pytest .mark .flaky
56
56
def test_custom_metric (client ):
57
57
PROJECT_RESOURCE = "projects/{}" .format (PROJECT )
58
58
# Use a constant seed so psuedo random number is known ahead of time
@@ -69,23 +69,30 @@ def test_custom_metric(client):
69
69
client , PROJECT_RESOURCE , METRIC_RESOURCE , METRIC_KIND )
70
70
71
71
# wait until metric has been created, use the get call to wait until
72
- # a response comes back with the new metric
72
+ # a response comes back with the new metric with 10 retries.
73
73
custom_metric = None
74
- while not custom_metric :
74
+ retry_count = 0
75
+ while not custom_metric and retry_count < 10 :
75
76
time .sleep (1 )
77
+ retry_count += 1
76
78
custom_metric = get_custom_metric (
77
79
client , PROJECT_RESOURCE , METRIC_RESOURCE )
80
+ # Make sure we get the custom metric
81
+ assert custom_metric
78
82
79
83
write_timeseries_value (client , PROJECT_RESOURCE ,
80
84
METRIC_RESOURCE , INSTANCE_ID ,
81
85
METRIC_KIND )
82
86
83
87
# Sometimes on new metric descriptors, writes have a delay in being
84
88
# read back. Use eventually_consistent to account for this.
85
- @backoff .on_exception (backoff .expo , AssertionError , max_time = 120 )
89
+ @backoff .on_exception (
90
+ backoff .expo , (AssertionError , HttpError ), max_time = 120 )
86
91
def eventually_consistent_test ():
87
92
response = read_timeseries (
88
93
client , PROJECT_RESOURCE , METRIC_RESOURCE )
94
+ # Make sure the value is not empty.
95
+ assert 'timeSeries' in response
89
96
value = int (
90
97
response ['timeSeries' ][0 ]['points' ][0 ]['value' ]['int64Value' ])
91
98
# using seed of 1 will create a value of 1
0 commit comments