circuit

package
v0.13.6-0...-d3ad96a Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EventSuccess      = "SUCCESS"
	EventFailure      = "FAILURE"
	EventReject       = "REJECT"
	EventTimeout      = "TIMEOUT"
	EventShortCircuit = "SHORT_CIRCUIT"

	EventFallbackSuccess = "FALLBACK_SUCCESS"
	EventFallbackFailure = "FALLBACK_FAILURE"
)

Functions

This section is empty.

Types

type CircuitBreaker

type CircuitBreaker struct {
	Name string
	// contains filtered or unexported fields
}

CircuitBreaker 熔断管理

func NewCircuitBreaker

func NewCircuitBreaker(opts ...Option) *CircuitBreaker

NewCircuitBreaker creates a CircuitBreaker with associated Health

func (*CircuitBreaker) AllowRequest

func (circuit *CircuitBreaker) AllowRequest() bool

AllowRequest is checked before a command executes, ensuring that circuit state and metric health allow it. When the circuit is open, this call will occasionally return true to measure whether the external service has recovered.

func (*CircuitBreaker) GetCircuitStatus

func (circuit *CircuitBreaker) GetCircuitStatus() (isOpen bool, canRequest bool)

GetCircuitStatus 获取熔断状态

func (*CircuitBreaker) IsHealthy

func (circuit *CircuitBreaker) IsHealthy(t time.Time) bool

IsHealthy 当前服务器健康状况

func (*CircuitBreaker) IsOpen

func (circuit *CircuitBreaker) IsOpen() bool

IsOpen is called before any Command execution to check whether or not it should be attempted. An "open" circuit means it is disabled.

func (*CircuitBreaker) ReportEvent

func (circuit *CircuitBreaker) ReportEvent(event string, i uint64) int64

ReportEvent records command metrics for tracking recent error rates and exposing data to the dashboard.

func (*CircuitBreaker) ToggleForceOpen

func (circuit *CircuitBreaker) ToggleForceOpen(toggle bool)

ToggleForceOpen allows manually causing the fallback logic for all instances of a given command.

type NamedCircuitBreakers

type NamedCircuitBreakers struct {
	// contains filtered or unexported fields
}

func NewNamedCircuitBreakers

func NewNamedCircuitBreakers(conf *conf.CircuitBreaker) *NamedCircuitBreakers

func (*NamedCircuitBreakers) Close

func (c *NamedCircuitBreakers) Close()

Close 关闭熔断配置

func (*NamedCircuitBreakers) GetBreaker

func (c *NamedCircuitBreakers) GetBreaker(url string) *CircuitBreaker

GetBreaker 获取当前URL的熔断信息

type Option

type Option func(*option)

Option 配置选项

func WithFPPS

func WithFPPS(i int) Option

WithEPPS 每秒失败比例

func WithRPS

func WithRPS(i int) Option

WithRPS 每秒请求数

func WithReject

func WithReject(i int) Option

WithReject 每秒拒绝访问数

func WithSleepWindow

func WithSleepWindow(i int64) Option

WithSleepWindow 每秒失败数

func WithTimeout

func WithTimeout(i int) Option

WithTimeout 每秒超时请求数

type SecondBucket

type SecondBucket struct {
	Buckets sync.Map
	// contains filtered or unexported fields
}

SecondBucket tracks a numberBucket over a bounded number of time buckets. Currently the buckets are one second long and only the last 10 seconds are kept.

func NewSecondBucket

func NewSecondBucket(seconds int64) *SecondBucket

NewSecondBucket initializes a RollingNumber struct.

func (*SecondBucket) Average

func (r *SecondBucket) Average(now time.Time) float64

Average 指定一段时间内的平均值

func (*SecondBucket) Increment

func (r *SecondBucket) Increment(i uint64) (t int64)

Increment increments the number in current SecondBucket.

func (*SecondBucket) Max

func (r *SecondBucket) Max(now time.Time) uint64

Max returns the maximum value seen in the last 10 seconds.

func (*SecondBucket) Sum

func (r *SecondBucket) Sum(now time.Time) uint64

Sum sums the values over the buckets in the last 10 seconds.

func (*SecondBucket) UpdateMax

func (r *SecondBucket) UpdateMax(n uint64) (t int64)

UpdateMax updates the maximum value in the current bucket.

type StandardMetricCollector

type StandardMetricCollector struct {
	// contains filtered or unexported fields
}

func NewStandardMetricCollector

func NewStandardMetricCollector(timeRange int64) *StandardMetricCollector

func (*StandardMetricCollector) Failure

func (d *StandardMetricCollector) Failure(i uint64) (t int64)

Failure 失败记数

func (*StandardMetricCollector) FailurePercent

func (m *StandardMetricCollector) FailurePercent(now time.Time) int

func (*StandardMetricCollector) Failures

func (d *StandardMetricCollector) Failures() *SecondBucket

Failures returns the rolling number of failures

func (*StandardMetricCollector) FallbackFailure

func (d *StandardMetricCollector) FallbackFailure(i uint64) int64

FallbackFailure 熔断执行失败记数

func (*StandardMetricCollector) FallbackFailures

func (d *StandardMetricCollector) FallbackFailures() *SecondBucket

FallbackFailures returns the rolling number of fallback failures

func (*StandardMetricCollector) FallbackSuccess

func (d *StandardMetricCollector) FallbackSuccess(i uint64) int64

FallbackSuccess 熔断执行成功记数

func (*StandardMetricCollector) FallbackSuccesses

func (d *StandardMetricCollector) FallbackSuccesses() *SecondBucket

FallbackSuccesses returns the rolling number of fallback successes

func (*StandardMetricCollector) NumRequests

func (d *StandardMetricCollector) NumRequests() *SecondBucket

func (*StandardMetricCollector) Reject

func (d *StandardMetricCollector) Reject(i uint64) (t int64)

Reject 拒绝访问

func (*StandardMetricCollector) RejectPercent

func (m *StandardMetricCollector) RejectPercent(now time.Time) int

func (*StandardMetricCollector) Rejects

func (d *StandardMetricCollector) Rejects() *SecondBucket

Rejects returns the rolling number of rejects

func (*StandardMetricCollector) Reset

func (d *StandardMetricCollector) Reset()

Reset resets all metrics in this collector to 0.

func (*StandardMetricCollector) ShortCircuit

func (d *StandardMetricCollector) ShortCircuit(i uint64) int64

ShortCircuit 熔断记数

func (*StandardMetricCollector) ShortCircuits

func (d *StandardMetricCollector) ShortCircuits() *SecondBucket

ShortCircuits returns the rolling number of short circuits

func (*StandardMetricCollector) Success

func (d *StandardMetricCollector) Success(i uint64) (t int64)

Success 成功记数

func (*StandardMetricCollector) Successes

func (d *StandardMetricCollector) Successes() *SecondBucket

Successes returns the rolling number of successes

func (*StandardMetricCollector) Timeout

func (d *StandardMetricCollector) Timeout(i uint64) (t int64)

Timeout 超时请求

func (*StandardMetricCollector) Timeouts

func (d *StandardMetricCollector) Timeouts() *SecondBucket

Timeouts returns the rolling number of rejects

Jump to

Keyboard shortcuts

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