From 2df6a51d45c640b051e27a91d833269ea3df8df8 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 16 Mar 2023 11:28:12 -0600 Subject: [PATCH] exporter: Make JobResults a singleton This should avoid "Duplicated timeseries in CollectorRegistry" errors. Signed-off-by: Zack Cerza --- teuthology/exporter.py | 4 +++- teuthology/kill.py | 2 +- teuthology/report.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/teuthology/exporter.py b/teuthology/exporter.py index af5126c9b4..f1d910da64 100644 --- a/teuthology/exporter.py +++ b/teuthology/exporter.py @@ -169,7 +169,7 @@ class Nodes(TeuthologyMetric): ) -class JobResults(TeuthologyMetric): +class _JobResults(TeuthologyMetric): def __init__(self): self.metric = Counter( "teuthology_job_results", @@ -182,6 +182,8 @@ class JobResults(TeuthologyMetric): self.metric.labels(machine_type=machine_type, status=status).inc() +JobResults = _JobResults() + NodeLockingTime = Summary( "teuthology_node_locking_duration_seconds", "Time spent waiting to lock nodes", diff --git a/teuthology/kill.py b/teuthology/kill.py index c26432a3ca..2df126d9a8 100755 --- a/teuthology/kill.py +++ b/teuthology/kill.py @@ -87,7 +87,7 @@ def kill_job(run_name, job_id, archive_base=None, owner=None, skip_nuke=False): owner = job_info['owner'] kill_processes(run_name, [job_info.get('pid')]) if 'machine_type' in job_info: - teuthology.exporter.JobResults().record( + teuthology.exporter.JobResults.record( job_info["machine_type"], job_info.get("status", "dead") ) diff --git a/teuthology/report.py b/teuthology/report.py index 3b4247e517..e5382133b5 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -474,7 +474,7 @@ def push_job_info(run_name, job_id, job_info, base_uri=None): reporter.report_job(run_name, job_id, job_info) status = get_status(job_info) if status in ["pass", "fail", "dead"] and "machine_type" in job_info: - teuthology.exporter.JobResults().record(job_info["machine_type"], status) + teuthology.exporter.JobResults.record(job_info["machine_type"], status) def try_push_job_info(job_config, extra_info=None): @@ -584,7 +584,7 @@ def try_mark_run_dead(run_name): log.info("Marking job {job_id} as dead".format(job_id=job_id)) reporter.report_job(run_name, job['job_id'], dead=True) if "machine_type" in job: - teuthology.exporter.JobResults().record(job["machine_type"], job["status"]) + teuthology.exporter.JobResults.record(job["machine_type"], job["status"]) except report_exceptions: log.exception("Could not mark job as dead: {job_id}".format( job_id=job_id)) -- 2.39.5