Documentation ¶
Index ¶
- Variables
- type CircuitBreaker
- func (circuit *CircuitBreaker) AllowRequest() bool
- func (circuit *CircuitBreaker) GetCircuitStatus() (isOpen bool, canRequest bool)
- func (circuit *CircuitBreaker) IsHealthy(t time.Time) bool
- func (circuit *CircuitBreaker) IsOpen() bool
- func (circuit *CircuitBreaker) ReportEvent(event string, i uint64) int64
- func (circuit *CircuitBreaker) ToggleForceOpen(toggle bool)
- type NamedCircuitBreakers
- type Option
- type SecondBucket
- type StandardMetricCollector
- func (d *StandardMetricCollector) Failure(i uint64) (t int64)
- func (m *StandardMetricCollector) FailurePercent(now time.Time) int
- func (d *StandardMetricCollector) Failures() *SecondBucket
- func (d *StandardMetricCollector) FallbackFailure(i uint64) int64
- func (d *StandardMetricCollector) FallbackFailures() *SecondBucket
- func (d *StandardMetricCollector) FallbackSuccess(i uint64) int64
- func (d *StandardMetricCollector) FallbackSuccesses() *SecondBucket
- func (d *StandardMetricCollector) NumRequests() *SecondBucket
- func (d *StandardMetricCollector) Reject(i uint64) (t int64)
- func (m *StandardMetricCollector) RejectPercent(now time.Time) int
- func (d *StandardMetricCollector) Rejects() *SecondBucket
- func (d *StandardMetricCollector) Reset()
- func (d *StandardMetricCollector) ShortCircuit(i uint64) int64
- func (d *StandardMetricCollector) ShortCircuits() *SecondBucket
- func (d *StandardMetricCollector) Success(i uint64) (t int64)
- func (d *StandardMetricCollector) Successes() *SecondBucket
- func (d *StandardMetricCollector) Timeout(i uint64) (t int64)
- func (d *StandardMetricCollector) Timeouts() *SecondBucket
Constants ¶
This section is empty.
Variables ¶
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) GetBreaker ¶
func (c *NamedCircuitBreakers) GetBreaker(url string) *CircuitBreaker
GetBreaker 获取当前URL的熔断信息
type SecondBucket ¶
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