Documentation
¶
Overview ¶
Package grayscale 提供灰度路由:按比例或按用户稳定分流新旧版本处理器。 场景:新接口灰度发版(5% → 20% → 50% → 100%)、A/B 测试。 支持灰度可观测:响应头标记命中版本(X-Gray-Version)与命中统计(Stats)。
Index ¶
Constants ¶
View Source
const DefaultHeaderName = "X-Gray-Version"
默认灰度标记响应头。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stats ¶ added in v1.76.0
type Stats struct {
Total uint64 // 总请求数
NewHits uint64 // 命中新版本数
OldHits uint64 // 命中旧版本数
Ratio float64 // 实际新版本占比(0~1;无请求时为 0)
}
Stats 灰度统计快照。
type Strategy ¶
type Strategy struct {
// Ratio 命中新版本的比例(0~1);1 = 全量新版本,0 = 全量旧版本。
Ratio float64
// UserKey 提取用户标识的函数(nil = 按请求随机分流)。
// 提供后同一用户始终命中同一版本(稳定灰度)。
UserKey func(ctx iris.Context) string
// HeaderName 响应头标记名("" 关闭标记;默认 X-Gray-Version)。
HeaderName string
// contains filtered or unexported fields
}
Strategy 灰度策略。
func (*Strategy) Route ¶
Route 返回分流处理器:命中走 newHandler,否则走 oldHandler。 响应头标记命中版本(X-Gray-Version: new|old,可 WithHeaderName 关闭),并计入统计。 用法:app.Get("/api/order", gray.Route(newOrderHandler, oldOrderHandler))
func (*Strategy) WithHeaderName ¶ added in v1.76.0
WithHeaderName 设置响应头标记名("" 关闭标记)。链式调用。
Click to show internal directories.
Click to hide internal directories.