Skip to content

Update cache_metrics.py #3175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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")