shedder

package
v0.25.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

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) Clone

func (s *Shedder) Clone() internal.Configurable

Clone 返回配置的副本

func (*Shedder) Disable

func (s *Shedder) Disable() *Shedder

Disable 禁用降载

func (*Shedder) Enable

func (s *Shedder) Enable() *Shedder

Enable 启用降载

func (*Shedder) Get

func (s *Shedder) Get() interface{}

Get 返回配置接口

func (*Shedder) GetLabel

func (s *Shedder) GetLabel() string

GetLabel 获取配置标签

func (*Shedder) Init

func (s *Shedder) Init() error

Init 初始化配置

func (*Shedder) IsEnabled

func (s *Shedder) IsEnabled() bool

IsEnabled 检查是否启用

func (*Shedder) Set

func (s *Shedder) Set(data interface{})

Set 设置配置数据

func (*Shedder) Validate

func (s *Shedder) Validate() error

Validate 验证配置

func (*Shedder) WithCPUThreshold

func (s *Shedder) WithCPUThreshold(threshold int64) *Shedder

WithCPUThreshold 设置 CPU 使用率阈值(千分比 0-1000)

func (*Shedder) WithCooldownMS

func (s *Shedder) WithCooldownMS(cooldownMS int64) *Shedder

WithCooldownMS 设置降载冷却时长(毫秒)

func (*Shedder) WithExcludePaths

func (s *Shedder) WithExcludePaths(paths []string) *Shedder

WithExcludePaths 设置排除的路径(前缀匹配)

func (*Shedder) WithFlyingBeta

func (s *Shedder) WithFlyingBeta(beta float64) *Shedder

WithFlyingBeta 设置飞行请求数 EWMA 平滑系数

func (*Shedder) WithMaxConcurrency

func (s *Shedder) WithMaxConcurrency(maxConcurrency int64) *Shedder

WithMaxConcurrency 设置硬并发上限(0 表示不限)

func (*Shedder) WithMinRTMS

func (s *Shedder) WithMinRTMS(minRTMS int64) *Shedder

WithMinRTMS 设置滑窗无样本时的兜底响应时间(毫秒)

func (*Shedder) WithModuleName

func (s *Shedder) WithModuleName(moduleName string) *Shedder

WithModuleName 设置模块名称

func (*Shedder) WithWindow

func (s *Shedder) WithWindow(windowMS int64, buckets int) *Shedder

WithWindow 设置响应时间滑窗的总长度(毫秒)与桶数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL