sentinel

package
v0.0.0-...-a89d410 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SENTINEL_DATASOURCE_ETCD  = "etcd"
	SENTINEL_DATASOURCE_FILES = "files"
)

Variables

View Source
var (
	WithError        = base.WithError
	WithResourceType = api.WithResourceType
	WithTrafficType  = api.WithTrafficType
)

Functions

func Entry

func Entry(resource string, opts ...EntryOption) (*SentinelEntry, *BlockError)

Entry 执行熔断策略.

func FromContext

func FromContext(ctx context.Context) *base.SentinelEntry

func WithContext

func WithContext(ctx context.Context, val *base.SentinelEntry) context.Context

Types

type BlockError

type BlockError = base.BlockError

type CircuitBreakerRule

type CircuitBreakerRule struct {
	Enable bool `json:"enable"`
	// resource name
	Resource string                  `json:"resource"`
	Strategy circuitbreaker.Strategy `json:"strategy"`
	// RetryTimeoutMs represents recovery timeout (in milliseconds) before the circuit breaker opens.
	// During the open period, no requests are permitted until the timeout has elapsed.
	// After that, the circuit breaker will transform to half-open state for trying a few "trial" requests.
	RetryTimeoutMs uint32 `json:"retryTimeoutMs"`
	// MinRequestAmount represents the minimum number of requests (in an active statistic time span)
	// that can trigger circuit breaking.
	MinRequestAmount uint64 `json:"minRequestAmount"`
	// StatIntervalMs represents statistic time interval of the internal circuit breaker (in ms).
	// Currently the statistic interval is collected by sliding window.
	StatIntervalMs uint32 `json:"statIntervalMs"`
	// StatSlidingWindowBucketCount represents the bucket count of statistic sliding window.
	// The statistic will be more precise as the bucket count increases, but the memory cost increases too.
	// The following must be true — “StatIntervalMs % StatSlidingWindowBucketCount == 0”,
	// otherwise StatSlidingWindowBucketCount will be replaced by 1.
	// If it is not set, default value 1 will be used.
	StatSlidingWindowBucketCount uint32 `json:"statSlidingWindowBucketCount"`
	// MaxAllowedRtMs indicates that any invocation whose response time exceeds this value (in ms)
	// will be recorded as a slow request.
	// MaxAllowedRtMs only takes effect for SlowRequestRatio strategy
	MaxAllowedRtMs uint64 `json:"maxAllowedRtMs"`
	// Threshold represents the threshold of circuit breaker.
	// for SlowRequestRatio, it represents the max slow request ratio
	// for ErrorRatio, it represents the max error request ratio
	// for ErrorCount, it represents the max error request count
	Threshold float64 `json:"threshold"`
}

type Config

type Config struct {
	Enable     bool   `toml:"enable"`
	Datasource string `toml:"datasource"`
	EtcdRawKey string `toml:"etcdRawKey"`
	// 熔断降级
	CbKey   string                `toml:"cbKey"`
	CbRules []*CircuitBreakerRule `toml:"cbRules"`
	// 流量控制
	FlowKey   string       `toml:"flowKey"`
	FlowRules []*flow.Rule `toml:"flowRules"`
	// 系统保护
	SystemKey   string         `toml:"systemKey"`
	SystemRules []*system.Rule `toml:"systemRules"`
}

func DefaultConfig

func DefaultConfig() Config

func RawConfig

func RawConfig(key string) Config

func StdConfig

func StdConfig() Config

func (Config) Build

func (c Config) Build() error

func (Config) Entry

func (c Config) Entry(resource string, opts ...EntryOption) (*SentinelEntry, *BlockError)

type EntryContext

type EntryContext = base.EntryContext

type EntryOption

type EntryOption = sentinel.EntryOption

type SentinelEntry

type SentinelEntry = base.SentinelEntry

Jump to

Keyboard shortcuts

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