Documentation
¶
Index ¶
- type Shedder
- func (s *Shedder) Clone() internal.Configurable
- func (s *Shedder) Disable() *Shedder
- func (s *Shedder) Enable() *Shedder
- func (s *Shedder) Get() interface{}
- func (s *Shedder) GetLabel() string
- func (s *Shedder) Init() error
- func (s *Shedder) IsEnabled() bool
- func (s *Shedder) Set(data interface{})
- func (s *Shedder) Validate() error
- func (s *Shedder) WithCPUThreshold(threshold int64) *Shedder
- func (s *Shedder) WithCooldownMS(cooldownMS int64) *Shedder
- func (s *Shedder) WithExcludePaths(paths []string) *Shedder
- func (s *Shedder) WithFlyingBeta(beta float64) *Shedder
- func (s *Shedder) WithMaxConcurrency(maxConcurrency int64) *Shedder
- func (s *Shedder) WithMinRTMS(minRTMS int64) *Shedder
- func (s *Shedder) WithModuleName(moduleName string) *Shedder
- func (s *Shedder) WithWindow(windowMS int64, buckets int) *Shedder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Shedder ¶
type Shedder struct {
ModuleName string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名称
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"` // 是否启用降载
CPUThreshold int64 `mapstructure:"cpu-threshold" yaml:"cpu-threshold" json:"cpuThreshold"` // CPU 使用率阈值,千分比 0-1000
MaxConcurrency int64 `mapstructure:"max-concurrency" yaml:"max-concurrency" json:"maxConcurrency"` // 硬并发上限,0 表示不限
WindowMS int64 `mapstructure:"window-ms" yaml:"window-ms" json:"windowMs"` // 响应时间滑窗总长度,毫秒
WindowBuckets int `mapstructure:"window-buckets" yaml:"window-buckets" json:"windowBuckets"` // 滑窗桶数
CooldownMS int64 `mapstructure:"cooldown-ms" yaml:"cooldown-ms" json:"cooldownMs"` // 降载冷却时长,毫秒
MinRTMS int64 `mapstructure:"min-rt-ms" yaml:"min-rt-ms" json:"minRtMs"` // 滑窗无样本时的兜底响应时间,毫秒
FlyingBeta float64 `mapstructure:"flying-beta" yaml:"flying-beta" json:"flyingBeta"` // 飞行请求数 EWMA 平滑系数,取值 (0,1)
ExcludePaths []string `mapstructure:"exclude-paths" yaml:"exclude-paths" json:"excludePaths"` // 排除的路径(前缀匹配)
}
Shedder 自适应降载配置
时间字段统一带 -ms 后缀并以毫秒为单位,不沿用 breaker.CircuitBreaker.Timeout 的 「int64 纳秒」写法:纳秒值写进 YAML 只能是 5000000000 这种数字,既不可读也容易误配成秒
[EN] Adaptive load-shedding configuration. Duration fields carry an explicit -ms suffix and are milliseconds rather than following breaker.CircuitBreaker.Timeout's int64-nanoseconds convention, because a nanosecond count is unreadable in YAML and easy to mistake for seconds
func Default ¶
func Default() *Shedder
Default 创建默认降载配置
Enabled 默认 false,与 breaker.Default() 默认 true 不同: 降载会在服务还能响应的时候主动丢请求,阈值要结合容量压测结果调,默认开启等于 替使用方做了一个会丢流量的决定;熔断只在下游已经坏掉时才动手,默认开启是安全的
ExcludePaths 默认排除健康检查与指标端点:前者被降载会让编排系统在服务过载时 直接重启或摘流,把一次本可自愈的过载变成重启风暴;后者被降载会让过载期间拿不到指标
[EN] Returns the default configuration. Enabled is false, unlike breaker.Default(): shedding actively drops requests while the service is still answering and its thresholds need capacity testing, so enabling it is a decision the operator must make, whereas a breaker only acts once the dependency is already broken. Health and metrics endpoints are excluded by default, since shedding health checks makes the orchestrator restart or evict the pod exactly when it is overloaded, and shedding metrics blinds the operator
func (*Shedder) WithCPUThreshold ¶
WithCPUThreshold 设置 CPU 使用率阈值(千分比 0-1000)
func (*Shedder) WithCooldownMS ¶
WithCooldownMS 设置降载冷却时长(毫秒)
func (*Shedder) WithExcludePaths ¶
WithExcludePaths 设置排除的路径(前缀匹配)
func (*Shedder) WithFlyingBeta ¶
WithFlyingBeta 设置飞行请求数 EWMA 平滑系数
func (*Shedder) WithMaxConcurrency ¶
WithMaxConcurrency 设置硬并发上限(0 表示不限)
func (*Shedder) WithMinRTMS ¶
WithMinRTMS 设置滑窗无样本时的兜底响应时间(毫秒)
func (*Shedder) WithModuleName ¶
WithModuleName 设置模块名称