From 0acc31a00136e8a954629888e1a822e3fa111020 Mon Sep 17 00:00:00 2001 From: Guilherme Gallo Date: Fri, 26 Jul 2024 12:48:32 -0300 Subject: [PATCH] bin/ci: crnm: Reduce trace cluttering Some recurrent messages are only cluttering the ci_run_n_monitor's logs, so let's use the easily provided @cache decorator to print stuff that the user will only needs to see once. Also removes some junk that can happen during the pipeline monitoring loop, like the "----" line break, and newlines. Signed-off-by: Guilherme Gallo Part-of: --- bin/ci/ci_run_n_monitor.py | 13 +++++++------ bin/ci/gitlab_common.py | 9 ++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bin/ci/ci_run_n_monitor.py b/bin/ci/ci_run_n_monitor.py index c9e7db1f392..eab53110080 100755 --- a/bin/ci/ci_run_n_monitor.py +++ b/bin/ci/ci_run_n_monitor.py @@ -33,6 +33,7 @@ from gitlab_common import ( get_gitlab_project, get_token_from_default_dir, pretty_duration, + print_once, read_token, wait_for_pipeline, ) @@ -79,9 +80,9 @@ def print_job_status( duration = job_duration(job) - print( + print_once( STATUS_COLORS[job.status] - + "🞋 target job " # U+1F78B Round target + + "🞋 job " # U+1F78B Round target + link2print(job.web_url, job.name, job_name_field_pad) + (f"has new status: {job.status}" if new_status else f"{job.status}") + (f" ({pretty_duration(duration)})" if job.started_at else "") @@ -206,10 +207,8 @@ def monitor_pipeline( pretty_wait(REFRESH_WAIT_JOBS) continue - print("---------------------------------", flush=False) - if jobs_waiting: - print( + print_once( f"{Fore.YELLOW}Waiting for jobs to update status:", ", ".join(jobs_waiting), Fore.RESET, @@ -321,7 +320,9 @@ def cancel_jobs( with ThreadPoolExecutor(max_workers=6) as exe: part = partial(cancel_job, project) exe.map(part, to_cancel) - print() + + # The cancelled jobs are printed without a newline + print_once() def print_log( diff --git a/bin/ci/gitlab_common.py b/bin/ci/gitlab_common.py index ee1c0581d6a..1bb41727e32 100644 --- a/bin/ci/gitlab_common.py +++ b/bin/ci/gitlab_common.py @@ -12,6 +12,7 @@ import logging import os import re import time +from functools import cache from pathlib import Path GITLAB_URL = "https://gitlab.freedesktop.org" @@ -28,10 +29,16 @@ TOKEN_PREFIXES: dict[str, str] = { "Feed token": "glft-", "Incoming mail token": "glimt-", "GitLab Agent for Kubernetes token": "glagent-", - "SCIM Tokens": "glsoat-" + "SCIM Tokens": "glsoat-", } +@cache +def print_once(*args, **kwargs): + """Print without spamming the output""" + print(*args, **kwargs) + + def pretty_duration(seconds): """Pretty print duration""" hours, rem = divmod(seconds, 3600)