From 73480c8fef55088d7cc3a351138252239b018cd4 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 9 Mar 2023 11:42:06 -0700 Subject: [PATCH] run_tasks: Add instrumentation for task time Signed-off-by: Zack Cerza --- teuthology/exporter.py | 6 ++++++ teuthology/run_tasks.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/teuthology/exporter.py b/teuthology/exporter.py index b3ee9dcf2..776cc873b 100644 --- a/teuthology/exporter.py +++ b/teuthology/exporter.py @@ -194,6 +194,12 @@ JobTime = Summary( ["suite"], ) +TaskTime = Summary( + "teuthology_task_duration_seconds", + "Time spent executing a task", + ["name", "phase"], +) + def main(args): exporter = TeuthologyExporter(interval=int(args["--interval"])) diff --git a/teuthology/run_tasks.py b/teuthology/run_tasks.py index 598947c80..e40830ca6 100644 --- a/teuthology/run_tasks.py +++ b/teuthology/run_tasks.py @@ -11,6 +11,8 @@ from copy import deepcopy from humanfriendly import format_timespan import sentry_sdk +import teuthology.exporter as exporter + from teuthology.config import config as teuth_config from teuthology.exceptions import ConnectionLostError from teuthology.job_status import set_status, get_status @@ -103,7 +105,8 @@ def run_tasks(tasks, ctx): manager = run_one_task(taskname, ctx=ctx, config=config) if hasattr(manager, '__enter__'): stack.append((taskname, manager)) - manager.__enter__() + with exporter.TaskTime.labels(taskname, "enter").time(): + manager.__enter__() except BaseException as e: if isinstance(e, ConnectionLostError): # Prevent connection issues being flagged as failures @@ -185,7 +188,8 @@ def run_tasks(tasks, ctx): log.debug('Unwinding manager %s', taskname) timer.mark('%s exit' % taskname) try: - suppress = manager.__exit__(*exc_info) + with exporter.TaskTime.labels(taskname, "exit").time(): + suppress = manager.__exit__(*exc_info) except Exception as e: if isinstance(e, ConnectionLostError): # Prevent connection issues being flagged as failures -- 2.47.3