Documentation
¶
Index ¶
- Constants
- func ClearRules() error
- func IsValidFlowRule(rule *FlowRule) error
- func LoadRules(rules []*FlowRule) (bool, error)
- func RemoveTrafficShapingGenerator(cb ControlBehavior) error
- func SetTrafficShapingGenerator(cb ControlBehavior, generator TrafficControllerGenFunc) error
- type ClusterRuleConfig
- type ClusterThresholdMode
- type ControlBehavior
- type DefaultTrafficShapingCalculator
- type DefaultTrafficShapingChecker
- type FlowRule
- type FlowSlot
- type MetricType
- type RelationStrategy
- type ThrottlingChecker
- type TrafficControllerGenFunc
- type TrafficControllerMap
- type TrafficShapingCalculator
- type TrafficShapingChecker
- type TrafficShapingController
- func (t *TrafficShapingController) FlowCalculator() TrafficShapingCalculator
- func (t *TrafficShapingController) FlowChecker() TrafficShapingChecker
- func (t *TrafficShapingController) PerformChecking(node base.StatNode, acquireCount uint32, flag int32) *base.TokenResult
- func (t *TrafficShapingController) Rule() *FlowRule
- type WarmUpTrafficShapingCalculator
Constants ¶
const ( // LimitOriginDefault represents all origins. LimitOriginDefault = "default" // LimitOriginOther represents all origins excluding those configured in other rules. // For example, if resource "abc" has a rule whose limit origin is "originA", // the "other" origin will represents all origins excluding "originA". LimitOriginOther = "other" )
Variables ¶
This section is empty.
Functions ¶
func ClearRules ¶
func ClearRules() error
func IsValidFlowRule ¶
IsValidFlowRule checks whether the given FlowRule is valid.
func LoadRules ¶
LoadRules loads the given flow rules to the rule manager, while all previous rules will be replaced.
func RemoveTrafficShapingGenerator ¶
func RemoveTrafficShapingGenerator(cb ControlBehavior) error
func SetTrafficShapingGenerator ¶
func SetTrafficShapingGenerator(cb ControlBehavior, generator TrafficControllerGenFunc) error
SetTrafficShapingGenerator sets the traffic controller generator for the given control behavior. Note that modifying the generator of default control behaviors is not allowed.
Types ¶
type ClusterRuleConfig ¶
type ClusterRuleConfig struct {
ThresholdType ClusterThresholdMode `json:"thresholdType"`
}
type ClusterThresholdMode ¶
type ClusterThresholdMode uint32
const ( AvgLocalThreshold ClusterThresholdMode = iota GlobalThreshold )
type ControlBehavior ¶
type ControlBehavior int32
ControlBehavior indicates the traffic shaping behaviour.
const ( Reject ControlBehavior = iota WarmUp Throttling WarmUpThrottling )
type DefaultTrafficShapingCalculator ¶
type DefaultTrafficShapingCalculator struct {
// contains filtered or unexported fields
}
func NewDefaultTrafficShapingCalculator ¶
func NewDefaultTrafficShapingCalculator(threshold float64) *DefaultTrafficShapingCalculator
func (*DefaultTrafficShapingCalculator) CalculateAllowedTokens ¶
type DefaultTrafficShapingChecker ¶
type DefaultTrafficShapingChecker struct {
// contains filtered or unexported fields
}
func NewDefaultTrafficShapingChecker ¶
func NewDefaultTrafficShapingChecker(rule *FlowRule) *DefaultTrafficShapingChecker
func (*DefaultTrafficShapingChecker) DoCheck ¶
func (d *DefaultTrafficShapingChecker) DoCheck(node base.StatNode, acquireCount uint32, threshold float64) *base.TokenResult
type FlowRule ¶
type FlowRule struct { // ID represents the unique ID of the rule (optional). ID uint64 `json:"id,omitempty"` // Resource represents the resource name. Resource string `json:"resource"` // LimitOrigin represents the target origin (reserved field). LimitOrigin string `json:"limitOrigin"` MetricType MetricType `json:"metricType"` // Count represents the threshold. Count float64 `json:"count"` RelationStrategy RelationStrategy `json:"relationStrategy"` ControlBehavior ControlBehavior `json:"controlBehavior"` RefResource string `json:"refResource"` WarmUpPeriodSec uint32 `json:"warmUpPeriodSec"` MaxQueueingTimeMs uint32 `json:"maxQueueingTimeMs"` // ClusterMode indicates whether the rule is for cluster flow control or local. ClusterMode bool `json:"clusterMode"` ClusterConfig ClusterRuleConfig `json:"clusterConfig"` WarmUpColdFactor uint32 `json:"warmUpColdFactor"` }
FlowRule describes the strategy of flow control.
func (*FlowRule) ResourceName ¶
type FlowSlot ¶
type FlowSlot struct { }
FlowSlot
func (*FlowSlot) Check ¶
func (s *FlowSlot) Check(ctx *base.EntryContext) *base.TokenResult
type MetricType ¶
type MetricType int32
MetricType represents the target metric type.
const ( // Concurrency represents concurrency count. Concurrency MetricType = iota // QPS represents request count per second. QPS )
type RelationStrategy ¶
type RelationStrategy int32
RelationStrategy indicates the flow control strategy based on the relation of invocations.
const ( // Direct means flow control by current resource directly. Direct RelationStrategy = iota // AssociatedResource means flow control by the associated resource rather than current resource. AssociatedResource )
type ThrottlingChecker ¶
type ThrottlingChecker struct {
// contains filtered or unexported fields
}
ThrottlingChecker limits the time interval between two requests.
func NewThrottlingChecker ¶
func NewThrottlingChecker(timeoutMs uint32) *ThrottlingChecker
func (*ThrottlingChecker) DoCheck ¶
func (c *ThrottlingChecker) DoCheck(_ base.StatNode, acquireCount uint32, threshold float64) *base.TokenResult
type TrafficControllerGenFunc ¶
type TrafficControllerGenFunc func(*FlowRule) *TrafficShapingController
TrafficControllerGenFunc represents the TrafficShapingController generator function of a specific control behavior.
type TrafficControllerMap ¶
type TrafficControllerMap map[string][]*TrafficShapingController
TrafficControllerMap represents the map storage for TrafficShapingController.
type TrafficShapingCalculator ¶
type TrafficShapingCalculator interface {
CalculateAllowedTokens(node base.StatNode, acquireCount uint32, flag int32) float64
}
TrafficShapingCalculator calculates the actual traffic shaping threshold based on the threshold of rule and the traffic shaping strategy.
type TrafficShapingChecker ¶
type TrafficShapingChecker interface {
DoCheck(node base.StatNode, acquireCount uint32, threshold float64) *base.TokenResult
}
TrafficShapingChecker performs checking according to current metrics and the traffic shaping strategy, then yield the token result.
type TrafficShapingController ¶
type TrafficShapingController struct {
// contains filtered or unexported fields
}
func NewTrafficShapingController ¶
func NewTrafficShapingController(flowCalculator TrafficShapingCalculator, flowChecker TrafficShapingChecker, rule *FlowRule) *TrafficShapingController
NewTrafficShapingController creates a TrafficShapingController wrapped with the given checker and flow rule.
func (*TrafficShapingController) FlowCalculator ¶
func (t *TrafficShapingController) FlowCalculator() TrafficShapingCalculator
func (*TrafficShapingController) FlowChecker ¶
func (t *TrafficShapingController) FlowChecker() TrafficShapingChecker
func (*TrafficShapingController) PerformChecking ¶
func (t *TrafficShapingController) PerformChecking(node base.StatNode, acquireCount uint32, flag int32) *base.TokenResult
func (*TrafficShapingController) Rule ¶
func (t *TrafficShapingController) Rule() *FlowRule
type WarmUpTrafficShapingCalculator ¶ added in v0.6.0
type WarmUpTrafficShapingCalculator struct {
// contains filtered or unexported fields
}
func NewWarmUpTrafficShapingCalculator ¶ added in v0.6.0
func NewWarmUpTrafficShapingCalculator(rule *FlowRule) *WarmUpTrafficShapingCalculator