Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Timeseries Query in Monitoring System Test #2460

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


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

end_time = datetime.datetime.utcnow()
query = client.query(METRIC_TYPE, end_time=end_time, 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