-
-
Notifications
You must be signed in to change notification settings - Fork 130
Add prometheus metrics, option to cap per-search results, optimizations #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d3ec1ff
9e5cb73
8fdc83b
2f4a5d5
3ba68a6
00ac6f4
3150349
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Branch Summary | ||
|
|
||
| - Added replica-aware database routing (`comet/core/db_router.py`, `comet/core/database.py`, `comet/core/models.py`), letting PostgreSQL deployments list `DATABASE_READ_REPLICA_URLS` so reads can go to replicas while writes remain on the primary, plus a force-primary escape hatch inside maintenance queries. | ||
| - Reduced startup thrash by gating the heavy cleanup sweep behind `DATABASE_STARTUP_CLEANUP_INTERVAL` and persisting anime mapping data in `anime_mapping_cache` tables so most boots load instantly from the DB instead of redownloading (`comet/core/database.py`, `comet/services/anime.py`, env knobs `ANIME_MAPPING_SOURCE`/`ANIME_MAPPING_REFRESH_INTERVAL`). | ||
| - Hardened torrent ingestion and ranking: `TorrentManager` now funnels inserts through an `INSERT ... ON CONFLICT DO UPDATE` helper to quiet duplicate-key races, and ranking/logging paths gained small cleanups (`comet/services/torrent_manager.py`, `comet/services/lock.py`, logging tweaks in `comet/core/log_levels.py`). | ||
| - Added an env-toggle to skip Gunicorn preload (`GUNICORN_PRELOAD_APP`) so large deployments can trade startup cost vs. schema-read requirements (`comet/main.py`, `.env-sample`). | ||
| - Introduced `DISABLE_TORRENT_STREAMS` plus customizable placeholder metadata so operators can block magnet-only usage and show a friendly Stremio message instead (`comet/api/endpoints/stream.py`, `comet/core/models.py`, `.env-sample`). | ||
| - Updated documentation/config samples and changelog to capture the new settings and behavior (`.env-sample`, `CHANGELOG.md`). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from fastapi import APIRouter | ||
|
|
||
| from comet.core.metrics import prom_response | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get("/metrics") | ||
| async def metrics_endpoint(): | ||
| return prom_response() | ||
|
Comment on lines
+1
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: rg -n "PUBLIC_METRICS_API" --type=py -C3Repository: g0ldyy/comet Length of output: 1522 LGTM! Metrics endpoint should respect PUBLIC_METRICS_API setting. The implementation is clean and minimal. However, the metrics endpoint doesn't check from fastapi import APIRouter, Cookie
from comet.core.metrics import prom_response
from comet.api.endpoints.admin import require_admin_auth
router = APIRouter()
@router.get("/metrics")
async def metrics_endpoint(admin_session: str = Cookie(None)):
if not settings.PUBLIC_METRICS_API:
await require_admin_auth(admin_session)
return prom_response()🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from fastapi import Response | ||
| from prometheus_client import (CONTENT_TYPE_LATEST, CollectorRegistry, Counter, | ||
| generate_latest) | ||
|
|
||
| # Dedicated registry so we only expose Comet-specific metrics | ||
| _registry = CollectorRegistry() | ||
|
|
||
| _stream_requests_total = Counter( | ||
| "comet_stream_requests_total", | ||
| "Total number of stream requests grouped by debrid service", | ||
| ["debrid_service"], | ||
| registry=_registry, | ||
| ) | ||
|
|
||
| _non_debrid_stream_requests_total = Counter( | ||
| "comet_stream_requests_non_debrid_total", | ||
| "Total number of stream requests that do not require a user API key", | ||
| registry=_registry, | ||
| ) | ||
|
Comment on lines
+1
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prometheus label cardinality: ensure If 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def record_stream_request(debrid_service: str | None): | ||
| """Increment the stream request counter for the provided service.""" | ||
| label = (debrid_service or "unknown").lower() | ||
| _stream_requests_total.labels(debrid_service=label).inc() | ||
|
|
||
|
|
||
| def record_non_debrid_stream_request(): | ||
| """Increment the counter tracking torrent (non-API) stream requests.""" | ||
| _non_debrid_stream_requests_total.inc() | ||
|
|
||
|
|
||
| def prom_response() -> Response: | ||
| """Return a Response containing the current Prometheus metrics payload.""" | ||
| payload = generate_latest(_registry) | ||
| return Response(content=payload, media_type=CONTENT_TYPE_LATEST) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR summary misses the PR’s headline features (metrics + server-side result caps + fail-early invalid debrid)
Given the PR title/objectives, add explicit bullets for:
/metricsendpoint + the new counters (and label dimensions)🤖 Prompt for AI Agents