Skip to content

Commit

Permalink
Fix Timeseries Query in Monitoring System Test
Browse files Browse the repository at this point in the history
The old method was querying with the wrong
interval, but the test still passed because
new query objects were being unnecessarily
created, and the end time would eventually roll
over so the interval was correct. Besides being
wrong, this also led to longer back off then
necessary since results might have been available
before the rollover.
  • Loading branch information
Bill Prin committed Sep 28, 2016
1 parent 5a0e492 commit d5be4a0
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions system_tests/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import unittest

from google.cloud.exceptions import BadRequest
Expand Down Expand Up @@ -201,18 +202,23 @@ def test_write_point(self):

retry_500(client.write_point)(metric, resource, VALUE)

def _query_timeseries_with_retries():
MAX_RETRIES = 7
MAX_RETRIES = 7

def _has_timeseries(result):
return len(list(result)) > 0
# need to wrap built-in function for decorators to work
def list_timeseries(query):
return list(query)

retry_result = RetryResult(_has_timeseries,
max_tries=MAX_RETRIES)(client.query)
return RetryErrors(BadRequest, max_tries=MAX_RETRIES)(retry_result)
def _has_timeseries(results):
return len(results) > 0

endtime = datetime.datetime.utcnow()
query = client.query(METRIC_TYPE, end_time=endtime, minutes=5)

retry_result = RetryResult(_has_timeseries, max_tries=MAX_RETRIES)(
list_timeseries)
timeseries_list = RetryErrors(BadRequest, max_tries=MAX_RETRIES)(
retry_result)(query)

query = _query_timeseries_with_retries()(METRIC_TYPE, minutes=5)
timeseries_list = list(query)
self.assertEqual(len(timeseries_list), 1)
timeseries = timeseries_list[0]
self.assertEqual(timeseries.metric, metric)
Expand Down

0 comments on commit d5be4a0

Please sign in to comment.