-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
status:todoPlanned but not startedPlanned but not started
Description
🔍 发现的问题 / 原始需求描述
当前 src/codex_a2a_server/metrics.py 模块存在完整的指标埋点逻辑(生产方),业务代码如 request_handler.py 和 stream_processor.py 也在积极调用 inc_counter/inc_gauge 记录数据。然而,生产代码中缺失对应的“消费方”:
snapshot_metrics()和reset_metrics()函数目前仅在单元测试中被调用。- FastAPI 应用中未挂载
/metrics或类似的监控接口,导致运行时的内存指标无法被外部运维系统(如 Prometheus)或开发者感知。
🛠️ 详细实施方案
涉及文件:src/codex_a2a_server/server/application.py, src/codex_a2a_server/metrics.py
方案建议:
- 暴露监控接口:在
create_app函数中增加一个内部路由(受配置开关控制,例如a2a_enable_metrics_endpoint),调用snapshot_metrics()并返回 JSON 格式的指标快照。 - 清理或移动:若短期内无监控需求,应将
snapshot_metrics和reset_metrics标记为仅限测试使用,或移动到测试支持目录中,以消除静态扫描中的“死代码”警告。 - 完善文档:在
README.md或相关运维文档中说明如何获取服务运行指标。
核心逻辑示例:
# src/codex_a2a_server/server/application.py
if settings.a2a_enable_metrics_endpoint:
@app.get("/metrics")
async def get_metrics():
return snapshot_metrics()🧪 回归测试建议
- 运行
pytest tests/execution/test_metrics.py确保现有断言依然通过。 - 启动服务后,手动请求
GET /metrics(若已实现),验证返回的counters和gauges是否随业务操作(如发起流请求)实时更新。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status:todoPlanned but not startedPlanned but not started