From 3b22de0b82d911bbe425d5072937fd8fd3192552 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Mon, 6 Jan 2020 10:57:25 -0600 Subject: [PATCH 01/19] Updated taskcluster.py to use Tenacity for retrying perform_download. Removed import of retry utility. --- bot/code_coverage_bot/taskcluster.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index c6277d627..3636ac3ac 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -9,7 +9,7 @@ import taskcluster from taskcluster.helper import TaskclusterConfig -from code_coverage_bot.utils import retry +from tenacity import retry logger = structlog.getLogger(__name__) taskcluster_config = TaskclusterConfig("https://firefox-ci-tc.services.mozilla.com") @@ -85,6 +85,7 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) + @retry(wait=wait_fixed(30), stop=stop_after_attempt(5)): def perform_download(): r = requests.get(url, stream=True) r.raise_for_status() @@ -96,8 +97,6 @@ def perform_download(): if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): raise BadZipFile("File is not a zip file") - retry(perform_download) - BUILD_PLATFORMS = [ "build-linux64-ccov/opt", From ff03947fa57a2d6e5b741a5edf4a12a108f35867 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Mon, 6 Jan 2020 12:01:25 -0600 Subject: [PATCH 02/19] Uploader.py in bot uses tenacity to retrying gcp_ingest in gcp function. Removed retry runction from utils.py --- bot/code_coverage_bot/uploader.py | 11 ++++++----- bot/code_coverage_bot/utils.py | 22 ---------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/bot/code_coverage_bot/uploader.py b/bot/code_coverage_bot/uploader.py index 4b8c4a26b..4909b47e3 100644 --- a/bot/code_coverage_bot/uploader.py +++ b/bot/code_coverage_bot/uploader.py @@ -7,9 +7,10 @@ import zstandard as zstd from code_coverage_bot.secrets import secrets -from code_coverage_bot.utils import retry from code_coverage_tools.gcp import get_bucket +from tenacity import retry + logger = structlog.get_logger(__name__) GCP_COVDIR_PATH = "{repository}/{revision}/{platform}:{suite}.json.zstd" @@ -45,10 +46,10 @@ def gcp(repository, revision, report, platform, suite): logger.info("Uploaded {} on {}".format(path, bucket)) # Trigger ingestion on backend - retry( - lambda: gcp_ingest(repository, revision, platform, suite), - retries=10, - wait_between_retries=60, + @tenacity.retry( + retry = retry_if_exception(lambda: gcp_ingest(repository, revision, platform, suite)), + stop=stop_after_attempt(10), + wait=wait_fixed(60) ) return blob diff --git a/bot/code_coverage_bot/utils.py b/bot/code_coverage_bot/utils.py index 38c56fcef..ab82592f8 100644 --- a/bot/code_coverage_bot/utils.py +++ b/bot/code_coverage_bot/utils.py @@ -10,28 +10,6 @@ log = structlog.get_logger(__name__) - -class RunException(Exception): - """ - Exception used to stop retrying - """ - - -def retry( - operation, retries=5, wait_between_retries=30, exception_to_break=RunException -): - while True: - try: - return operation() - except Exception as e: - if isinstance(e, exception_to_break): - raise - retries -= 1 - if retries == 0: - raise - time.sleep(wait_between_retries) - - def hide_secrets(text, secrets): if type(text) is bytes: encode_secret, xxx = lambda x: bytes(x, encoding="utf-8"), b"XXX" From 45cd5bbcb820ede8fa99851a3694121f66b65b66 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Tue, 7 Jan 2020 16:10:55 -0600 Subject: [PATCH 03/19] Remove extra : from retry in taskcluster.py --- bot/code_coverage_bot/taskcluster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index 7277fe9a6..1fa431b41 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -87,7 +87,7 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) - @retry(wait=wait_fixed(30), stop=stop_after_attempt(5)): + @retry(wait=wait_fixed(30), stop=stop_after_attempt(5)) def perform_download(): r = requests.get(url, stream=True) r.raise_for_status() From 77b8b9144da7c2d400aed9330eee06d153bb22b3 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Tue, 7 Jan 2020 16:34:29 -0600 Subject: [PATCH 04/19] Add tenacity to requirementspdev.txt to intall --- bot/requirements-dev.txt | 1 + bot/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/requirements-dev.txt b/bot/requirements-dev.txt index 8146d32c5..7fffac092 100644 --- a/bot/requirements-dev.txt +++ b/bot/requirements-dev.txt @@ -4,3 +4,4 @@ pre-commit==1.21.0 pytest==5.3.2 pytest-responses==0.4.0 responses==0.10.9 +tenacity==6.0.0 diff --git a/bot/requirements.txt b/bot/requirements.txt index 50b5888a2..7dc915378 100644 --- a/bot/requirements.txt +++ b/bot/requirements.txt @@ -3,4 +3,4 @@ google-cloud-storage==1.24.1 libmozdata==0.1.64 pytoml==0.1.21 pytz==2019.3 -zstandard==0.13.0 +zstandard==0.13.0 \ No newline at end of file From de3b91b5f7f4258b61311763f19bcc74bb0dc937 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Tue, 7 Jan 2020 16:45:29 -0600 Subject: [PATCH 05/19] Add tenacity to requirements.txt for install and removed it from requirements-dev.txt --- bot/requirements-dev.txt | 3 +-- bot/requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/requirements-dev.txt b/bot/requirements-dev.txt index 7fffac092..65b70b65d 100644 --- a/bot/requirements-dev.txt +++ b/bot/requirements-dev.txt @@ -3,5 +3,4 @@ jsonschema==3.2.0 pre-commit==1.21.0 pytest==5.3.2 pytest-responses==0.4.0 -responses==0.10.9 -tenacity==6.0.0 +responses==0.10.9 \ No newline at end of file diff --git a/bot/requirements.txt b/bot/requirements.txt index 7dc915378..1addd12b2 100644 --- a/bot/requirements.txt +++ b/bot/requirements.txt @@ -3,4 +3,5 @@ google-cloud-storage==1.24.1 libmozdata==0.1.64 pytoml==0.1.21 pytz==2019.3 -zstandard==0.13.0 \ No newline at end of file +zstandard==0.13.0 +tenacity==6.0.0 \ No newline at end of file From 55113e811e13fc5d8db4c5f24d341ceb56dd2227 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Thu, 9 Jan 2020 14:02:41 -0600 Subject: [PATCH 06/19] Updated taskcluster.py and uploader.py to run tenacity --- bot/code_coverage_bot/taskcluster.py | 4 ++-- bot/code_coverage_bot/uploader.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index 1fa431b41..a31af57c4 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -9,7 +9,7 @@ import taskcluster from taskcluster.helper import TaskclusterConfig -from tenacity import retry +import tenacity logger = structlog.getLogger(__name__) taskcluster_config = TaskclusterConfig("https://firefox-ci-tc.services.mozilla.com") @@ -87,7 +87,7 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) - @retry(wait=wait_fixed(30), stop=stop_after_attempt(5)) + @tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) def perform_download(): r = requests.get(url, stream=True) r.raise_for_status() diff --git a/bot/code_coverage_bot/uploader.py b/bot/code_coverage_bot/uploader.py index 4909b47e3..07177833f 100644 --- a/bot/code_coverage_bot/uploader.py +++ b/bot/code_coverage_bot/uploader.py @@ -9,7 +9,7 @@ from code_coverage_bot.secrets import secrets from code_coverage_tools.gcp import get_bucket -from tenacity import retry +from tenacity logger = structlog.get_logger(__name__) GCP_COVDIR_PATH = "{repository}/{revision}/{platform}:{suite}.json.zstd" From 5e4b422e2f406243e59aa71221ae298b9b0be578 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Thu, 9 Jan 2020 14:15:41 -0600 Subject: [PATCH 07/19] Add call for perform_download function --- bot/code_coverage_bot/taskcluster.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index a31af57c4..94905c6eb 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -98,6 +98,7 @@ def perform_download(): if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): raise BadZipFile("File is not a zip file") + perform_download() def is_coverage_task(task): From a825a35600c0cb1552cbba9825902a43c4840bb6 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Thu, 9 Jan 2020 14:23:52 -0600 Subject: [PATCH 08/19] Corrected error with import tenacity instead of from --- bot/code_coverage_bot/uploader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/code_coverage_bot/uploader.py b/bot/code_coverage_bot/uploader.py index 07177833f..9d5e368f4 100644 --- a/bot/code_coverage_bot/uploader.py +++ b/bot/code_coverage_bot/uploader.py @@ -9,7 +9,7 @@ from code_coverage_bot.secrets import secrets from code_coverage_tools.gcp import get_bucket -from tenacity +import tenacity logger = structlog.get_logger(__name__) GCP_COVDIR_PATH = "{repository}/{revision}/{platform}:{suite}.json.zstd" From f6883ba17da0304b1e0e479fc8e4286c3b7d9a3e Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 18:18:17 -0600 Subject: [PATCH 09/19] Updated uploader.py to use tenacity functions --- bot/code_coverage_bot/uploader.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bot/code_coverage_bot/uploader.py b/bot/code_coverage_bot/uploader.py index 9d5e368f4..3583ec1c1 100644 --- a/bot/code_coverage_bot/uploader.py +++ b/bot/code_coverage_bot/uploader.py @@ -4,13 +4,12 @@ import requests import structlog +import tenacity import zstandard as zstd from code_coverage_bot.secrets import secrets from code_coverage_tools.gcp import get_bucket -import tenacity - logger = structlog.get_logger(__name__) GCP_COVDIR_PATH = "{repository}/{revision}/{platform}:{suite}.json.zstd" @@ -46,11 +45,7 @@ def gcp(repository, revision, report, platform, suite): logger.info("Uploaded {} on {}".format(path, bucket)) # Trigger ingestion on backend - @tenacity.retry( - retry = retry_if_exception(lambda: gcp_ingest(repository, revision, platform, suite)), - stop=stop_after_attempt(10), - wait=wait_fixed(60) - ) + gcp_ingest(repository, revision, platform, suite) return blob @@ -66,7 +61,7 @@ def gcp_covdir_exists(repository, revision, platform, suite): blob = bucket.blob(path) return blob.exists() - +@tenacity.retry(stop = tenacity.stop_after_attempt(10), wait = tenacity.wait_fixed(60)) def gcp_ingest(repository, revision, platform, suite): """ The GCP report ingestion is triggered remotely on a backend From 77a4eb0d53869f2b166ca22f270052bd8d730087 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 19:00:10 -0600 Subject: [PATCH 10/19] Tabs to spaces and added tenacity to know third party --- .isort.cfg | 2 +- bot/code_coverage_bot/uploader.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.isort.cfg b/.isort.cfg index 5f64710da..ab08dd46a 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,6 +1,6 @@ [settings] known_first_party = code_coverage_backend,code_coverage_bot,code_coverage_events,code_coverage_tools,conftest,firefox_code_coverage -known_third_party = connexion,datadog,dateutil,fakeredis,flask,flask_cors,flask_talisman,google,hglib,jsone,jsonschema,libmozdata,libmozevent,logbook,pytest,pytz,raven,redis,requests,responses,setuptools,structlog,taskcluster,werkzeug,zstandard +known_third_party = connexion,datadog,dateutil,fakeredis,flask,flask_cors,flask_talisman,google,hglib,jsone,jsonschema,libmozdata,libmozevent,logbook,pytest,pytz,raven,redis,requests,responses,setuptools,structlog,taskcluster,tenacity,werkzeug,zstandard force_single_line = True default_section=FIRSTPARTY line_length=159 diff --git a/bot/code_coverage_bot/uploader.py b/bot/code_coverage_bot/uploader.py index 3583ec1c1..0687d2cb3 100644 --- a/bot/code_coverage_bot/uploader.py +++ b/bot/code_coverage_bot/uploader.py @@ -45,7 +45,7 @@ def gcp(repository, revision, report, platform, suite): logger.info("Uploaded {} on {}".format(path, bucket)) # Trigger ingestion on backend - gcp_ingest(repository, revision, platform, suite) + gcp_ingest(repository, revision, platform, suite) return blob @@ -61,7 +61,8 @@ def gcp_covdir_exists(repository, revision, platform, suite): blob = bucket.blob(path) return blob.exists() -@tenacity.retry(stop = tenacity.stop_after_attempt(10), wait = tenacity.wait_fixed(60)) + +@tenacity.retry(stop=tenacity.stop_after_attempt(10), wait=tenacity.wait_fixed(60)) def gcp_ingest(repository, revision, platform, suite): """ The GCP report ingestion is triggered remotely on a backend From 2e64b0d1dbaf433abfc0b4b0483f6618187b7756 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 19:23:10 -0600 Subject: [PATCH 11/19] Update requirements.txt and requirements-dev.txt with sorting. Updated utils.py and taskcluster.py because pre-commit run --- bot/code_coverage_bot/taskcluster.py | 4 ++-- bot/code_coverage_bot/utils.py | 1 + bot/requirements-dev.txt | 2 +- bot/requirements.txt | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index d06b55658..0977f0978 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -7,9 +7,8 @@ import requests import structlog import taskcluster -from taskcluster.helper import TaskclusterConfig - import tenacity +from taskcluster.helper import TaskclusterConfig logger = structlog.getLogger(__name__) taskcluster_config = TaskclusterConfig("https://firefox-ci-tc.services.mozilla.com") @@ -98,6 +97,7 @@ def perform_download(): if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): raise BadZipFile("File is not a zip file") + perform_download() diff --git a/bot/code_coverage_bot/utils.py b/bot/code_coverage_bot/utils.py index ab82592f8..1d1768971 100644 --- a/bot/code_coverage_bot/utils.py +++ b/bot/code_coverage_bot/utils.py @@ -10,6 +10,7 @@ log = structlog.get_logger(__name__) + def hide_secrets(text, secrets): if type(text) is bytes: encode_secret, xxx = lambda x: bytes(x, encoding="utf-8"), b"XXX" diff --git a/bot/requirements-dev.txt b/bot/requirements-dev.txt index 65b70b65d..8146d32c5 100644 --- a/bot/requirements-dev.txt +++ b/bot/requirements-dev.txt @@ -3,4 +3,4 @@ jsonschema==3.2.0 pre-commit==1.21.0 pytest==5.3.2 pytest-responses==0.4.0 -responses==0.10.9 \ No newline at end of file +responses==0.10.9 diff --git a/bot/requirements.txt b/bot/requirements.txt index 1addd12b2..5eb443ab7 100644 --- a/bot/requirements.txt +++ b/bot/requirements.txt @@ -3,5 +3,5 @@ google-cloud-storage==1.24.1 libmozdata==0.1.64 pytoml==0.1.21 pytz==2019.3 +tenacity==6.0.0 zstandard==0.13.0 -tenacity==6.0.0 \ No newline at end of file From 2a6ea477b77af5d98e2b5a3abf06ee98f5b40c89 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 19:34:29 -0600 Subject: [PATCH 12/19] Added back class RunException to utils.py and removed import time --- bot/code_coverage_bot/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/code_coverage_bot/utils.py b/bot/code_coverage_bot/utils.py index 1d1768971..20021415d 100644 --- a/bot/code_coverage_bot/utils.py +++ b/bot/code_coverage_bot/utils.py @@ -4,13 +4,18 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import concurrent.futures import subprocess -import time import structlog log = structlog.get_logger(__name__) +class RunException(Exception): + """ + Exception used to stop retrying + """ + + def hide_secrets(text, secrets): if type(text) is bytes: encode_secret, xxx = lambda x: bytes(x, encoding="utf-8"), b"XXX" From e895b126d39c36d410f52483977d3148ae08d701 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 20:12:21 -0600 Subject: [PATCH 13/19] Moved perform download function outside of download artifact --- bot/code_coverage_bot/taskcluster.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index 0977f0978..a025be632 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -75,6 +75,19 @@ def get_tasks_in_group(group_id): break +@tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) +def perform_download(): + r = requests.get(url, stream=True) + r.raise_for_status() + + with open(artifact_path, "wb") as f: + r.raw.decode_content = True + shutil.copyfileobj(r.raw, f) + + if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): + raise BadZipFile("File is not a zip file") + + def download_artifact(artifact_path, task_id, artifact_name): if os.path.exists(artifact_path): return artifact_path @@ -86,18 +99,6 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) - @tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) - def perform_download(): - r = requests.get(url, stream=True) - r.raise_for_status() - - with open(artifact_path, "wb") as f: - r.raw.decode_content = True - shutil.copyfileobj(r.raw, f) - - if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): - raise BadZipFile("File is not a zip file") - perform_download() From 1fbd5526a2a0931090a4cf498522e4b1a66b138b Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 20:23:58 -0600 Subject: [PATCH 14/19] Added agruements from urls and artifact path for perform download --- bot/code_coverage_bot/taskcluster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index a025be632..a95ba1d00 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -76,7 +76,7 @@ def get_tasks_in_group(group_id): @tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) -def perform_download(): +def perform_download(url, artifact_path): r = requests.get(url, stream=True) r.raise_for_status() @@ -99,7 +99,7 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) - perform_download() + perform_download(url, artifact_path) def is_coverage_task(task): From da866ce7d840f39240d798c4ef73b9b304970533 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 20:45:39 -0600 Subject: [PATCH 15/19] Moved perform download back into download_artifact function --- bot/code_coverage_bot/taskcluster.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index a95ba1d00..3f9a9856f 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -99,7 +99,19 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) - perform_download(url, artifact_path) + @tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) + def perform_download(): + r = requests.get(url, stream=True) + r.raise_for_status() + + with open(artifact_path, "wb") as f: + r.raw.decode_content = True + shutil.copyfileobj(r.raw, f) + + if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): + raise BadZipFile("File is not a zip file") + + perform_download() def is_coverage_task(task): From ec20deabc8c4cb30810bd7203d04b7a7155a1f22 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Fri, 10 Jan 2020 22:31:23 -0600 Subject: [PATCH 16/19] Removed extra perform_download function and set reraise to try for retry of perform_download --- bot/code_coverage_bot/taskcluster.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/bot/code_coverage_bot/taskcluster.py b/bot/code_coverage_bot/taskcluster.py index 3f9a9856f..f5734d6cc 100644 --- a/bot/code_coverage_bot/taskcluster.py +++ b/bot/code_coverage_bot/taskcluster.py @@ -75,19 +75,6 @@ def get_tasks_in_group(group_id): break -@tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) -def perform_download(url, artifact_path): - r = requests.get(url, stream=True) - r.raise_for_status() - - with open(artifact_path, "wb") as f: - r.raw.decode_content = True - shutil.copyfileobj(r.raw, f) - - if artifact_path.endswith(".zip") and not is_zipfile(artifact_path): - raise BadZipFile("File is not a zip file") - - def download_artifact(artifact_path, task_id, artifact_name): if os.path.exists(artifact_path): return artifact_path @@ -99,7 +86,9 @@ def download_artifact(artifact_path, task_id, artifact_name): url = queue.buildUrl("getLatestArtifact", task_id, artifact_name) logger.debug("Downloading artifact", url=url) - @tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5)) + @tenacity.retry( + reraise=True, wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5) + ) def perform_download(): r = requests.get(url, stream=True) r.raise_for_status() From efbe2e98f51ebfdf2532926fc3b613aa00ba9e4f Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Tue, 14 Jan 2020 16:16:16 -0600 Subject: [PATCH 17/19] Remove the function RaiseExpection and used expection instead in utils.py. Updated test_taskcluster.py to check on number of times a function is called --- bot/code_coverage_bot/utils.py | 10 ++-------- bot/tests/test_taskcluster.py | 8 ++++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/bot/code_coverage_bot/utils.py b/bot/code_coverage_bot/utils.py index 20021415d..0bafa8ff4 100644 --- a/bot/code_coverage_bot/utils.py +++ b/bot/code_coverage_bot/utils.py @@ -10,12 +10,6 @@ log = structlog.get_logger(__name__) -class RunException(Exception): - """ - Exception used to stop retrying - """ - - def hide_secrets(text, secrets): if type(text) is bytes: encode_secret, xxx = lambda x: bytes(x, encoding="utf-8"), b"XXX" @@ -38,7 +32,7 @@ def run_check(command, **kwargs): assert isinstance(command, list) if len(command) == 0: - raise RunException("Can't run an empty command.") + raise Exception("Can't run an empty command.") _kwargs = dict( stdin=subprocess.DEVNULL, # no interactions @@ -65,7 +59,7 @@ def run_check(command, **kwargs): error=error, ) - raise RunException(f"`{command[0]}` failed with code: {proc.returncode}.") + raise Exception(f"`{command[0]}` failed with code: {proc.returncode}.") return output diff --git a/bot/tests/test_taskcluster.py b/bot/tests/test_taskcluster.py index 53b85cab3..b720e2c88 100644 --- a/bot/tests/test_taskcluster.py +++ b/bot/tests/test_taskcluster.py @@ -119,7 +119,7 @@ def test_get_tasks_in_group(mock_taskcluster, GROUP_TASKS_1, GROUP_TASKS_2): ) responses.add( responses.GET, - "http://taskcluster.test/api/queue/v1/task-group/aPt9FbIdQwmhwDIPDYLuaw/list?continuationToken=1%2132%21YVB0OUZiSWRRd21od0RJUERZTHVhdw--~1%2132%21ZnJVcGRRT0VTalN0Nm9Ua1Ztcy04UQ--&limit=200", # noqa + "http://taskcluster.test/api/queue/v1/task-group/aPt9FbIdQwmhwDIPDYLuaw/list?continuationToken=1%2132%21YVB0OUZiSWRRd21od0RJUERZTHVhdw--~1%2132%21ZnJVcGRRT0VTalN0Nm9Ua1Ztcy04UQ--&limit=200", json=GROUP_TASKS_2, status=200, match_querystring=True, @@ -282,7 +282,7 @@ def test_download_artifact_forbidden(mocked_sleep, mock_taskcluster, tmpdir): with pytest.raises( requests.exceptions.HTTPError, - match="403 Client Error: Forbidden for url: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/FBdocjnAQOW_GJDOfmgjxw/artifacts/public%2Ftest_info%2Fcode-coverage-grcov.zip", # noqa + match="403 Client Error: Forbidden for url: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/FBdocjnAQOW_GJDOfmgjxw/artifacts/public%2Ftest_info%2Fcode-coverage-grcov.zip", ): taskcluster.download_artifact( os.path.join(tmpdir.strpath, "windows_reftest-6_code-coverage-grcov.zip"), @@ -290,7 +290,7 @@ def test_download_artifact_forbidden(mocked_sleep, mock_taskcluster, tmpdir): "public/test_info/code-coverage-grcov.zip", ) - assert mocked_sleep.call_count == 4 + assert len(responses.calls) == 5 @mock.patch("time.sleep") @@ -310,4 +310,4 @@ def test_download_artifact_badzip(mocked_sleep, mock_taskcluster, tmpdir): "public/test_info/code-coverage-grcov.zip", ) - assert mocked_sleep.call_count == 4 + assert len(responses.calls) == 5 From 744e11456b0f48ddba9598b01ccd07e0876d07f5 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Tue, 14 Jan 2020 19:05:05 -0600 Subject: [PATCH 18/19] Added back # noqa for lines too long in test_taskcluster.py --- bot/tests/test_taskcluster.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/tests/test_taskcluster.py b/bot/tests/test_taskcluster.py index b720e2c88..46831aedc 100644 --- a/bot/tests/test_taskcluster.py +++ b/bot/tests/test_taskcluster.py @@ -119,7 +119,7 @@ def test_get_tasks_in_group(mock_taskcluster, GROUP_TASKS_1, GROUP_TASKS_2): ) responses.add( responses.GET, - "http://taskcluster.test/api/queue/v1/task-group/aPt9FbIdQwmhwDIPDYLuaw/list?continuationToken=1%2132%21YVB0OUZiSWRRd21od0RJUERZTHVhdw--~1%2132%21ZnJVcGRRT0VTalN0Nm9Ua1Ztcy04UQ--&limit=200", + "http://taskcluster.test/api/queue/v1/task-group/aPt9FbIdQwmhwDIPDYLuaw/list?continuationToken=1%2132%21YVB0OUZiSWRRd21od0RJUERZTHVhdw--~1%2132%21ZnJVcGRRT0VTalN0Nm9Ua1Ztcy04UQ--&limit=200", # noqa json=GROUP_TASKS_2, status=200, match_querystring=True, @@ -282,7 +282,7 @@ def test_download_artifact_forbidden(mocked_sleep, mock_taskcluster, tmpdir): with pytest.raises( requests.exceptions.HTTPError, - match="403 Client Error: Forbidden for url: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/FBdocjnAQOW_GJDOfmgjxw/artifacts/public%2Ftest_info%2Fcode-coverage-grcov.zip", + match="403 Client Error: Forbidden for url: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/FBdocjnAQOW_GJDOfmgjxw/artifacts/public%2Ftest_info%2Fcode-coverage-grcov.zip", # noqa ): taskcluster.download_artifact( os.path.join(tmpdir.strpath, "windows_reftest-6_code-coverage-grcov.zip"), From bdb6464235e44b4625a4c278e083839fe1377c73 Mon Sep 17 00:00:00 2001 From: seb-sojka Date: Tue, 28 Jan 2020 16:06:25 -0600 Subject: [PATCH 19/19] Pre-commit changed retry style --- bot/code_coverage_bot/uploader.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/code_coverage_bot/uploader.py b/bot/code_coverage_bot/uploader.py index 0687d2cb3..929f65c4c 100644 --- a/bot/code_coverage_bot/uploader.py +++ b/bot/code_coverage_bot/uploader.py @@ -62,7 +62,9 @@ def gcp_covdir_exists(repository, revision, platform, suite): return blob.exists() -@tenacity.retry(stop=tenacity.stop_after_attempt(10), wait=tenacity.wait_fixed(60)) +@tenacity.retry( + stop=tenacity.stop_after_attempt(10), wait=tenacity.wait_fixed(60), reraise=True +) def gcp_ingest(repository, revision, platform, suite): """ The GCP report ingestion is triggered remotely on a backend