Files
Scrobbler/tests/test_app.py
T
mattandClaude Opus 5.5 ea705589f1
CI / lint (push) Successful in 9s
CI / test (push) Successful in 36s
CI / notify (push) Successful in 5s
Monitoring stack, containers and dashboards
- API image (uv multi-stage, non-root, gunicorn, migrations on start,
  health check) and UI image (nginx, CSP, config.js rendered from
  API_BASE_URL); /healthz documented in OpenAPI
- docker compose runs db, api and ui; the "monitoring" profile adds
  Prometheus, postgres-exporter and Grafana, all provisioned from files
- Grafana dashboards: API overview (RED), Last.fm API, Usage, Database
- Prometheus alert rules: API down, error rate, latency, auth failure
  spike, ignored scrobbles, DB pool saturation, Postgres down
- Pool checkout gauge counts events (the pool's own counters lag the
  checkin event); error ratios show 0 instead of "No data"
- Tests check dashboards and alerts only use metrics that exist
- scripts/generate_traffic.py drives realistic traffic for demos

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-25 14:26:19 +01:00

38 lines
1.0 KiB
Python

from sqlalchemy import inspect
from scrobbler import __version__
from scrobbler.extensions import db
def test_migrations_create_all_tables(app):
tables = set(inspect(db.engine).get_table_names())
assert {
"users",
"api_apps",
"ui_tokens",
"auth_tokens",
"sessions",
"scrobbles",
"now_playing",
} <= tables
def test_unmatched_requests_use_a_fixed_endpoint_label(client, metric_delta):
requests = metric_delta(
"scrobbler_http_requests_total", endpoint="unmatched", http_method="GET", status="404"
)
client.get("/no/such/path/123")
client.get("/another/random/path")
assert requests.delta == 2
def test_build_info_is_exported(metric_delta):
from prometheus_client import REGISTRY
samples = [s for m in REGISTRY.collect() if m.name == "scrobbler_build_info" for s in m.samples]
assert samples and samples[0].labels["version"] == __version__
def test_healthz(client):
assert client.get("/healthz").get_json() == {"status": "ok"}