- Replace skip-based pagination with cursor-based pagination (timestamp|_id cursors) - Add Prometheus /metrics endpoint with request latency, fetch volume, and error counters - Implement incremental fetch watermarking per source (watermarks collection in MongoDB) - Add Graph change notification webhook endpoint (/api/webhooks/graph) - Add correlation ID middleware for distributed tracing (x-request-id header) - Update frontend to use cursor-based pagination with Prev/Next navigation - Update tests for cursor pagination, metrics, webhooks, and watermark mocking
This commit is contained in:
43
backend/metrics.py
Normal file
43
backend/metrics.py
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
from prometheus_client import Counter, Histogram, generate_latest
|
||||
|
||||
REQUEST_DURATION = Histogram(
|
||||
"aoc_request_duration_seconds",
|
||||
"HTTP request duration",
|
||||
["method", "path", "status"],
|
||||
)
|
||||
EVENTS_FETCHED = Counter(
|
||||
"aoc_events_fetched_total",
|
||||
"Number of audit events fetched per source",
|
||||
["source"],
|
||||
)
|
||||
FETCH_ERRORS = Counter(
|
||||
"aoc_fetch_errors_total",
|
||||
"Number of fetch errors per source",
|
||||
["source"],
|
||||
)
|
||||
FETCH_DURATION = Histogram(
|
||||
"aoc_fetch_duration_seconds",
|
||||
"Duration of fetch jobs per source",
|
||||
["source"],
|
||||
)
|
||||
|
||||
|
||||
def observe_request(method: str, path: str, status: int, duration: float):
|
||||
REQUEST_DURATION.labels(method=method, path=path, status=str(status)).observe(duration)
|
||||
|
||||
|
||||
def track_fetch(source: str, count: int):
|
||||
EVENTS_FETCHED.labels(source=source).inc(count)
|
||||
|
||||
|
||||
def track_fetch_error(source: str):
|
||||
FETCH_ERRORS.labels(source=source).inc()
|
||||
|
||||
|
||||
def track_fetch_duration(source: str, duration: float):
|
||||
FETCH_DURATION.labels(source=source).observe(duration)
|
||||
|
||||
|
||||
def prometheus_metrics():
|
||||
return generate_latest()
|
||||
Reference in New Issue
Block a user