Repository navigation
feat(serve): add lightweight Prometheus metrics endpoint - #48
Conversation
Reviewer's GuideThe PR introduces a lightweight, dependency-free /metrics endpoint that collects request-load and state-cache data only when scraped, using nonblocking cache snapshots to minimize inference interference; documentation and HTTP coverage describe and validate the behavior. Sequence diagram for Prometheus metrics scrapingsequenceDiagram
participant Prometheus
participant Metrics as /metrics
participant Server
participant Cache as StateCache
Prometheus->>Metrics: GET /metrics
Metrics->>Server: load()
Server-->>Metrics: running and queued
Metrics->>Cache: stats(blocking=False)
alt snapshot available
Cache-->>Metrics: cache statistics
Metrics->>Metrics: update cached snapshot
else cache lock busy
Cache-->>Metrics: None
Metrics->>Metrics: reuse last snapshot
end
Metrics-->>Prometheus: Prometheus text response
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_http_status.py" line_range="127" />
<code_context>
await until(lambda: srv.in_flight == 2)
health.append((await c.get("/health")).json())
+ metrics = await c.get("/metrics")
+ assert "basal_requests_running 1\n" in metrics.text and "basal_requests_queued 1\n" in metrics.text
engine.go.set()
codes = [(await t).status_code for t in (first, second)]
</code_context>
<issue_to_address>
**Hard-coded metrics pass the test**
When the `/metrics` endpoint always emits `basal_requests_running 1` and `basal_requests_queued 1`, the assertion in `test_health_counts_running_and_queued_requests` checks only the `/metrics` response while the expected values are exactly 1 and 1, so an endpoint that always returns those constants passes and broken load reporting goes undetected.
Check the metrics at multiple load states, including idle and running-only, and assert each response matches the current load.
</issue_to_address>|
Thank you, Marcin! Your metrics work is in basal 2.5. While this PR was open, the 2.5 branch got its own |
… for the seven 2.5 pull requests
Problem
basal-serveexposes current load through/health, but has no native Prometheus metrics endpoint.Change
GET /metricsusing Prometheus text format, without additional dependencies.Validation
Summary by Sourcery
Add lightweight Prometheus monitoring for server load, build details, and state-cache performance.
New Features:
/metricsendpoint exposing build, request-load, and state-cache metrics.Enhancements:
Documentation:
Tests: