Commit 52ebc1a7 authored by Caleb Rouleau's avatar Caleb Rouleau Committed by Commit Bot

[Benchmarking] Reduce retry time and add urllib timeout.

It seems we are somehow hitting the overall 4000 second timeout,
which prevents us from getting logs. Attempt to timeout earlier
so that we get some logs.

Bug: 1035590
Change-Id: I293d2772ccd2cc87b66b47c1954ecb802c8f0ddb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1974705
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Auto-Submit: Caleb Rouleau <crouleau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726225}
parent 6baf6f98
...@@ -80,18 +80,13 @@ def SendResults(data, data_label, url, send_as_histograms=False, ...@@ -80,18 +80,13 @@ def SendResults(data, data_label, url, send_as_histograms=False,
recoverable error. recoverable error.
""" """
start = time.time() start = time.time()
errors = []
all_data_uploaded = False all_data_uploaded = False
data_type = ('histogram' if send_as_histograms else 'chartjson') data_type = ('histogram' if send_as_histograms else 'chartjson')
dashboard_data_str = json.dumps(data) dashboard_data_str = json.dumps(data)
# When perf dashboard is overloaded, it takes sometimes to spin up new # When perf dashboard is overloaded, it takes sometimes to spin up new
# instance. So sleep before retrying again. ( # instance. So sleep before retrying again. (
# For more details, see crbug.com/867379. # For more details, see crbug.com/867379.
wait_before_next_retry_in_seconds = 30 wait_before_next_retry_in_seconds = 15
for i in xrange(1, num_retries + 1): for i in xrange(1, num_retries + 1):
try: try:
print('Sending %s result of %s to dashboard (attempt %i out of %i).' % print('Sending %s result of %s to dashboard (attempt %i out of %i).' %
...@@ -104,25 +99,17 @@ def SendResults(data, data_label, url, send_as_histograms=False, ...@@ -104,25 +99,17 @@ def SendResults(data, data_label, url, send_as_histograms=False,
all_data_uploaded = True all_data_uploaded = True
break break
except SendResultsRetryException as e: except SendResultsRetryException as e:
error = 'Error while uploading %s data: %s' % (data_type, str(e)) print('Error while uploading %s data: %s' % (data_type, str(e)))
errors.append(error)
time.sleep(wait_before_next_retry_in_seconds) time.sleep(wait_before_next_retry_in_seconds)
wait_before_next_retry_in_seconds *= 2 wait_before_next_retry_in_seconds *= 2
except SendResultsFatalException as e: except SendResultsFatalException as e:
error = 'Fatal error while uploading %s data: %s' % (data_type, str(e)) print('Fatal error while uploading %s data: %s' % (data_type, str(e)))
errors.append(error)
break break
except Exception: except Exception:
error = 'Unexpected error while uploading %s data: %s' % ( print('Unexpected error while uploading %s data: %s' % (
data_type, traceback.format_exc()) data_type, traceback.format_exc()))
errors.append(error)
break break
for err in errors:
print(err)
print('Time spent sending results to %s: %s' % (url, time.time() - start)) print('Time spent sending results to %s: %s' % (url, time.time() - start))
return all_data_uploaded return all_data_uploaded
...@@ -448,7 +435,7 @@ def _SendResultsJson(url, results_json): ...@@ -448,7 +435,7 @@ def _SendResultsJson(url, results_json):
data = urllib.urlencode({'data': results_json}) data = urllib.urlencode({'data': results_json})
req = urllib2.Request(url + SEND_RESULTS_PATH, data) req = urllib2.Request(url + SEND_RESULTS_PATH, data)
try: try:
urllib2.urlopen(req) urllib2.urlopen(req, timeout=60 * 5)
except (urllib2.HTTPError, urllib2.URLError, httplib.HTTPException): except (urllib2.HTTPError, urllib2.URLError, httplib.HTTPException):
error = traceback.format_exc() error = traceback.format_exc()
......
...@@ -34,7 +34,7 @@ class ResultsDashboardTest(unittest.TestCase): ...@@ -34,7 +34,7 @@ class ResultsDashboardTest(unittest.TestCase):
self.assertEqual(m.call_count, 5) self.assertEqual(m.call_count, 5)
self.assertEqual( self.assertEqual(
sleep_mock.mock_calls, sleep_mock.mock_calls,
[call(30), call(60), call(120), call(240), call(480)]) [call(15), call(30), call(60), call(120), call(240)])
def testNoRetryForSendResultFatalException(self): def testNoRetryForSendResultFatalException(self):
...@@ -89,4 +89,4 @@ class ResultsDashboardTest(unittest.TestCase): ...@@ -89,4 +89,4 @@ class ResultsDashboardTest(unittest.TestCase):
self.assertTrue(upload_result) self.assertTrue(upload_result)
self.assertEqual(m.call_count, 3) self.assertEqual(m.call_count, 3)
self.assertEqual( self.assertEqual(
sleep_mock.mock_calls, [call(30), call(60)]) sleep_mock.mock_calls, [call(15), call(30)])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment