OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Write more data from rerunner to DB and add network retries (#33798)
Andrey Babushkin3bfb85f61ef4
diff --git a/.github/scripts/workflow_rerun/argument_parser.py b/.github/scripts/workflow_rerun/argument_parser.pyindex 36022c1bb56..f62d9dffc4b 100644--- a/.github/scripts/workflow_rerun/argument_parser.py+++ b/.github/scripts/workflow_rerun/argument_parser.py@@ -7,15 +7,19 @@ from pathlib import Pathdef get_arguments() -> argparse.Namespace:parser = argparse.ArgumentParser()- parser.add_argument('-r', '--repository-name',- type=str,+ parser.add_argument('-r', '--repository-name',+ type=str,required=True,help='Repository name in the OWNER/REPOSITORY format')- parser.add_argument('--run-id',- type=int,+ parser.add_argument('--run-id',+ type=int,required=True,help='Workflow Run ID')- parser.add_argument('--errors-to-look-for-file',+ parser.add_argument('--rerunner-run-id',+ type=int,+ required=True,+ help='Workflow Run ID for the rerunner run itself')+ parser.add_argument('--errors-to-look-for-file',type=Path,required=False,help='.json file with the errors to look for in logs',diff --git a/.github/scripts/workflow_rerun/log_analyzer.py b/.github/scripts/workflow_rerun/log_analyzer.pyindex 5ca1d186dcd..48b40e7fe59 100644--- a/.github/scripts/workflow_rerun/log_analyzer.py+++ b/.github/scripts/workflow_rerun/log_analyzer.py@@ -128,7 +128,7 @@ class LogAnalyzer:if __name__ == '__main__':# Usage example- log_analyzer = LogAnalyzer(path_to_log_archive=Path('/tmp/logs/log.zip'),+ log_analyzer = LogAnalyzer(path_to_logs=Path('/tmp/logs_dir'),path_to_errors_file=Path('/tmp/errors_to_look_for.json'))log_analyzer.analyze()if log_analyzer.found_matching_error:diff --git a/.github/scripts/workflow_rerun/log_collector.py b/.github/scripts/workflow_rerun/log_collector.pyindex 64bdf668cd1..a3f96799254 100644--- a/.github/scripts/workflow_rerun/log_collector.py+++ b/.github/scripts/workflow_rerun/log_collector.py@@ -11,7 +11,8 @@ from workflow_rerun.constants import GITHUB_TOKEN, LOGGERdef collect_logs_for_run(run: WorkflowRun,- logs_dir: Path) -> Path:+ logs_dir: Path,+ session: requests.Session) -> Path:"""Downloads logs of a given Workflow Run,saves them to a specified path, and returns that path.@@ -73,8 +74,8 @@ def collect_logs_for_run(run: WorkflowRun,LOGGER.info(f'DOWNLOADING LOGS FOR RUN ID {run.id}')# PyGitHub does not expose the "/repos/{owner}/{repo}/actions/runs/{run_id}/logs" endpoint so we have to use requestsLOGGER.debug(f'Downloading logs from {run.logs_url}')- response = requests.get(url=run.logs_url,- headers={'Authorization': f'Bearer {GITHUB_TOKEN}'})+ response = session.get(url=run.logs_url,+ headers={'Authorization': f'Bearer {GITHUB_TOKEN}'})response.raise_for_status()log_archive.write(response.content)diff --git a/.github/scripts/workflow_rerun/rerunner.py b/.github/scripts/workflow_rerun/rerunner.pyindex 076c8f2d314..1c98f25dcaa 100644--- a/.github/scripts/workflow_rerun/rerunner.py+++ b/.github/scripts/workflow_rerun/rerunner.py@@ -10,14 +10,21 @@ from psycopg2 import sqlimport requestsfrom github import Github, Auth+from requests.adapters import HTTPAdapter+from requests.packages.urllib3.util.retry import Retry+from workflow_rerun.argument_parser import get_argumentsfrom workflow_rerun.constants import GITHUB_TOKEN, LOGGERfrom workflow_rerun.log_analyzer import LogAnalyzerfrom workflow_rerun.log_collector import collect_logs_for_run-def record_rerun_to_db(repository_full_name: str, run_id: int, ticket_number: int):+def record_rerun_to_db(repository_full_name: str, run_id: int, ticket_number: int, rerunner_run_id: int, error_text: str):"""Record the rerun event to the PostgreSQL database."""+ if ticket_number is None:+ LOGGER.error('No ticket number provided, cannot record rerun to database.')+ raise ValueError('Ticket number is required to record rerun to database.')+db_username = os.environ.get('PGUSER')db_password = os.environ.get('PGPASSWORD')db_host = os.environ.get('PGHOST')@@ -34,15 +41,15 @@ def record_rerun_to_db(repository_full_name: str, run_id: int, ticket_number: incursor = conn.cursor()insert_query = sql.SQL("""- INSERT INTO rerunner_stats (repository_full_name, run_id, ticket_number, rerun_at)- VALUES (%s, %s, %s, NOW() AT TIME ZONE 'UTC')+ INSERT INTO rerunner_stats (repository_full_name, run_id, ticket_number, rerun_at, rerunner_run_id, error_text)+ VALUES (%s, %s, %s, NOW() AT TIME ZONE 'UTC', %s, %s)""")- cursor.execute(insert_query, (repository_full_name, run_id, ticket_number))+ cursor.execute(insert_query, (repository_full_name, run_id, ticket_number, rerunner_run_id, error_text))conn.commit()LOGGER.info(f'Successfully recorded rerun to database: repo={repository_full_name}, '- f'run_id={run_id}, ticket={ticket_number}')+ f'run_id={run_id}, ticket={ticket_number}, rerunner_run_id={rerunner_run_id}, error_text={error_text}')except psycopg2.Error as e:LOGGER.error(f'Failed to record rerun to database: {e}')@@ -53,18 +60,25 @@ def record_rerun_to_db(repository_full_name: str, run_id: int, ticket_number: incursor.close()conn.close()--if __name__ == '__main__':-args = get_arguments()run_id = args.run_id+ rerunner_run_id = args.rerunner_run_idrepository_name = args.repository_nameerrors_file = args.errors_to_look_for_fileis_dry_run = args.dry_runif is_dry_run:LOGGER.info('RUNNING IN DRY RUN MODE. IF ERROR WILL BE FOUND, WILL NOT RETRIGGER')+ session = requests.Session()+ retry_strategy = Retry(+ total=5,+ backoff_factor=3,+ backoff_jitter=1,+ status_forcelist=[429, 500, 502, 503, 504]+ )+ session.mount("https://github.com", HTTPAdapter(max_retries=retry_strategy))+github = Github(auth=Auth.Token(token=GITHUB_TOKEN))gh_repo = github.get_repo(full_name_or_id=repository_name)run = gh_repo.get_workflow_run(id_=run_id)@@ -82,6 +96,7 @@ if __name__ == '__main__':collect_logs_for_run(run=run,logs_dir=logs_dir,+ session=session)log_analyzer = LogAnalyzer(@@ -98,18 +113,8 @@ if __name__ == '__main__':# PyGitHub does not expose the "/repos/{owner}/{repo}/actions/runs/RUN_ID/rerun-failed-jobs" endpoint# so we have to use requests- response = requests.post(url=f'https://api.github.com/repos/{repository_name}/actions/runs/{run_id}/rerun-failed-jobs',+ response = session.post(url=f'https://api.github.com/repos/{repository_name}/actions/runs/{run_id}/rerun-failed-jobs',headers={'Authorization': f'Bearer {GITHUB_TOKEN}'})- status = response.status_code == 201-- if status:- LOGGER.info(f'RUN RETRIGGERED SUCCESSFULLY: {run.html_url}')- record_rerun_to_db(repository_name, run_id,- log_analyzer.found_error_ticket)- else:- LOGGER.info(f'RUN WAS NOT RETRIGGERED, SEE ABOVE')-- # "status" is True (which is 1) if everything is ok, False (which is 0) otherwise- sys.exit(not status)+ response.raise_for_status()else:LOGGER.info(f'NO ERROR WAS FOUND, NOT RETRIGGERING')diff --git a/.github/scripts/workflow_rerun/tests/integration_test.py b/.github/scripts/workflow_rerun/tests/integration_test.pyindex f54ed85daf0..1a4a6aaf015 100644--- a/.github/scripts/workflow_rerun/tests/integration_test.py+++ b/.github/scripts/workflow_rerun/tests/integration_test.py@@ -8,10 +8,13 @@ Integration testsimport unittestfrom pathlib import Pathfrom datetime import datetime, timedelta-from github import Github, Authimport osimport tempfile+import requests+from github import Github, Auth+from requests.adapters import HTTPAdapter+from requests.packages.urllib3.util.retry import Retryfrom workflow_rerun.log_analyzer import LogAnalyzerfrom workflow_rerun.log_collector import collect_logs_for_run@@ -28,6 +31,16 @@ class IntegrationTest(unittest.TestCase):cls.errors_to_look_for_file = cls._cwd.parent.joinpath('errors_to_look_for.json')++ cls.session = requests.Session()+ retry_strategy = Retry(+ total=5,+ backoff_factor=3,+ backoff_jitter=1,+ status_forcelist=[429, 500, 502, 503, 504]+ )+ cls.session.mount("https://github.com", HTTPAdapter(max_retries=retry_strategy))+cls.github = Github(auth=Auth.Token(token=os.environ.get('GITHUB_TOKEN')))gh_repo = cls.github.get_repo(full_name_or_id='openvinotoolkit/openvino')@@ -50,7 +63,8 @@ class IntegrationTest(unittest.TestCase):with tempfile.TemporaryDirectory() as temp_dir:logs_dir = Path(temp_dir)collect_logs_for_run(run=self.wf_run,- logs_dir=logs_dir)+ logs_dir=logs_dir,+ session=self.session)analyzer = LogAnalyzer(path_to_logs=logs_dir,diff --git a/.github/scripts/workflow_rerun/tests/log_collector_test.py b/.github/scripts/workflow_rerun/tests/log_collector_test.pyindex 0b5a8207abd..e818c1e270d 100644--- a/.github/scripts/workflow_rerun/tests/log_collector_test.py+++ b/.github/scripts/workflow_rerun/tests/log_collector_test.py@@ -11,7 +11,10 @@ import tempfilefrom pathlib import Pathfrom datetime import datetime, timedelta+import requestsfrom github import Github, Auth+from requests.adapters import HTTPAdapter+from requests.packages.urllib3.util.retry import Retryfrom workflow_rerun.log_collector import collect_logs_for_run@@ -23,6 +26,15 @@ class LogCollectorTest(unittest.TestCase):@classmethoddef setUpClass(cls) -> None:+ cls.session = requests.Session()+ retry_strategy = Retry(+ total=5,+ backoff_factor=3,+ backoff_jitter=1,+ status_forcelist=[429, 500, 502, 503, 504]+ )+ cls.session.mount("https://github.com", HTTPAdapter(max_retries=retry_strategy))+cls.github = Github(auth=Auth.Token(token=os.environ.get('GITHUB_TOKEN')))gh_repo = cls.github.get_repo(full_name_or_id='openvinotoolkit/openvino')@@ -47,7 +59,7 @@ class LogCollectorTest(unittest.TestCase):"""with tempfile.TemporaryDirectory() as temp_dir:logs_dir = Path(temp_dir)- collect_logs_for_run(run=self.failed_workflow_run, logs_dir=logs_dir)+ collect_logs_for_run(run=self.failed_workflow_run, logs_dir=logs_dir, session=self.session)self.assertTrue(any(logs_dir.iterdir()),'Logs directory should not be empty for failed runs')@@ -57,7 +69,7 @@ class LogCollectorTest(unittest.TestCase):"""with tempfile.TemporaryDirectory() as temp_dir:logs_dir = Path(temp_dir)- collect_logs_for_run(run=self.successful_workflow_run, logs_dir=logs_dir)+ collect_logs_for_run(run=self.successful_workflow_run, logs_dir=logs_dir, session=self.session)self.assertFalse(any(logs_dir.iterdir()),'Logs directory should be empty for successful runs')diff --git a/.github/workflows/workflow_rerunner.yml b/.github/workflows/workflow_rerunner.ymlindex fbabe700c55..dad1ac303eb 100644--- a/.github/workflows/workflow_rerunner.yml+++ b/.github/workflows/workflow_rerunner.yml@@ -72,6 +72,7 @@ jobs:export PYTHONPATH=${{ github.workspace }}/.github/scripts/workflow_rerun:${{ github.workspace }}/.github/scripts:$PYTHONPATHpython3 ${{ github.workspace }}/.github/scripts/workflow_rerun/rerunner.py \--run-id ${{ github.event.workflow_run.id }} \+ --rerunner-run-id ${{ github.run_id }} \--repository-name ${GITHUB_REPOSITORY}rerunner_tests:@@ -109,4 +110,4 @@ jobs:# cannot lock a run id as logs get deleted after some timerun_id=$(python3 -c "from github import Github, Auth; import os; github=Github(auth=Auth.Token(token=os.environ.get('GITHUB_TOKEN'))); repo = github.get_repo('${GITHUB_REPOSITORY}'); run_id = repo.get_workflow_runs(status='success')[0].id; print(run_id)")- python3 rerunner.py --repository-name ${GITHUB_REPOSITORY} --run-id $run_id --dry-run+ python3 rerunner.py --repository-name ${GITHUB_REPOSITORY} --run-id $run_id --rerunner-run-id ${{ github.run_id }} --dry-run