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

[monitoring] fix: use the same random value for retry #3900

Merged
merged 3 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions monitoring/api/v3/api-client/custom_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# [START all]
import argparse
import datetime
import os
import pprint
import random
import time
Expand Down Expand Up @@ -103,6 +104,12 @@ def get_custom_data_point():
"""Dummy method to return a mock measurement for demonstration purposes.
Returns a random number between 0 and 10"""
length = random.randint(0, 10)
# [END all]
# Just in case, terminate the region tag.
# If there's an envvar "MONITORING_TEST_REPORT_VALUE" is set, use it.
if 'MONITORING_TEST_REPORT_VALUE' in os.environ:
length = int(os.environ.get('MONITORING_TEST_REPORT_VALUE'))
# [START all]
print("reporting timeseries value {}".format(str(length)))
return length

Expand Down
9 changes: 3 additions & 6 deletions monitoring/api/v3/api-client/custom_metric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ def custom_metric(client):


def test_custom_metric(client, custom_metric):
# Use a constant seed so psuedo random number is known ahead of time
random.seed(1)
pseudo_random_value = random.randint(0, 10)
# Reseed it
random.seed(1)
os.environ['MONITORING_TEST_REPORT_VALUE'] = str(pseudo_random_value)

INSTANCE_ID = "test_instance"

Expand All @@ -107,7 +104,7 @@ def eventually_consistent_test():
assert 'timeSeries' in response
value = int(
response['timeSeries'][0]['points'][0]['value']['int64Value'])
# using seed of 1 will create a value of 1
assert value == pseudo_random_value
# We override the report value with MONITORING_TEST_REPORT_VALUE env var
assert pseudo_random_value == value

eventually_consistent_test()