From 9182aaeb7f2bc94b776b9346210a5cc56d0cc9cd Mon Sep 17 00:00:00 2001 From: Andi-Bogdan Postelnicu Date: Thu, 23 Sep 2021 14:15:57 +0300 Subject: [PATCH 1/2] bot: when a generic bot failures occurs also report it in phabricator. --- bot/code_review_bot/cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bot/code_review_bot/cli.py b/bot/code_review_bot/cli.py index 6fefb7306..e78550369 100644 --- a/bot/code_review_bot/cli.py +++ b/bot/code_review_bot/cli.py @@ -12,6 +12,8 @@ from libmozdata.lando import LandoWarnings from libmozdata.phabricator import BuildState from libmozdata.phabricator import PhabricatorAPI +from libmozdata.phabricator import UnitResult +from libmozdata.phabricator import UnitResultState from code_review_bot import AnalysisException from code_review_bot import stats @@ -162,6 +164,7 @@ def main(): w.ingest_autoland(revision) else: w.run(revision) + except Exception as e: # Log errors to papertrail logger.error("Static analysis failure", revision=revision, error=e) @@ -176,6 +179,19 @@ def main(): # Update Harbormaster status w.update_status(revision, state=BuildState.Fail) + failure = UnitResult( + namespace="code-review", + name="general", + result=UnitResultState.Broken, + details="WARNING: A generic error occurred in the code review bot.", + format="remarkup", + duration=0, + ) + + w.phabricator.update_build_target( + revision.target_phid, BuildState.Fail, unit=[failure] + ) + # Then raise to mark task as erroneous raise From 5e628681be6cc98dcc5ebd05b08d561dabbd0349 Mon Sep 17 00:00:00 2001 From: Andi-Bogdan Postelnicu Date: Thu, 23 Sep 2021 17:09:21 +0300 Subject: [PATCH 2/2] bot: updates to the generic failure flow. --- bot/code_review_bot/cli.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/bot/code_review_bot/cli.py b/bot/code_review_bot/cli.py index e78550369..97003c518 100644 --- a/bot/code_review_bot/cli.py +++ b/bot/code_review_bot/cli.py @@ -28,6 +28,11 @@ logger = structlog.get_logger(__name__) +LANDO_FAILURE_MESSAGE = ( + "Static analysis and linting did not run due to a generic failure." +) + + def parse_cli(): """ Setup CLI options parser @@ -114,12 +119,17 @@ def main(): # lando the Lando API lando_reporting_enabled = "lando" in reporters + lando_api = None + lando_publish_generic_failure = False if lando_reporting_enabled: if taskcluster.secrets["LANDO"].get("publish", False): lando_api = LandoWarnings( api_url=taskcluster.secrets["LANDO"]["url"], api_key=phabricator["api_key"], ) + lando_publish_generic_failure = taskcluster.secrets["LANDO"][ + "publish_failure" + ] reporters["lando"].setup_api(lando_api) # Load unique revision @@ -164,7 +174,6 @@ def main(): w.ingest_autoland(revision) else: w.run(revision) - except Exception as e: # Log errors to papertrail logger.error("Static analysis failure", revision=revision, error=e) @@ -176,9 +185,7 @@ def main(): extras["error_message"] = str(e) w.index(revision, state="error", **extras) - # Update Harbormaster status - w.update_status(revision, state=BuildState.Fail) - + # Update Phabricator failure = UnitResult( namespace="code-review", name="general", @@ -189,9 +196,23 @@ def main(): ) w.phabricator.update_build_target( - revision.target_phid, BuildState.Fail, unit=[failure] + revision.build_target_phid, BuildState.Fail, unit=[failure] ) + # Also update lando + if lando_publish_generic_failure: + try: + lando_api.lando_api.del_all_warnings( + revision=revision.id, diff=revision.diff["id"] + ) + lando_api.add_warning( + LANDO_FAILURE_MESSAGE, + revision=revision.id, + diff=revision.diff["id"], + ) + except Exception as ex: + logger.error(str(ex)) + # Then raise to mark task as erroneous raise