From 690f1aa16c77e418dc40109cd5e8fdf4a7ed947a Mon Sep 17 00:00:00 2001 From: Ignas Kiela Date: Wed, 8 Dec 2021 10:19:53 +0200 Subject: [PATCH] Add build submission and queue monitoring --- buildsrht/app.py | 3 +++ buildsrht/runner.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/buildsrht/app.py b/buildsrht/app.py index 7c9977c..e5321a2 100644 --- a/buildsrht/app.py +++ b/buildsrht/app.py @@ -36,6 +36,9 @@ class BuildApp(SrhtFlask): self.register_blueprint(secrets) self.register_blueprint(gql_blueprint) + from buildsrht.runner import builds_queue_metrics_collector + self.metrics_registry.register(builds_queue_metrics_collector) + @self.context_processor def inject(): return { diff --git a/buildsrht/runner.py b/buildsrht/runner.py index 0389c8e..7773452 100644 --- a/buildsrht/runner.py +++ b/buildsrht/runner.py @@ -5,10 +5,13 @@ from srht.config import cfg from srht.database import db from srht.email import send_email from srht.oauth import UserType +from srht.metrics import RedisQueueCollector +from prometheus_client import Counter allow_free = cfg("builds.sr.ht", "allow-free", default="no") == "yes" -runner = Celery('builds', broker=cfg("builds.sr.ht", "redis"), config_source={ +builds_broker = cfg("builds.sr.ht", "redis") +runner = Celery('builds', broker=builds_broker, config_source={ "CELERY_TASK_SERIALIZER": "json", "CELERY_ACCEPT_CONTENT": ["json"], "CELERY_RESULT_SERIALIZER": "json", @@ -16,6 +19,9 @@ runner = Celery('builds', broker=cfg("builds.sr.ht", "redis"), config_source={ "CELERY_TASK_PROTOCOL": 1 }) +builds_queue_metrics_collector = RedisQueueCollector(builds_broker, "buildsrht_builds", "Number of builds currently in queue") +builds_submitted = Counter("buildsrht_builds_submited", "Number of builds submitted") + def queue_build(job, manifest): from buildsrht.types import JobStatus job.status = JobStatus.queued @@ -28,6 +34,7 @@ def queue_build(job, manifest): cfg("sr.ht", "owner-email"), "Cryptocurrency mining attempt on builds.sr.ht") else: + builds_submitted.inc() run_build.delay(job.id, manifest.to_dict()) def requires_payment(user): -- 2.38.5