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
@@ -11,29 +11,29 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
||||
)
|
||||
|
||||
// Default list limits shared by the trace/audit endpoints. Compile-time constants
|
||||
// so no magic number appears in the run path (project rule §10).
|
||||
// trace/audit 端点共享的默认列表上限。编译期常量,
|
||||
// 因此运行路径中不出现魔法数字(项目规范 §10)。
|
||||
const (
|
||||
defaultObsLimit = 50
|
||||
maxObsLimit = 500
|
||||
)
|
||||
|
||||
// observability bundles the gateway's live admin instrumentation: the request
|
||||
// metrics counter, the trace span ring buffer, the audit store and the
|
||||
// process-wide log ring buffer. It is built in New and is safe for concurrent
|
||||
// use.
|
||||
// observability 打包网关的实时管理仪表:请求
|
||||
// 指标计数器、trace span 环形缓冲、审计存储与
|
||||
// 进程级日志环形缓冲。它在 New 中构建,且对并发
|
||||
// 使用安全。
|
||||
type observability struct {
|
||||
metrics *MetricsCollector
|
||||
traceBuf *RingBuffer
|
||||
audit AuditStore
|
||||
// logBuf is the logger's log ring buffer behind the admin log-tail endpoint.
|
||||
// The composition root injects it via SetLogBuffer once the gateway exists;
|
||||
// until then the endpoint answers 501 rather than an empty-but-fake tail.
|
||||
// logBuf 是管理日志尾部端点背后的 logger 日志环形缓冲。
|
||||
// 组合根在网关存在后经 SetLogBuffer 注入它;在那之前
|
||||
// 该端点返回 501,而不是空但虚假的尾部。
|
||||
logBuf atomic.Pointer[logger.RingBuffer]
|
||||
}
|
||||
|
||||
// newObservability builds the instrumentation, falling back to an in-memory audit
|
||||
// store when no store is injected.
|
||||
// newObservability 构建仪表,未注入存储时回退到内存审计
|
||||
// 存储。
|
||||
func newObservability(deps Deps) *observability {
|
||||
obs := &observability{
|
||||
metrics: newMetricsCollector(),
|
||||
@@ -47,10 +47,10 @@ func newObservability(deps Deps) *observability {
|
||||
return obs
|
||||
}
|
||||
|
||||
// ObserveSpan feeds a completed trace span into the gateway's ring buffer and the
|
||||
// LLM/subagent metric counters. It is the gateway's trace injection point: the
|
||||
// composition root wires the loop tracer here (e.g. through TraceSink) so the
|
||||
// admin panel can query spans without the gateway touching wire.go.
|
||||
// ObserveSpan 把一个已完成的 trace span 送入网关的环形缓冲与
|
||||
// LLM/子代理指标计数器。它是网关的 trace 注入点:
|
||||
// 组合根把 loop tracer 接到这里(例如通过 TraceSink),使
|
||||
// 管理面板能查询 span 而网关无需触碰 wire.go。
|
||||
func (s *Server) ObserveSpan(rec trace.SpanRecord) {
|
||||
if s.obs == nil {
|
||||
return
|
||||
@@ -59,10 +59,10 @@ func (s *Server) ObserveSpan(rec trace.SpanRecord) {
|
||||
s.obs.metrics.Observe(rec)
|
||||
}
|
||||
|
||||
// TraceSink returns a trace.Writer that appends completed spans to the gateway's
|
||||
// trace ring buffer. Combine it with the existing JSONRecorder in the composition
|
||||
// root (e.g. trace.New(MultiTraceWriter{...})) so spans both hit stderr and the
|
||||
// admin panel.
|
||||
// TraceSink 返回一个 trace.Writer,把已完成的 span 追加进网关的
|
||||
// trace 环形缓冲。在组合根把它与既有的 JSONRecorder 结合
|
||||
// (例如 trace.New(MultiTraceWriter{...})),使 span 既落 stderr 又进
|
||||
// 管理面板。
|
||||
func (s *Server) TraceSink() trace.Writer {
|
||||
if s.obs == nil {
|
||||
return nil
|
||||
@@ -70,7 +70,7 @@ func (s *Server) TraceSink() trace.Writer {
|
||||
return traceSink{s.obs.traceBuf}
|
||||
}
|
||||
|
||||
// recordMetric counts one request for the observability panel.
|
||||
// recordMetric 为可观测面板计一次请求。
|
||||
func (s *Server) recordMetric(method, path string, status int, durMs int64) {
|
||||
if s.obs == nil {
|
||||
return
|
||||
@@ -78,7 +78,7 @@ func (s *Server) recordMetric(method, path string, status int, durMs int64) {
|
||||
s.obs.metrics.Record(method, path, status, durMs)
|
||||
}
|
||||
|
||||
// adminObservabilityMetrics returns the current gateway metrics (admin read).
|
||||
// adminObservabilityMetrics 返回当前网关指标(管理读)。
|
||||
func (s *Server) adminObservabilityMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
if s.obs == nil {
|
||||
writeJSON(w, http.StatusOK, AdminMetrics{
|
||||
@@ -89,7 +89,7 @@ func (s *Server) adminObservabilityMetrics(w http.ResponseWriter, r *http.Reques
|
||||
writeJSON(w, http.StatusOK, s.obs.metrics.Snapshot(time.Now()))
|
||||
}
|
||||
|
||||
// adminObservabilityTrace returns the most recent traced spans (admin read).
|
||||
// adminObservabilityTrace 返回最近的已追踪 span(管理读)。
|
||||
func (s *Server) adminObservabilityTrace(w http.ResponseWriter, r *http.Request) {
|
||||
if s.obs == nil {
|
||||
writeJSON(w, http.StatusOK, []AdminTraceSpan{})
|
||||
@@ -103,7 +103,7 @@ func (s *Server) adminObservabilityTrace(w http.ResponseWriter, r *http.Request)
|
||||
writeJSON(w, http.StatusOK, out)
|
||||
}
|
||||
|
||||
// adminObservabilityAudit returns the most recent audit entries (admin read).
|
||||
// adminObservabilityAudit 返回最近的审计条目(管理读)。
|
||||
func (s *Server) adminObservabilityAudit(w http.ResponseWriter, r *http.Request) {
|
||||
if s.obs == nil || s.obs.audit == nil {
|
||||
writeJSON(w, http.StatusOK, []AuditRecord{})
|
||||
@@ -118,8 +118,8 @@ func (s *Server) adminObservabilityAudit(w http.ResponseWriter, r *http.Request)
|
||||
writeJSON(w, http.StatusOK, records)
|
||||
}
|
||||
|
||||
// parseLimit parses the ?limit= query param, clamping to [1, maxObsLimit], and
|
||||
// selects defaultObsLimit when absent or invalid.
|
||||
// parseLimit 解析 ?limit= 查询参数,夹取到 [1, maxObsLimit],
|
||||
// 缺失或非法时选用 defaultObsLimit。
|
||||
func parseLimit(r *http.Request) int {
|
||||
n, err := strconv.Atoi(r.URL.Query().Get("limit"))
|
||||
if err != nil || n <= 0 {
|
||||
|
||||
Reference in new issue
Block a user