docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批: 已推库 16 个文件 + 本批剩余文件)。 校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0); 全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
1 parent
91e8d7a029
commit
074ffc4ebf
73 files changed
+2529
-2529
No files matched your search
@@ -8,17 +8,17 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
||||
)
|
||||
|
||||
// Metrics collector tuning. Compile-time constants.
|
||||
// 指标收集器调参。编译期常量。
|
||||
const (
|
||||
// metricsWindow bounds how long request timestamps are retained for QPS.
|
||||
// metricsWindow 限定请求时间戳为 QPS 保留多久。
|
||||
metricsWindow = 2 * time.Second
|
||||
// metricsQPSSpan is the sliding window over which QPS is measured.
|
||||
// metricsQPSSpan 是测量 QPS 的滑动窗口。
|
||||
metricsQPSSpan = time.Second
|
||||
)
|
||||
|
||||
// AdminMetrics is the wire shape of GET /api/v1/admin/observability/metrics.
|
||||
// LLM/Token cost is deliberately absent: the gateway does not track token usage or
|
||||
// spend, and a fabricated number would violate the "不伪造指标" red line.
|
||||
// AdminMetrics 是 GET /api/v1/admin/observability/metrics 的线上结构。
|
||||
// LLM/Token 成本刻意缺位:网关不跟踪 token 用量或
|
||||
// 花费,编造一个数字会违反「不伪造指标」红线。
|
||||
type AdminMetrics struct {
|
||||
TotalRequests int64 `json:"totalRequests"`
|
||||
QPS float64 `json:"qps"`
|
||||
@@ -31,8 +31,8 @@ type AdminMetrics struct {
|
||||
SubagentEvents int64 `json:"subagentEvents"`
|
||||
}
|
||||
|
||||
// MetricsCollector accumulates request metrics and derived counters for the admin
|
||||
// observability panel. It is concurrency-safe.
|
||||
// MetricsCollector 为管理可观测面板累积请求指标与派生
|
||||
// 计数器。它对并发安全。
|
||||
type MetricsCollector struct {
|
||||
mu sync.Mutex
|
||||
total int64
|
||||
@@ -46,7 +46,7 @@ type MetricsCollector struct {
|
||||
subagent int64
|
||||
}
|
||||
|
||||
// newMetricsCollector builds an empty metrics collector.
|
||||
// newMetricsCollector 构建一个空指标收集器。
|
||||
func newMetricsCollector() *MetricsCollector {
|
||||
return &MetricsCollector{
|
||||
perMethod: make(map[string]int64),
|
||||
@@ -55,7 +55,7 @@ func newMetricsCollector() *MetricsCollector {
|
||||
}
|
||||
}
|
||||
|
||||
// Record counts one request with the given method, path, status and duration.
|
||||
// Record 用给定的 method、path、status 与 duration 计一次请求。
|
||||
func (m *MetricsCollector) Record(method, path string, status int, durMs int64) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -72,8 +72,8 @@ func (m *MetricsCollector) Record(method, path string, status int, durMs int64)
|
||||
m.prune(now)
|
||||
}
|
||||
|
||||
// Observe increments the LLM/subagent counters when a span of that kind is
|
||||
// recorded. It is called by ObserveSpan so the counters reflect real work.
|
||||
// Observe 在记录到该类 span 时递增 LLM/子代理计数器。
|
||||
// 它由 ObserveSpan 调用,使计数器反映真实工作。
|
||||
func (m *MetricsCollector) Observe(rec trace.SpanRecord) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -85,8 +85,8 @@ func (m *MetricsCollector) Observe(rec trace.SpanRecord) {
|
||||
}
|
||||
}
|
||||
|
||||
// prune drops request times older than metricsWindow so recent stays small. The
|
||||
// caller must hold m.mu.
|
||||
// prune 丢弃早于 metricsWindow 的请求时间,使 recent 保持小。
|
||||
// 调用方必须持有 m.mu。
|
||||
func (m *MetricsCollector) prune(now time.Time) {
|
||||
min := now.Add(-metricsWindow)
|
||||
i := 0
|
||||
@@ -98,15 +98,15 @@ func (m *MetricsCollector) prune(now time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
// Snapshot returns a point-in-time copy of the metrics. qps counts the requests
|
||||
// started within metricsQPSSpan of now.
|
||||
// Snapshot 返回指标的时间点副本。qps 统计在 now 的
|
||||
// metricsQPSSpan 之内开始的请求。
|
||||
//
|
||||
// Every map in the result is a fresh copy, never the collector's own: the caller
|
||||
// serializes the value AFTER this lock is released (the admin handler JSON-encodes
|
||||
// it), so returning the live maps would let a concurrent Record mutate a map while
|
||||
// the encoder iterates it — the Go runtime answers that with an unrecoverable
|
||||
// fatal "concurrent map iteration and map write" that takes the whole process
|
||||
// down (the 2026-10-03 21:00:28 crash on GET /api/v1/admin/observability/metrics).
|
||||
// 结果中的每个 map 都是全新副本,绝不是收集器自己的:调用方
|
||||
// 在本锁释放之后才序列化该值(管理 handler 对它做 JSON
|
||||
// 编码),因此返回活 map 会让并发的 Record 在编码器
|
||||
// 遍历它时改动该 map —— Go 运行时对此的回答是不可恢复的
|
||||
// 致命错误 "concurrent map iteration and map write",它会让整个进程
|
||||
// 倒下(2026-10-03 21:00:28 在 GET /api/v1/admin/observability/metrics 上的崩溃)。
|
||||
func (m *MetricsCollector) Snapshot(now time.Time) AdminMetrics {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
@@ -133,9 +133,9 @@ func (m *MetricsCollector) Snapshot(now time.Time) AdminMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
// copyCounts returns a detached copy of a string-keyed counter map, so the
|
||||
// snapshot can be encoded after the collector's lock is released. The caller must
|
||||
// hold m.mu while copying (the copy iterates the live map).
|
||||
// copyCounts 返回字符串键计数器 map 的脱离副本,使
|
||||
// 快照能在收集器锁释放后编码。调用方在复制时
|
||||
// 必须持有 m.mu(复制会遍历活 map)。
|
||||
func copyCounts(src map[string]int64) map[string]int64 {
|
||||
out := make(map[string]int64, len(src))
|
||||
for k, v := range src {
|
||||
@@ -144,8 +144,8 @@ func copyCounts(src map[string]int64) map[string]int64 {
|
||||
return out
|
||||
}
|
||||
|
||||
// copyStatusCounts renders the int-keyed status counter as the string-keyed wire
|
||||
// map the AdminMetrics JSON shape declares. The caller must hold m.mu while copying.
|
||||
// copyStatusCounts 把 int 键的状态计数器渲染为 AdminMetrics JSON
|
||||
// 形状所声明的字符串键线上 map。调用方在复制时必须持有 m.mu。
|
||||
func copyStatusCounts(src map[int]int64) map[string]int64 {
|
||||
out := make(map[string]int64, len(src))
|
||||
for k, v := range src {
|
||||
|
||||
Reference in new issue
Block a user