fix(billing-probe): govern the automatic account rate write-back

- 自动写回值域治理与留痕:上游声明值必须 > 0 且 <= 100 才写回。0 会让
  accountCost 恒为 0(账号总额/日/周配额与成本告警全部静默失效),极大值可
  一次打爆配额并污染成本报表;越界时保持原倍率、记 WARN,探测快照照常记 ok。
  写回成功时记结构化 slog(account_id / 旧值 / 新值 / source),并在快照中
  新增 synced_rate_multiplier 记录本次写回值——后台任务裸 SQL 不产生
  audit_logs,这两处是唯一可追溯来源。管理员手工设 0 不受影响。
- 写回改用 resolved_rate_multiplier(不含高峰的基准倍率):effective 含探测
  那一刻的高峰系数,写回会把一个探测周期的峰值/谷值冻结进静态列,而展示与
  调度用 upstreamBillingRateAt 按当前时间重算高峰,两者会持续不一致。
- 倍率解析失败不再污染公共探测路径:账号级值域/精度只在该账号已开启同步、
  真要写回时才有影响;未开同步的账号照常记 ok 快照,不累计 failure_count、
  不进入指数退避。
- 单账号编辑补 service 层守卫:同步开启时拒绝手工倍率(新增
  UPSTREAM_BILLING_RATE_SYNC_CONFLICT,与批量路径同族),此前只有前端
  disabled 挡人,直接 PUT /admin/accounts/{id} 可写入并活到下次成功探测。
  判断的是本次请求生效后的状态,"关同步 + 改倍率"同请求仍然放行。
- 修正开关反推方向:不再由 rate_sync=true 推出 probe=true,否则一条"同步开、
  探测键缺失"的僵尸记录会在任意一次无关编辑时静默打开周期性外呼;改为探测
  关闭/缺失一律把同步归零。
- 删除死代码 UpdateWithUpstreamBillingProbeEnabled(PR 删接口后生产已无调用
  方),其回滚测试改为直接覆盖生产路径 UpdateWithAccountBillingSettings。
  upstreamBillingRateSyncEnabled 不再是只服务测试的假门控,现为写回前置过滤,
  SQL CAS 仍是权威门控,两侧均加注释说明分工。
- en/zh 文案补充:同步的是不含高峰的基准倍率;开启同步会连带打开自动探测。
This commit is contained in:
shaw
2026-08-01 22:11:10 +08:00
parent b0f5007f04
commit 0b6b4ea956
9 changed files with 421 additions and 45 deletions
@@ -227,9 +227,9 @@ export default {
autoProbe: 'Automatically probe upstream declared rate',
autoProbeHint: 'Refresh the upstream declared rate on the global interval. This switch alone does not change the account rate.',
syncRate: 'Sync upstream declared rate',
syncRateHint: 'Update the account rate after each successful probe. Failed or invalid declarations leave it unchanged.',
syncRateManagedHint: 'The current rate is maintained automatically from the upstream declared rate.',
syncedRateTooltip: 'This account rate is synchronized from the upstream declared rate',
syncRateHint: 'Update the account rate after each successful probe, using the base rate excluding peak hours. Failed probes or declarations outside the allowed range leave it unchanged. Enabling this also turns on "Automatically probe upstream declared rate".',
syncRateManagedHint: 'The current rate is maintained automatically from the upstream declared base rate (excluding peak hours).',
syncedRateTooltip: 'This account rate is synchronized from the upstream declared base rate (excluding peak hours)',
manualProbe: 'Probe upstream rate now',
stale: 'Stale',
unsupported: 'Unsupported',
@@ -180,9 +180,9 @@ export default {
autoProbe: '自动探测上游声明倍率',
autoProbeHint: '启用后按全局周期刷新上游声明倍率;此开关本身不会修改账号倍率。',
syncRate: '同步上游声明倍率',
syncRateHint: '成功探测后自动更新账号倍率;探测失败或声明无效时保持不变。',
syncRateManagedHint: '当前倍率由上游声明倍率自动维护。',
syncedRateTooltip: '该账号倍率由上游声明倍率自动同步',
syncRateHint: '成功探测后自动更新账号倍率,同步的是不含高峰的基准倍率;探测失败或声明超出允许范围时保持不变。开启本项会同时打开“自动探测上游声明倍率”。',
syncRateManagedHint: '当前倍率由上游声明的基准倍率(不含高峰)自动维护。',
syncedRateTooltip: '该账号倍率由上游声明的基准倍率(不含高峰)自动同步',
manualProbe: '立即探测上游倍率',
stale: '已过期',
unsupported: '不支持',
+3
View File
@@ -970,6 +970,9 @@ export interface UpstreamBillingProbeSnapshot {
failure_count?: number
http_status?: number
last_error?: string
// Value this probe wrote into the account rate multiplier; absent when the
// probe did not sync a rate.
synced_rate_multiplier?: number
}
export interface UpstreamBillingProbeSettings {