reject

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketShareInfo

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

BucketShareInfo 通用信息

type QuotaBucketReject

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

func (*QuotaBucketReject) GetAmountInfos

func (q *QuotaBucketReject) GetAmountInfos() []ratelimiter.AmountInfo

GetAmountInfos 获取规则的限流阈值信息

func (*QuotaBucketReject) GetQuota

func (q *QuotaBucketReject) GetQuota(curTimeMs int64, token uint32) *model.QuotaResponse

GetQuota 在令牌桶/漏桶中进行单个配额的划扣,并返回本次分配的结果

func (*QuotaBucketReject) GetQuotaUsed

func (q *QuotaBucketReject) GetQuotaUsed(curTimeMilli int64) ratelimiter.UsageInfo

GetQuotaUsed 拉取本地使用配额情况以供上报

func (*QuotaBucketReject) OnRemoteUpdate

func (q *QuotaBucketReject) OnRemoteUpdate(remoteQuota ratelimiter.RemoteQuotaResult)

OnRemoteUpdate 远程配额更新

func (*QuotaBucketReject) Release

func (q *QuotaBucketReject) Release()

Release 释放配额(仅对于并发数限流有用)

type RateLimiterReject

type RateLimiterReject struct {
	*plugin.PluginBase
}

RateLimiterReject 基于直接拒绝策略的限流控制器

func (*RateLimiterReject) Destroy

func (g *RateLimiterReject) Destroy() error

Destroy 销毁插件,可用于释放资源

func (*RateLimiterReject) Init

func (g *RateLimiterReject) Init(ctx *plugin.InitContext) error

Init 初始化插件

func (*RateLimiterReject) InitQuota

InitQuota 初始化并创建限流窗口 主流程会在首次调用,以及规则对象变更的时候,调用该方法

func (*RateLimiterReject) IsEnable

func (g *RateLimiterReject) IsEnable(cfg config.Configuration) bool

IsEnable enable

func (*RateLimiterReject) Name

func (g *RateLimiterReject) Name() string

Name 插件名,一个类型下插件名唯一

func (*RateLimiterReject) Type

func (g *RateLimiterReject) Type() common.Type

Type 插件类型

type RemoteAwareQpsBucket

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

RemoteAwareQpsBucket 远程配额分配的算法桶

func NewRemoteAwareQpsBucket

func NewRemoteAwareQpsBucket(criteria *ratelimiter.InitCriteria) *RemoteAwareQpsBucket

NewRemoteAwareQpsBucket 创建QPS远程限流窗口

func (*RemoteAwareQpsBucket) Allocate

func (r *RemoteAwareQpsBucket) Allocate(curTimeMs int64, token uint32) *model.QuotaResponse

Allocate 执行配额分配操作

func (*RemoteAwareQpsBucket) GetQuotaUsed

func (r *RemoteAwareQpsBucket) GetQuotaUsed(serverTimeMilli int64) ratelimiter.UsageInfo

func (*RemoteAwareQpsBucket) GetTokenBuckets

func (r *RemoteAwareQpsBucket) GetTokenBuckets() TokenBuckets

func (*RemoteAwareQpsBucket) Release

func (r *RemoteAwareQpsBucket) Release()

Release 执行配额回收操作

func (*RemoteAwareQpsBucket) SetRemoteQuota

func (r *RemoteAwareQpsBucket) SetRemoteQuota(remoteQuotas ratelimiter.RemoteQuotaResult)

SetRemoteQuota 设置通过限流服务端获取的远程QPS

type TokenBucket

type TokenBucket struct {
	UpdateIdentifier
	// contains filtered or unexported fields
}

TokenBucket 令牌桶

func NewTokenBucket

func NewTokenBucket(
	windowKey string, validDuration time.Duration, tokenAmount uint32, shareInfo *BucketShareInfo) *TokenBucket

NewTokenBucket 创建令牌桶

func (*TokenBucket) ConfirmLimited

func (t *TokenBucket) ConfirmLimited(limited uint32, nowMilli int64)

ConfirmLimited 记录限流分配配额

func (*TokenBucket) ConfirmPassed

func (t *TokenBucket) ConfirmPassed(passed uint32, nowMilli int64)

ConfirmPassed 记录真实分配配额

func (*TokenBucket) GetRuleTotal

func (t *TokenBucket) GetRuleTotal() int64

GetRuleTotal 获取限流总量

func (*TokenBucket) GiveBackToken

func (t *TokenBucket) GiveBackToken(identifier *UpdateIdentifier, token int64, mode TokenBucketMode)

GiveBackToken 归还配额

func (*TokenBucket) TryAllocateToken

func (t *TokenBucket) TryAllocateToken(
	token uint32, nowMilli int64, identifier *UpdateIdentifier, mode TokenBucketMode) (int64, TokenBucketMode)

TryAllocateToken 尝试分配配额

func (*TokenBucket) UpdateRemoteClientCount

func (t *TokenBucket) UpdateRemoteClientCount(remoteQuotas ratelimiter.RemoteQuotaResult)

UpdateRemoteClientCount 只更新远程客户端数量,不更新配额

func (*TokenBucket) UpdateRemoteToken

func (t *TokenBucket) UpdateRemoteToken(remoteQuotas ratelimiter.RemoteQuotaResult, updateClient bool)

UpdateRemoteToken 更新远程配额

type TokenBucketMode

type TokenBucketMode int
const (
	Unknown TokenBucketMode = iota
	Remote
	RemoteToLocal
	Local
)

type TokenBuckets

type TokenBuckets []*TokenBucket

TokenBuckets 令牌桶序列

func (TokenBuckets) Len

func (tbs TokenBuckets) Len() int

Len 数组长度

func (TokenBuckets) Less

func (tbs TokenBuckets) Less(i, j int) bool

Less 比较数组成员大小

func (TokenBuckets) Swap

func (tbs TokenBuckets) Swap(i, j int)

Swap 交换数组成员

type UpdateIdentifier

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

UpdateIdentifier 令牌桶是否进行更新的凭证

Jump to

Keyboard shortcuts

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