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 rerunner trigger events to the database (#31931)
Andrey Babushkin1549a791573a
diff --git a/.github/scripts/workflow_rerun/rerunner.py b/.github/scripts/workflow_rerun/rerunner.pyindex b37f51e282a..798a0ec271b 100644--- a/.github/scripts/workflow_rerun/rerunner.py+++ b/.github/scripts/workflow_rerun/rerunner.py@@ -4,7 +4,9 @@import osimport sysimport tempfile+import psycopg2from pathlib import Path+from psycopg2 import sqlimport requestsfrom github import Github, Auth@@ -13,6 +15,45 @@ from 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):+ """Record the rerun event to the PostgreSQL database."""++ db_username = os.environ.get('PGUSER')+ db_password = os.environ.get('PGPASSWORD')+ db_host = os.environ.get('PGHOST')+ db_database = os.environ.get('PGDATABASE')+ db_port = os.environ.get('PGPORT')+ conn = psycopg2.connect(host=db_host,+ port=db_port,+ user=db_username,+ password=db_password,+ database=db_database)++ cursor = None+ try:+ cursor = 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')+ """)++ cursor.execute(insert_query, (repository_full_name, run_id, ticket_number))+ conn.commit()++ LOGGER.info(f'Successfully recorded rerun to database: repo={repository_full_name}, '+ f'run_id={run_id}, ticket={ticket_number}')++ except psycopg2.Error as e:+ LOGGER.error(f'Failed to record rerun to database: {e}')+ conn.rollback()+ raise+ finally:+ if cursor:+ cursor.close()+ conn.close()++if __name__ == '__main__':@@ -60,18 +101,14 @@ if __name__ == '__main__':response = requests.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')- # Needed to run a step after for statistics- with open(file=os.environ['GITHUB_ENV'],- mode='a') as fh:- fh.write('PIPELINE_RETRIGGERED=true\n')- fh.write(f'FOUND_ERROR_TICKET={log_analyzer.found_error_ticket}\n')-# "status" is True (which is 1) if everything is ok, False (which is 0) otherwisesys.exit(not status)else:diff --git a/.github/workflows/workflow_rerunner.yml b/.github/workflows/workflow_rerunner.ymlindex 823e14a7581..46bccb29b54 100644--- a/.github/workflows/workflow_rerunner.yml+++ b/.github/workflows/workflow_rerunner.yml@@ -52,7 +52,7 @@ jobs:sparse-checkout: '.github/scripts/workflow_rerun'- name: Install deps- run: pip3 install PyGithub==2.2.0 requests==2.31.0+ run: pip3 install PyGithub==2.2.0 requests==2.31.0 psycopg2-binary==2.9.9- name: Dump GitHub contextenv:@@ -62,20 +62,17 @@ jobs:- name: Rerunenv:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ PGHOST: ${{ secrets.METRICS_DATABASE_HOST }}+ PGUSER: ${{ secrets.METRICS_DATABASE_USERNAME }}+ PGPASSWORD: ${{ secrets.METRICS_DATABASE_PASSWORD }}+ PGDATABASE: ${{ secrets.METRICS_DATABASE_NAME }}+ PGPORT: 5432run: |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 }} \--repository-name ${GITHUB_REPOSITORY}- - name: Rerun Retriggered (Ticket ${{ env.FOUND_ERROR_TICKET }})- if: ${{ env.PIPELINE_RETRIGGERED == 'true' }}- run: echo "Rerun retriggered for ${{ github.event.workflow_run.html_url }} with ticket ${{ env.FOUND_ERROR_TICKET }}"-- - name: ${{ github.event.workflow_run.html_url }}- if: ${{ env.PIPELINE_RETRIGGERED == 'true' }}- run: echo "Step for statistics gathering"-rerunner_tests:name: Rerunner Testsif: ${{ github.event_name == 'pull_request' && github.repository_owner == 'openvinotoolkit' }}@@ -89,7 +86,7 @@ jobs:lfs: true- name: Install deps- run: pip3 install PyGithub==2.2.0 requests==2.31.0+ run: pip3 install PyGithub==2.2.0 requests==2.31.0 psycopg2-binary==2.9.9- name: Test Rerunner (Tests)env: