add a prometheus /metrics endpoint (std.prometheus)#448
Merged
Conversation
first phase of observability support. std.prometheus.serve(host, port) runs an
accept loop that answers GET /metrics with the text exposition of every
registered std.metrics series (labels included), and 404 for anything else.
spawn it alongside an app and prometheus scrapes it on its interval:
spawn prometheus.serve("0.0.0.0", 9464)
it reuses what already exists: metrics.snapshot_text() for the body and the
std.net.http request/response helpers over the raw tcp accept primitives, so no
server framework is needed. the endpoint is read-only and pull-based, so serve()
just renders the current snapshot per request; concurrent scrapes are safe
because the metric maps are mutex-guarded.
verified: a unit test on the response (content type + snapshot), a live
self-scrape (spawn serve, GET /metrics over the http client -> 200 with the
labeled counter and gauge present), a new deterministic example, and 86 examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
first phase of observability support.
std.prometheus.serve(host, port)runs anaccept loop that answers
GET /metricswith the text exposition of everyregistered
std.metricsseries (labels included), 404 otherwise. spawn italongside an app and prometheus scrapes it on its interval:
it reuses what exists —
metrics.snapshot_text()for the body, thestd.net.httprequest/response helpers over the raw
tcp_acceptprimitives — so no serverframework is needed. read-only and pull-based;
serve()renders the currentsnapshot per request, and concurrent scrapes are safe (the metric maps are
mutex-guarded).
part of the observability sprint (prerequisites #441/#445/#446 already landed).
next:
std.trace+ OTLP export.what was tested
metrics_response()(prometheus content type + snapshot present)serve, GET/metricsover the http client → 200with the labeled counter and gauge in the body
examples/prometheus_metrics.pith; 86 examplespure-additive stdlib; no compiler change, no bootstrap seed refresh.