Conversation
在 metrics.py 顶部新增 11 个 Prometheus 指标(Counter/Histogram/Gauge), 保留原有 MetricsCollector 完全不变,确保向后兼容。 新增指标: - HTTP_REQUEST_DURATION / HTTP_REQUESTS_TOTAL - AGENT_EXECUTION_TOTAL / AGENT_EXECUTION_DURATION - LLM_CALLS_TOTAL / LLM_CALL_DURATION - CACHE_QUERIES_TOTAL / CACHE_SIZE / CACHE_HIT_RATE - SYSTEM_UPTIME_SECONDS / ACTIVE_REQUESTS 同时创建 tests/core/test_prometheus_metrics.py 验证 prometheus_client 基本行为,14 条测试全部通过。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 新增 MetricsMiddleware,记录请求到 Prometheus Counter/Histogram - HTTP_REQUEST_DURATION 按 method/endpoint 分桶记录耗时 - HTTP_REQUESTS_TOTAL 按 method/endpoint/status 计数 - ACTIVE_REQUESTS Gauge 在请求开始 +1、结束 -1 - 保留原有 metrics_collector.record_request() 向后兼容 - lifespan 中设置 SYSTEM_UPTIME_SECONDS 为启动时间戳 - 新增 /prometheus 端点返回 Prometheus 文本格式指标 - 原有 /metrics JSON 端点保持不变(向后兼容) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- classify/process/review 节点增加 AGENT_EXECUTION_TOTAL 和 AGENT_EXECUTION_DURATION 指标上报 - handle_failure 节点增加 error 计数 - 使用 time.perf_counter() 计时,try/except/else/finally 保证异常时也能记录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- chat_completions_create 中跳过缓存和缓存未命中两种情况均增加 LLM_CALLS_TOTAL 和 LLM_CALL_DURATION 指标上报 - 缓存命中时不记录 LLM 调用指标(无实际 API 调用) - 使用 time.perf_counter() 计时,finally 保证异常时也能记录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- get 方法中命中/未命中分别增加 CACHE_QUERIES_TOTAL 计数,并更新 CACHE_HIT_RATE - set 方法后更新 CACHE_SIZE - clear 方法后重置 CACHE_SIZE 和 CACHE_HIT_RATE Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ArtLjn
added a commit
that referenced
this pull request
Jul 13, 2026
修复 v1.1 P0 #1:traces.total_tokens 永远为 0,token 控制台无数据源。 - 新增 models/token_stats.py:TokenDailyStatsORM 表 字段:id/user_id(nullable)/date/model/call_type/ticket_id/prompt/completion/ total/request_count/estimated_cost_cny 唯一约束 (user_id, date, model, call_type);3 个索引 call_type 6 枚举:intent/classify/process/review/coordinator/rag - database.py 新增 accumulate_token_daily_stats + list_token_daily_stats 用 SELECT-then-INSERT/UPDATE 模式跨方言兼容 NULL 累加(MySQL/SQLite 中 NULL 在 UNIQUE 索引里被视为 distinct) - TraceManager 新增 accumulate_token_daily_stats:通过 trace_id 反查 ticket_id + user_id,调用方只需传 trace_id + model + call_type + token 用量 - CachedLLMClient._finalize_llm_span 在已有 add_token_usage 调用后追加 accumulate_token_daily_stats;task_type 映射到 call_type 枚举 - 新增 tests/core/test_token_accumulation.py:验证 INSERT/UPDATE 累加、 user_id=None 独立行、6 个 call_type 分行、traces.total_tokens 修复后非 0 (7 个测试) 完成 C2 任务块 3(Token 累加修复)。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
No description provided.