mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: Add Prometheus metrics for requests
Adds gauge for requests by type and status Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
e45878a058
commit
375895f080
3 changed files with 31 additions and 3 deletions
|
@ -24,6 +24,12 @@ PACKAGES = Gauge(
|
||||||
["state"],
|
["state"],
|
||||||
multiprocess_mode="livemax",
|
multiprocess_mode="livemax",
|
||||||
)
|
)
|
||||||
|
REQUESTS = Gauge(
|
||||||
|
"aur_requests",
|
||||||
|
"Number of AUR requests by type and status",
|
||||||
|
["type", "status"],
|
||||||
|
multiprocess_mode="livemax",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def instrumentator():
|
def instrumentator():
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
from aurweb import config, db, time
|
from aurweb import config, db, time
|
||||||
from aurweb.cache import db_count_cache
|
from aurweb.cache import db_count_cache, db_query_cache
|
||||||
from aurweb.models import PackageBase, PackageRequest, User
|
from aurweb.models import PackageBase, PackageRequest, RequestType, User
|
||||||
from aurweb.models.account_type import TRUSTED_USER_AND_DEV_ID, TRUSTED_USER_ID, USER_ID
|
from aurweb.models.account_type import TRUSTED_USER_AND_DEV_ID, TRUSTED_USER_ID, USER_ID
|
||||||
from aurweb.models.package_request import (
|
from aurweb.models.package_request import (
|
||||||
ACCEPTED_ID,
|
ACCEPTED_ID,
|
||||||
|
@ -8,7 +10,7 @@ from aurweb.models.package_request import (
|
||||||
PENDING_ID,
|
PENDING_ID,
|
||||||
REJECTED_ID,
|
REJECTED_ID,
|
||||||
)
|
)
|
||||||
from aurweb.prometheus import PACKAGES, USERS
|
from aurweb.prometheus import PACKAGES, REQUESTS, USERS
|
||||||
|
|
||||||
cache_expire = config.getint("cache", "expiry_time_statistics", 300)
|
cache_expire = config.getint("cache", "expiry_time_statistics", 300)
|
||||||
|
|
||||||
|
@ -131,6 +133,20 @@ def update_prometheus_metrics():
|
||||||
count = stats.get_count(counter)
|
count = stats.get_count(counter)
|
||||||
PACKAGES.labels(state).set(count)
|
PACKAGES.labels(state).set(count)
|
||||||
|
|
||||||
|
# Requests gauge
|
||||||
|
query = (
|
||||||
|
db.get_session()
|
||||||
|
.query(PackageRequest, func.count(PackageRequest.ID), RequestType.Name)
|
||||||
|
.join(RequestType)
|
||||||
|
.group_by(RequestType.Name, PackageRequest.Status)
|
||||||
|
)
|
||||||
|
results = db_query_cache("request_metrics", query, cache_expire)
|
||||||
|
for record in results:
|
||||||
|
status = record[0].status_display()
|
||||||
|
count = record[1]
|
||||||
|
rtype = record[2]
|
||||||
|
REQUESTS.labels(type=rtype, status=status).set(count)
|
||||||
|
|
||||||
|
|
||||||
def _get_counts(counters: list[str]) -> dict[str, int]:
|
def _get_counts(counters: list[str]) -> dict[str, int]:
|
||||||
stats = Statistics(cache_expire)
|
stats = Statistics(cache_expire)
|
||||||
|
|
|
@ -144,6 +144,7 @@ def test_update_prometheus_metrics(test_data):
|
||||||
|
|
||||||
assert "aur_users{" not in metrics
|
assert "aur_users{" not in metrics
|
||||||
assert "aur_packages{" not in metrics
|
assert "aur_packages{" not in metrics
|
||||||
|
assert "aur_requests{" not in metrics
|
||||||
|
|
||||||
# Let's update our metrics. We should find our gauges now
|
# Let's update our metrics. We should find our gauges now
|
||||||
update_prometheus_metrics()
|
update_prometheus_metrics()
|
||||||
|
@ -151,3 +152,8 @@ def test_update_prometheus_metrics(test_data):
|
||||||
|
|
||||||
assert 'aur_users{type="user"} 9.0' in metrics
|
assert 'aur_users{type="user"} 9.0' in metrics
|
||||||
assert 'aur_packages{state="updated"} 9.0' in metrics
|
assert 'aur_packages{state="updated"} 9.0' in metrics
|
||||||
|
assert 'aur_requests{status="Pending",type="orphan"} 6.0' in metrics
|
||||||
|
assert 'aur_requests{status="Closed",type="orphan"} 1.0' in metrics
|
||||||
|
assert 'aur_requests{status="Accepted",type="orphan"} 1.0' in metrics
|
||||||
|
assert 'aur_requests{status="Rejected",type="orphan"} 1.0' in metrics
|
||||||
|
assert 'aur_requests{status="Pending",type="deletion"} 1.0' in metrics
|
||||||
|
|
Loading…
Add table
Reference in a new issue