Fix monitor averages and retry failure accounting#188
Merged
Conversation
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.
Motivation
429/503错误时才将一次重试计为失败尝试,从而使监控统计中的失败次数更准确。Description
src/utils/usageStats.js中为每日统计桶添加firstSeen和lastSeen字段并在record中维护它们,汇总时只统计有请求的 "活跃" 天/分钟作为平均值分母,并通过averageBasis返回activeDays和activeMinutes。activeMinutes/activeDays计算:tpm/rpm基于活跃分钟,rdp基于活跃天数。public/js/monitor.js中新增展示逻辑以显示平均值的统计基准(例如按多少分钟/小时/天或按多少个有请求日期统计),并改进 Tokens 数字格式化显示。src/server/handlers/common/retry.js中调整onAttemptFailure的调用位置,使其仅在捕获到可重试的429/503错误后计入失败尝试。src/server/index.js中的监控中间件)将req.apiUsageMetrics.failedAttempts汇总为failedCount并与successCount一起传入usageStats.record,以便统计重试失败次数。Testing
usageStats.getSummary的断言测试验证汇总/平均值计算(node --input-type=module),测试通过。with429Retry的行为测试(模拟连续503重试并断言onAttemptFailure次数),测试通过。node --check src/utils/usageStats.js && node --check src/server/handlers/common/retry.js && node --check public/js/monitor.js均通过。npm run build:linux时pkg在拉取/构建 Node 二进制阶段因外部资源返回403 Forbidden导致构建失败(环境/网络问题,与代码变更无关)。Codex Task