~comcloudway/builds.sr.ht

5b995c3cc4de19cb68c2aa590f68469b8c94add8 — Ignas Kiela 2 years ago 97fcc9e
Monitor build log cache hits
1 files changed, 12 insertions(+), 0 deletions(-)

M buildsrht/blueprints/jobs.py
M buildsrht/blueprints/jobs.py => buildsrht/blueprints/jobs.py +12 -0
@@ 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"])