From a2c16f97c7e199b00650008e6c250a76ab8280a4 Mon Sep 17 00:00:00 2001 From: Arjun Dinesh Jagdale <142811259+ArjunJagdale@users.noreply.github.com> Date: Tue, 1 Jul 2025 22:43:21 +0530 Subject: [PATCH] git commit -m "fix(cache_metrics): clamp negative total values before writing to DB" --- jobs/cache_maintenance/src/cache_maintenance/cache_metrics.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jobs/cache_maintenance/src/cache_maintenance/cache_metrics.py b/jobs/cache_maintenance/src/cache_maintenance/cache_metrics.py index dbe015d4b7..8f140ef9b2 100644 --- a/jobs/cache_maintenance/src/cache_maintenance/cache_metrics.py +++ b/jobs/cache_maintenance/src/cache_maintenance/cache_metrics.py @@ -31,9 +31,13 @@ def collect_cache_metrics() -> None: logging.info(f"{kind=} {http_status=} {error_code=} has been deleted") for (kind, http_status, error_code), total in new_metric_by_id.items(): + if total < 0: + logging.warning(f"Corrected negative total for {kind=} {http_status=} {error_code=}: was {total}") + total = max(total, 0) CacheTotalMetricDocument.objects(kind=kind, http_status=http_status, error_code=error_code).upsert_one( total=total ) logging.info(f"{kind=} {http_status=} {error_code=}: {total=} has been inserted") + logging.info("cache metrics have been updated")