ratelimiter

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AmountDuration

type AmountDuration struct {
	AmountUsed    uint32
	ValidDuration time.Duration
}

AmountDuration 单个配额

type AmountInfo added in v1.2.0

type AmountInfo struct {
	// 限流时间段,单位秒
	ValidDuration uint32
	// 最大配额数
	MaxAmount uint32
}

type InitCriteria

type InitCriteria struct {
	DstRule   *namingpb.Rule
	WindowKey string
}

InitCriteria 配额查询相关的信息

type Proxy

type Proxy struct {
	ServiceRateLimiter
	// contains filtered or unexported fields
}

Proxy is a proxy plugin for rate-limiter

func (*Proxy) InitQuota

func (p *Proxy) InitQuota(criteria *InitCriteria) QuotaBucket

InitQuota proxy ServiceRateLimiter InitQuota

func (*Proxy) SetRealPlugin

func (p *Proxy) SetRealPlugin(plug plugin.Plugin, engine model.Engine)

SetRealPlugin 设置

type QuotaBucket

type QuotaBucket interface {
	// GetQuota 在令牌桶/漏桶中进行单个配额的划扣,并返回本次分配的结果
	GetQuota(curTimeMs int64, token uint32) *model.QuotaResponse
	// Release 释放配额(仅对于并发数限流有用)
	Release()
	// OnRemoteUpdate 远程配额更新
	OnRemoteUpdate(RemoteQuotaResult)
	// GetQuotaUsed 拉取本地使用配额情况以供上报
	GetQuotaUsed(curTimeMilli int64) UsageInfo
	// GetAmountInfos 获取规则的限流阈值信息
	GetAmountInfos() []AmountInfo
}

QuotaBucket 配额池

type RemoteQuotaResult added in v1.2.0

type RemoteQuotaResult struct {
	Left            int64
	ClientCount     uint32
	ServerTimeMilli int64
	DurationMill    int64
	ClientTimeMilli int64
}

RemoteQuotaResult 远程下发配额

type ServiceRateLimiter

type ServiceRateLimiter interface {
	plugin.Plugin
	// InitQuota 初始化并创建令牌桶/漏桶
	// 主流程会在首次调用,以及规则对象变更的时候,调用该方法
	InitQuota(criteria *InitCriteria) QuotaBucket
}

ServiceRateLimiter 服务限流处理插件接口

type UsageInfo added in v1.2.0

type UsageInfo struct {
	// 配额使用时间
	CurTimeMilli int64
	// 配额使用详情
	Passed map[int64]uint32
	// 限流情况
	Limited map[int64]uint32
}

UsageInfo 配额使用信息

Jump to

Keyboard shortcuts

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