From 5b995c3cc4de19cb68c2aa590f68469b8c94add8 Mon Sep 17 00:00:00 2001 From: Ignas Kiela Date: Wed, 8 Dec 2021 00:06:33 +0200 Subject: [PATCH] Monitor build log cache hits --- buildsrht/blueprints/jobs.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/buildsrht/blueprints/jobs.py b/buildsrht/blueprints/jobs.py index a354c64..31897cb 100644 --- a/buildsrht/blueprints/jobs.py +++ b/buildsrht/blueprints/jobs.py @@ -14,6 +14,7 @@ from buildsrht.manifest import Manifest from buildsrht.rss import generate_feed from buildsrht.runner import queue_build, requires_payment from buildsrht.search import apply_search +from prometheus_client import Counter from jinja2 import Markup, escape import sqlalchemy as sa import hashlib @@ -24,6 +25,15 @@ import textwrap jobs = Blueprint("jobs", __name__) +metrics = type("metrics", tuple(), { + c.describe()[0].name: c + for c in [ + Counter("buildsrht_logcache_hit", "Number of log cache hits"), + Counter("buildsrht_logcache_miss", "Number of log cache misses"), + ] +}) + + def tags(tags): if not tags: return list() @@ -419,9 +429,11 @@ def job_by_id(username, job_id): cachekey = f"builds.sr.ht:logs:{log_url}" log = get_cache(cachekey) if log: + metrics.buildsrht_logcache_hit.inc() log = json.loads(log) log["log"] = Markup(log["log"]) if not log: + metrics.buildsrht_logcache_miss.inc() try: r = requests.head(log_url) cl = int(r.headers["Content-Length"]) -- 2.38.5