Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions jobs/cache_maintenance/src/cache_maintenance/cache_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ 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():
CacheTotalMetricDocument.objects(kind=kind, http_status=http_status, error_code=error_code).upsert_one(
total=total
)
#add a validation to force total to be non-negative
if total < 0:
logging.warning(f"Negative metric value for {kind=} {http_status=} {error_code=}: {total=}. Setting to 0.")
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")