feat: 可观测性最小集——零依赖指标 + 周期 slog 快照(方向 C)#136
Conversation
新增 pkg/metrics:埋点与暴露解耦。计数器(丢帧/读写/背压)就地累加, 仪表(MemTable 未刷盘字节/预算)经回调实时读取,StartLogger 周期性用默认 slog 打一行快照——headless 边缘设备 tail 日志即可观测,无需端口/Prometheus。 未来可再接 HTTP 出口而无需改埋点。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- ingesthook: 三类丢帧分别计数(畸形/超限/回退) - router: PUT/GET/DEL 读写计数与写错误计数 - memtable: 背压慢路径停顿计数,并注册未刷盘字节数仪表 - Server(两个 main): 每 10s 打印一行指标快照,tail 日志即可观测 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughA new ChangesIn-process metrics observability
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🐯 BanGD 数据库内核评审整体风险:🟢 低 变更总结:该 PR 在 BanDB 中引入了一个零依赖的进程内可观测性层(
埋点散布在三处:ingesthook/filter.go(丢帧三类)、service/router.go(读写/删除/写错误计数)、storage/zstorage/memtable.go(背压停顿计数 + 注册仪表回调)。两个 Server main 入口各启动一次 这是一个纯「观测」改造,不改变任何业务逻辑、不涉及存储格式或 WAL。整体设计合理,把埋点与暴露解耦,底层用
架构问题(共 2 项)
本次评审消耗 token:共 63504 tokens(输入 61516,输出 1988,缓存命中 0,缓存写入 0)|维度 [concurrency, memory, lock, storage, performance]|补充阅读周边文件 [pkg/credit/credit.go]|对抗式复核 3 票/条,过滤疑似误报 0 条 |
背景(采集员视角痛点 #4:野外两眼一抹黑)
BanDB 此前无任何指标——丢了几帧、内存到顶没、写被背压卡住没,全看不到。本 PR 给这个 headless 边缘「服务端」装上仪表盘。
暴露方式选型
选 周期性 slog 快照(而非 expvar/Prometheus/Grafana):边缘设备 headless,任务中无法 curl 端口或开 Grafana,但日志一定读得到。零依赖、零新增端口,贴合「单二进制边缘」定位。埋点与暴露解耦——未来要 HTTP/Prometheus 出口无需改埋点。
改动(两个原子 commit)
1.
pkg/metrics核心 — 零依赖Take()取快照,StartLogger(ctx, interval)周期打印2. 埋点 + 装配
效果
tail日志即可见:测试
go build ./...通过;pkg/metrics单测覆盖计数增量与仪表回调实时读取;service/ingesthook/storage 既有测试不回归。设计为 atomic-only,无锁竞争(race 检测器因本机无 gcc 未跑)。🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Tests
Chores