datasource

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Overview

Package ext/datasource provides interfaces and helper classes of dynamic data-source.

Index

Constants

View Source
const (
	OK                  = iota
	ConvertSourceError  = 1
	UpdatePropertyError = 2
	HandleSourceError   = 3
)

Variables

This section is empty.

Functions

func CircuitBreakerRuleJsonArrayParser

func CircuitBreakerRuleJsonArrayParser(src []byte) (interface{}, error)

func CircuitBreakerRulesUpdater

func CircuitBreakerRulesUpdater(data interface{}) error

CircuitBreakerRulesUpdater load the newest []cb.Rule to downstream circuit breaker component.

func FlowRuleJsonArrayParser

func FlowRuleJsonArrayParser(src []byte) (interface{}, error)

FlowRuleJsonArrayParser provide JSON as the default serialization for list of flow.Rule

func FlowRulesUpdater

func FlowRulesUpdater(data interface{}) error

FlowRulesUpdater load the newest []flow.Rule to downstream flow component.

func HotSpotParamRuleJsonArrayParser

func HotSpotParamRuleJsonArrayParser(src []byte) (interface{}, error)

HotSpotParamRuleJsonArrayParser decodes list of param flow rules from JSON bytes.

func HotSpotParamRulesUpdater

func HotSpotParamRulesUpdater(data interface{}) error

HotSpotParamRulesUpdater loads the provided hot-spot param rules to downstream rule manager.

func IsolationRuleJsonArrayParser

func IsolationRuleJsonArrayParser(src []byte) (interface{}, error)

IsolationRuleJsonArrayParser provide JSON as the default serialization for list of isolation.Rule

func IsolationRulesUpdater

func IsolationRulesUpdater(data interface{}) error

IsolationRulesUpdater load the newest []isolation.Rule to downstream system component.

func SystemRuleJsonArrayParser

func SystemRuleJsonArrayParser(src []byte) (interface{}, error)

SystemRuleJsonArrayParser provide JSON as the default serialization for list of system.Rule

func SystemRulesUpdater

func SystemRulesUpdater(data interface{}) error

SystemRulesUpdater load the newest []system.Rule to downstream system component.

Types

type Base

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

func (*Base) AddPropertyHandler

func (b *Base) AddPropertyHandler(h PropertyHandler)

func (*Base) Handle

func (b *Base) Handle(src []byte) (err error)

func (*Base) RemovePropertyHandler

func (b *Base) RemovePropertyHandler(h PropertyHandler)

type Code

type Code uint32

type DataSource

type DataSource interface {
	// Add specified property handler in current datasource
	AddPropertyHandler(h PropertyHandler)
	// Remove specified property handler in current datasource
	RemovePropertyHandler(h PropertyHandler)
	// Read original data from the data source.
	// return source bytes if succeed to read, if not, return error when reading
	ReadSource() ([]byte, error)
	// Initialize the datasource and load initial rules
	// start listener to listen on dynamic source
	// return error if initialize failed;
	// once initialized, listener should recover all panic and error.
	Initialize() error
	// Close the data source.
	io.Closer
}

The generic interface to describe the datasource Each DataSource instance listen in one property type.

type DefaultPropertyHandler

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

DefaultPropertyHandler encapsulate the Converter and updater of property. One DefaultPropertyHandler instance is to handle one property type. DefaultPropertyHandler should check whether current property is consistent with last update property converter convert the message to the specific property updater update the specific property to downstream.

func NewCircuitBreakerRulesHandler

func NewCircuitBreakerRulesHandler(converter PropertyConverter) *DefaultPropertyHandler

func NewDefaultPropertyHandler

func NewDefaultPropertyHandler(converter PropertyConverter, updater PropertyUpdater) *DefaultPropertyHandler

func NewIsolationRulesHandler

func NewIsolationRulesHandler(converter PropertyConverter) *DefaultPropertyHandler

func NewSystemRulesHandler

func NewSystemRulesHandler(converter PropertyConverter) *DefaultPropertyHandler

func (*DefaultPropertyHandler) Handle

func (h *DefaultPropertyHandler) Handle(src []byte) error

type Error

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

func NewError

func NewError(code Code, desc string) Error

func (Error) Code

func (e Error) Code() Code

func (Error) Error

func (e Error) Error() string

type HotspotRule

type HotspotRule struct {
	// ID is the unique id
	ID string `json:"id,omitempty"`
	// Resource is the resource name
	Resource string `json:"resource"`
	// MetricType indicates the metric type for checking logic.
	// For Concurrency metric, hotspot module will check the each hot parameter's concurrency,
	//		if concurrency exceeds the Threshold, reject the traffic directly.
	// For QPS metric, hotspot module will check the each hot parameter's QPS,
	//		the ControlBehavior decides the behavior of traffic shaping controller
	MetricType hotspot.MetricType `json:"metricType"`
	// ControlBehavior indicates the traffic shaping behaviour.
	// ControlBehavior only takes effect when MetricType is QPS
	ControlBehavior hotspot.ControlBehavior `json:"controlBehavior"`
	// ParamIndex is the index in context arguments slice.
	// if ParamIndex is great than or equals to zero, ParamIndex means the <ParamIndex>-th parameter
	// if ParamIndex is the negative, ParamIndex means the reversed <ParamIndex>-th parameter
	ParamIndex int `json:"paramIndex"`
	// Threshold is the threshold to trigger rejection
	Threshold int64 `json:"threshold"`
	// MaxQueueingTimeMs only takes effect when ControlBehavior is Throttling and MetricType is QPS
	MaxQueueingTimeMs int64 `json:"maxQueueingTimeMs"`
	// BurstCount is the silent count
	// BurstCount only takes effect when ControlBehavior is Reject and MetricType is QPS
	BurstCount int64 `json:"burstCount"`
	// DurationInSec is the time interval in statistic
	// DurationInSec only takes effect when MetricType is QPS
	DurationInSec int64 `json:"durationInSec"`
	// ParamsMaxCapacity is the max capacity of cache statistic
	ParamsMaxCapacity int64           `json:"paramsMaxCapacity"`
	SpecificItems     []SpecificValue `json:"specificItems"`
}

type MockPropertyHandler

type MockPropertyHandler struct {
	mock.Mock
}

func (*MockPropertyHandler) Handle

func (m *MockPropertyHandler) Handle(src []byte) error

type ParamKind

type ParamKind int

ParamKind represents the Param kind.

const (
	KindInt ParamKind = iota
	KindString
	KindBool
	KindFloat64
	KindSum
)

func (ParamKind) String

func (t ParamKind) String() string

type PropertyConverter

type PropertyConverter func(src []byte) (interface{}, error)

PropertyConverter func is to convert source message bytes to the specific property. the first return value: is the real property; the second return value: return nil if succeed to convert src, if not return the detailed error when convert src. if src is nil or len(src)==0, the return value is (nil,nil)

type PropertyHandler

type PropertyHandler interface {

	// handle the current property
	Handle(src []byte) error
	// contains filtered or unexported methods
}

func NewFlowRulesHandler

func NewFlowRulesHandler(converter PropertyConverter) PropertyHandler

func NewHotSpotParamRulesHandler

func NewHotSpotParamRulesHandler(converter PropertyConverter) PropertyHandler

type PropertyUpdater

type PropertyUpdater func(data interface{}) error

PropertyUpdater func is to update the specific properties to downstream. return nil if succeed to update, if not, return the error.

type SpecificValue

type SpecificValue struct {
	ValKind   ParamKind `json:"valKind"`
	ValStr    string    `json:"valStr"`
	Threshold int64     `json:"threshold"`
}

SpecificValue indicates the specific param, contain the supported param kind and concrete value.

func (*SpecificValue) String

func (s *SpecificValue) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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