window

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

抄的kratos , 在滑块中添加缓存, 并修复了kratosapply的一个小BUG, 见 https://github.com/go-kratos/aegis/issues/17

kratos: https://github.com/go-kratos/kratos/blob/main/middleware/circuitbreaker/circuitbreaker.go sre: https://github.com/go-kratos/aegis/tree/main/circuitbreaker/sre window: https://github.com/go-kratos/aegis/tree/main/pkg/window

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWindow

func NewWindow(size int) *window

Types

type Breaker

type Breaker interface {
	Allow() (bool, error)
}

type Bucket

type Bucket struct {
	Sum   uint64 // 这里可以是请求耗时, 也可以是请求成功次数
	Count uint64 // 请求总数
}

func (*Bucket) Add

func (b *Bucket) Add(val uint64)

Add Count是总数,这个是必须加1的

func (*Bucket) Reset

func (b *Bucket) Reset()

Reset 重置桶

type Option

type Option func(*options)

func WithBucket

func WithBucket(bucketSize int) Option

func WithBucketDuration

func WithBucketDuration(bucketDuration time.Duration) Option

type Rolling

type Rolling interface {
	Add(val uint64)

	Reduce(func(*Bucket))
	Summary() (accept uint64, count uint64)
	// contains filtered or unexported methods
}

type RollingPolicy

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

RollingPolicy 滑块

func NewRollingPolicy

func NewRollingPolicy(opts ...Option) *RollingPolicy

func (*RollingPolicy) Add

func (r *RollingPolicy) Add(val uint64)

Add 桶数据增 这里会触发滑动

func (*RollingPolicy) Reduce

func (r *RollingPolicy) Reduce(fn func(*Bucket))

Reduce 统计所有的采集完整的桶, 当前这个桶和跳过的桶不计算

func (*RollingPolicy) Summary

func (r *RollingPolicy) Summary() (uint64, uint64)

Summary 返回有效bucket数量之和

type Window

type Window interface {
	Add(offset int, val uint64)
	ResetBuckets(offset int, count int)
	Reduce(start int, end int, fn func(*Bucket))
}

Jump to

Keyboard shortcuts

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