Merge branch 'feat/m24-flowgate-move-review-off-admission-p' into dev
This commit is contained in:
commit
7ea2850f18
9 files changed
+1129
-150
No files matched your search
+63
-2
@@ -90,11 +90,62 @@ func buildPlatformAdapters(platform string, accts []config.ChannelAccount, log *
|
||||
log.Warn("channel account build skipped", "platform", platform, "account", acct.ID, "error", berr)
|
||||
continue
|
||||
}
|
||||
logFlowControl(log, built)
|
||||
out = append(out, built)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// logFlowControl 逐账号打一条启动日志,如实报出这个账号此刻被限成什么样(M24 裁决 A):
|
||||
// 闸是否开、每群几条/分、待处理上限、审查触发水位(reviewAt)。
|
||||
//
|
||||
// 为什么需要它:namedAdapter 的 Config() 无条件暴露四个流控键(含零值),桥的 cfgInt
|
||||
// 因此永远认为「键存在」,flowOrDefault 再把 0 映射成保护性默认 —— 于是「一个流控键都
|
||||
// 没写的账号,闸门仍然是开着的」。这条事实必须一眼可见,否则「群里为什么有消息被丢」
|
||||
// 只能靠读代码解释。判据:只看这一行日志就能说出这个群的限流/审查额度。
|
||||
//
|
||||
// 判定依据是**构建出来的那个适配器本身**,不是重新读一遍配置:非 namedAdapter 的实例
|
||||
// 不暴露流控键,桥按 flowgate.go「键缺失 ⇒ 该限制关闭」处理;这时必须如实报 off,
|
||||
// 不能拿保护性默认值假装成「开着」。
|
||||
func logFlowControl(log *slog.Logger, built adapter.PlatformAdapter) {
|
||||
if log == nil {
|
||||
log = slog.Default()
|
||||
}
|
||||
log = logger.WithSource(log, "cmd/cyrene/channels")
|
||||
n, ok := built.(*namedAdapter)
|
||||
if !ok {
|
||||
log.Info("channel account ingress flow control",
|
||||
"account", built.Name(), "gate", "off",
|
||||
"why", "adapter exposes no flow keys, every limit stays disabled")
|
||||
return
|
||||
}
|
||||
group := flowLimitOrDefault(n.groupMsgPerMin, adapter.FlowLimitDefault)
|
||||
direct := flowLimitOrDefault(n.directMsgPerMin, adapter.FlowDirectDefault)
|
||||
pending := flowLimitOrDefault(n.maxMessages, adapter.FlowCapDefault)
|
||||
log.Info("channel account ingress flow control",
|
||||
"account", n.Name(), "gate", "on",
|
||||
"group_msg_per_min", group, "group_msg_per_min_raw", n.groupMsgPerMin,
|
||||
"direct_msg_per_min", direct, "direct_msg_per_min_raw", n.directMsgPerMin,
|
||||
"msg_per_min", max(n.msgPerMin, 0),
|
||||
"max_messages", pending, "max_messages_raw", n.maxMessages,
|
||||
"review_at", adapter.ReviewAtFor(pending),
|
||||
"note", "raw 0 (or absent in channels.json) takes the protective default; negative disables")
|
||||
}
|
||||
|
||||
// flowLimitOrDefault 把账号原始值映射为实际生效值:负值关闭该限制、零值取保护性默认、
|
||||
// 正值固定。它与 internal/services/channelbridge/flowgate.go 的 flowOrDefault 逐字同
|
||||
// 口径,这里只用于上面那条启动日志 —— 日志必须报生效值,不能报原始值。
|
||||
func flowLimitOrDefault(v, def int) int {
|
||||
switch {
|
||||
case v < 0:
|
||||
return 0
|
||||
case v == 0:
|
||||
return def
|
||||
default:
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
// channelAccountsFromEnv 合成 env 兜底:单账号 CHANNEL_<NAME>_* 适配器,加上
|
||||
// CHANNELS_JSON 里的多账号条目。它是 channels.json 缺失或非法时传给
|
||||
// runtimeconfig.LoadChannels 的 .env 兜底。.env 只承载必要的连接兜底
|
||||
@@ -174,8 +225,18 @@ type namedAdapter struct {
|
||||
denyGroups []string
|
||||
allowUsers []string
|
||||
denyUsers []string
|
||||
// 流控限制(design/12 §6 策略三/四)。它们始终经 Config() 暴露,使桥能构建按账号
|
||||
// 的入口闸门;桥把零值默认映射为保护性取值,把负值映射为「关闭」。
|
||||
// 流控限制(design/12 §6 策略三/四)。**四个键始终经 Config() 暴露,包括零值**:
|
||||
// 桥的 cfgInt 因此永远认为「键存在」,flowOrDefault 于是把 0 映射成保护性默认
|
||||
// (每群 6 条/分、待处理上限 50、reviewAt = 40)—— 一个在 channels.json 里一个
|
||||
// 流控键都没写的账号,闸门**仍然是开着的**(M24 只读勘测实测:现存 qq 账号就是
|
||||
// 这种状态)。负值经桥映射为「关闭」。
|
||||
//
|
||||
// 边界的准确说法(M24):flowgate.go 那句「键缺失 ⇒ 该限制关闭」的向后兼容分支,
|
||||
// 对 CHANNELS_JSON 账号**不可达** —— config.ChannelAccount 用的是普通 int
|
||||
// (omitempty),「未配置」与「显式配 0」解出来都是 0,这里无从区分。要区分就得
|
||||
// 改 config 的类型(*int / 存在性表)或在本题二次解析原始 JSON;而那样做会改掉
|
||||
// 「闸门默认开还是关」这个产品口径(群聊限流/审查默认从开变关),属主人裁决,
|
||||
// 不在本处自行翻转。见 M24 回报里的选项 A/B/C。
|
||||
groupMsgPerMin int
|
||||
directMsgPerMin int
|
||||
msgPerMin int
|
||||
|
||||
Reference in new issue
Block a user