flowcontrol

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2021 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	FlowControlFilterName = "flowControlFilter"
)

FlowControlFilterName is the flow control stream filter name.

Variables

This section is empty.

Functions

func RegisterCallbacks added in v0.21.0

func RegisterCallbacks(name string, cb Callbacks)

RegisterCallbacks stores customized callbacks.

Types

type Action

type Action struct {
	Status int    `json:"status"`
	Body   string `json:"body"`
}

Action represents the direct response of request after limited.

type Callbacks

type Callbacks interface {
	Init()
	ShouldIgnore(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) bool
	Prepare(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType)
	ParseResource(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType) *ParsedResource
	AfterBlock(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)
	AfterPass(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)
	Append(ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)
	Exit(filter *StreamFilter)
	Enabled() bool
	SetConfig(conf *Config)
	GetConfig() *Config
}

Callbacks defines the flow control callbacks

func GetCallbacksByConfig added in v0.21.0

func GetCallbacksByConfig(conf *Config) Callbacks

GetCallbacksByName returns specified or default Callbacks.

type Config

type Config struct {
	AppName      string                   `json:"app_name"`
	CallbackName string                   `json:"callback_name"`
	LogPath      string                   `json:"log_path"`
	GlobalSwitch bool                     `json:"global_switch"`
	Monitor      bool                     `json:"monitor"`
	KeyType      api.ProtocolResourceName `json:"limit_key_type"`
	Action       Action                   `json:"action"`
	Rules        []*flow.Rule             `json:"rules"`
}

Config represents the flow control configurations.

type DefaultCallbacks

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

DefaultCallbacks represents the default flow control filter implementation.

func (*DefaultCallbacks) AfterBlock

func (dc *DefaultCallbacks) AfterBlock(filter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)

AfterBlock sends response directly.

func (*DefaultCallbacks) AfterPass

func (dc *DefaultCallbacks) AfterPass(filter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap)

AfterPass is a no-op by default.

func (*DefaultCallbacks) Append added in v0.21.0

func (dc *DefaultCallbacks) Append(ctx context.Context, headers types.HeaderMap,
	buf types.IoBuffer, trailers types.HeaderMap)

Append is a no-op by default.

func (*DefaultCallbacks) Enabled

func (dc *DefaultCallbacks) Enabled() bool

Enabled reports whether the callbacks enabled.

func (*DefaultCallbacks) Exit

func (dc *DefaultCallbacks) Exit(filter *StreamFilter)

Exit is a no-op by default.

func (*DefaultCallbacks) GetConfig added in v0.22.0

func (dc *DefaultCallbacks) GetConfig() *Config

GetConfig gets the config of callbacks.

func (*DefaultCallbacks) Init

func (dc *DefaultCallbacks) Init()

Init is a no-op.

func (*DefaultCallbacks) ParseResource

func (dc *DefaultCallbacks) ParseResource(ctx context.Context, headers types.HeaderMap,
	buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType) *ParsedResource

ParseResource parses Resource from context.

func (*DefaultCallbacks) Prepare added in v0.21.0

func (dc *DefaultCallbacks) Prepare(ctx context.Context, headers types.HeaderMap,
	buf types.IoBuffer, trailers types.HeaderMap, trafficType base.TrafficType)

Prepare is a no-op by default.

func (*DefaultCallbacks) SetConfig added in v0.22.0

func (dc *DefaultCallbacks) SetConfig(conf *Config)

SetConfig sets the config of callbacks.

func (*DefaultCallbacks) ShouldIgnore added in v0.21.0

func (dc *DefaultCallbacks) ShouldIgnore(flowControlFilter *StreamFilter, ctx context.Context, headers types.HeaderMap, buf types.IoBuffer, trailers types.HeaderMap) bool

ShouldIgnore is a no-op by default.

type ParsedResource

type ParsedResource struct {
	Resource *base.ResourceWrapper
	Opts     []sentinel.EntryOption
}

ParsedResource contains the parsed Resource wrapper and entry options.

type StreamFilter

type StreamFilter struct {
	Entry           *base.SentinelEntry
	BlockError      *base.BlockError
	Callbacks       Callbacks
	ReceiverHandler api.StreamReceiverFilterHandler
	SenderHandler   api.StreamSenderFilterHandler
	// contains filtered or unexported fields
}

StreamFilter represents the flow control stream filter.

func NewStreamFilter

func NewStreamFilter(callbacks Callbacks, trafficType base.TrafficType) *StreamFilter

NewStreamFilter creates flow control filter.

func (*StreamFilter) Append added in v0.21.0

Append will be called after request response, do nothing if request was blocked in OnReceive phase.

func (*StreamFilter) OnDestroy

func (f *StreamFilter) OnDestroy()

OnDestroy calls the exit tasks.

func (*StreamFilter) OnReceive

func (f *StreamFilter) OnReceive(ctx context.Context, headers types.HeaderMap,
	buf types.IoBuffer, trailers types.HeaderMap) api.StreamFilterStatus

OnReceive creates resource and judges whether current request should be blocked.

func (*StreamFilter) SetReceiveFilterHandler

func (f *StreamFilter) SetReceiveFilterHandler(handler api.StreamReceiverFilterHandler)

func (*StreamFilter) SetSenderFilterHandler added in v0.21.0

func (f *StreamFilter) SetSenderFilterHandler(handler api.StreamSenderFilterHandler)

type StreamFilterFactory

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

StreamFilterFactory represents the stream filter factory.

func (*StreamFilterFactory) CreateFilterChain

func (f *StreamFilterFactory) CreateFilterChain(context context.Context,
	callbacks api.StreamFilterChainFactoryCallbacks)

CreateFilterChain add the flow control stream filter to filter chain.

Jump to

Keyboard shortcuts

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