Repository navigation
feat(webapp): 指标注册表与 /health /ready /metrics(#71) - #78
Merged
Merged
Conversation
核心层新增 `uvcpp_metrics_registry`(无外部依赖、无线程/定时器/单例):
Counter / Gauge / Histogram,线程安全,`render()` 输出 Prometheus 文本
(0.0.4 格式:`# HELP` / `# TYPE` / `_bucket{le}` 累计桶 / `+Inf` / `_sum` /
`_count`,标签按名字排序、值转义),另有"渲染时取值"的回调 Gauge
(给连接池 `in_use()`、线程池深度这类本来在别处维护的数)。
webapp 层新增 `uvcpp_web_metrics`:
- `/health`:恒 200(liveness 不查依赖);
- `/ready`:`set_ready_check()` 返回 false 时 503 + 原因,每请求现问;
- `/metrics`:Prometheus 文本;
- 可选请求中间件(默认开,注册在最外层):`http_requests_total{method,status}`、
`http_request_duration_ms{method}`(默认 1..10000 ms 桶)、
`http_requests_in_flight`;连接数用回调 Gauge `uvcpp_web_app_connections`;
- 标签只放有限集合(方法/状态码),**不放 URL 原串**(高基数)——路由维度让业务
自己按路由模式计数。
用例 `web_app_metrics_func`:注册表文本/转义/桶/并发更新 + 真端口上的
`/health`、`/ready` 的 200/503 切换、`/metrics` 里 200/404/503 计数与直方图、
在途 Gauge 归零、连接数回调 Gauge。文档 `doc/webapp-guide.md` §20。
本地 build-all 163/163、build-h3/default 编过;文档门禁全绿。
Antruly
force-pushed
the
feat/webapp-metrics
branch
from
November 21, 2026 14:59
52042e1 to
22a6256
Compare
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.
Closes #71.
内容
核心层
uvcpp_metrics_registry(src/uvcpp/,无外部依赖、无后台线程/定时器/单例):render()输出 Prometheus 文本格式(# HELP/# TYPE、_bucket{le}累计桶、+Inf、_sum/_count,标签按名字排序、值按文本格式转义);register_gauge(name, help, fn):渲染时取值,给连接池in_use()、线程池深度这类本来在别处维护的数用(回调在锁外跑)。webapp 层
uvcpp_web_metrics:GET /health:恒 200(liveness 不查依赖 —— 数据库挂了该摘流量,不该重启进程);GET /ready:set_ready_check()返回 false 时 503,body 带原因;每个请求现问一次;GET /metrics:Prometheus 文本(text/plain; version=0.0.4);http_requests_total{method,status}、http_request_duration_ms{method}(默认 1..10000 ms 桶)、http_requests_in_flight;连接数用回调 Gaugeuvcpp_web_app_connections;install()时零成本。用例
web_app_metrics_func.cpp:le累计桶、+Inf、_sum/_count、回调 Gauge、4 线程 × 5000 次并发自增无丢失(并发同时 render);uvcpp_web_app+ 真 TCP 客户端):/health200;/ready在 200 / 503(带原因)之间切换;/metrics里能看到 200/404/503 计数、耗时直方图、直接渲染时在途 Gauge 为 0(HTTP 请求里为 1,即渲染它的这条请求自己)、连接数回调 Gauge。验证
check_docs/check_doc_lines/check_doc_versions/check_ci_layout全绿。(本分支基于当前
master;runner 漂移那几条红会由 #77 合入后 rebase 掉。)