Documentation ¶
Index ¶
- Constants
- type BlockError
- type BlockType
- type EntryContext
- type MetricEvent
- type MetricItem
- type MetricItemRetriever
- type ReadStat
- type ResourceType
- type ResourceWrapper
- type RuleCheckSlot
- type SentinelEntry
- type SentinelInput
- type SentinelOutput
- type SentinelRule
- type SlotChain
- func (sc *SlotChain) AddRuleCheckSlotFirst(s RuleCheckSlot)
- func (sc *SlotChain) AddRuleCheckSlotLast(s RuleCheckSlot)
- func (sc *SlotChain) AddStatPrepareSlotFirst(s StatPrepareSlot)
- func (sc *SlotChain) AddStatPrepareSlotLast(s StatPrepareSlot)
- func (sc *SlotChain) AddStatSlotFirst(s StatSlot)
- func (sc *SlotChain) AddStatSlotLast(s StatSlot)
- func (sc *SlotChain) Entry(ctx *EntryContext) *TokenResult
- func (sc *SlotChain) GetPooledContext() *EntryContext
- func (sc *SlotChain) RefurbishContext(c *EntryContext)
- type StatNode
- type StatPrepareSlot
- type StatSlot
- type TimePredicate
- type TokenResult
- func NewTokenResultBlocked(blockType BlockType, blockMsg string) *TokenResult
- func NewTokenResultBlockedWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *TokenResult
- func NewTokenResultPass() *TokenResult
- func NewTokenResultShouldWait(waitMs uint64) *TokenResult
- type TokenResultStatus
- type TrafficType
- type WriteStat
Constants ¶
const ( TotalInBoundResourceName = "__total_inbound_traffic__" DefaultMaxResourceAmount uint32 = 10000 DefaultSampleCount uint32 = 2 DefaultIntervalMs uint32 = 1000 // default 10*1000/500 = 20 DefaultSampleCountTotal uint32 = 20 // default 10s (total length) DefaultIntervalMsTotal uint32 = 10000 DefaultStatisticMaxRt = int64(60000) )
global variable
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockError ¶
type BlockError struct {
// contains filtered or unexported fields
}
BlockError indicates the request was blocked by Sentinel.
func NewBlockError ¶
func NewBlockError(blockType BlockType, blockMsg string) *BlockError
func NewBlockErrorWithCause ¶
func NewBlockErrorWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *BlockError
func (*BlockError) BlockMsg ¶
func (e *BlockError) BlockMsg() string
func (*BlockError) BlockType ¶
func (e *BlockError) BlockType() BlockType
func (*BlockError) Error ¶
func (e *BlockError) Error() string
func (*BlockError) TriggeredRule ¶
func (e *BlockError) TriggeredRule() SentinelRule
func (*BlockError) TriggeredValue ¶
func (e *BlockError) TriggeredValue() interface{}
type EntryContext ¶
type EntryContext struct { Resource *ResourceWrapper StatNode StatNode Input *SentinelInput Output *SentinelOutput // contains filtered or unexported fields }
func NewEmptyEntryContext ¶
func NewEmptyEntryContext() *EntryContext
func (*EntryContext) IsBlocked ¶
func (ctx *EntryContext) IsBlocked() bool
func (*EntryContext) StartTime ¶
func (ctx *EntryContext) StartTime() uint64
type MetricEvent ¶
type MetricEvent int8
const ( // sentinel rules check pass MetricEventPass MetricEvent = iota // sentinel rules check block MetricEventBlock MetricEventComplete // Biz error, used for circuit breaker MetricEventError // request execute rt, unit is millisecond MetricEventRt // hack for the number of event MetricEventTotal )
There are five events to record pass + block == Total
type MetricItem ¶
type MetricItem struct { Resource string Classification int32 Timestamp uint64 PassQps uint64 BlockQps uint64 CompleteQps uint64 ErrorQps uint64 AvgRt uint64 OccupiedPassQps uint64 Concurrency uint32 }
MetricItem represents the data of metric log per line.
func MetricItemFromFatString ¶
func MetricItemFromFatString(line string) (*MetricItem, error)
func (*MetricItem) ToFatString ¶
func (m *MetricItem) ToFatString() (string, error)
func (*MetricItem) ToThinString ¶
func (m *MetricItem) ToThinString() (string, error)
type MetricItemRetriever ¶
type MetricItemRetriever interface {
MetricsOnCondition(predicate TimePredicate) []*MetricItem
}
type ReadStat ¶
type ReadStat interface { GetQPS(event MetricEvent) float64 GetSum(event MetricEvent) int64 MinRT() float64 AvgRT() float64 }
type ResourceType ¶
type ResourceType int32
ResourceType represents classification of the resources
const ( ResTypeCommon ResourceType = iota ResTypeWeb ResTypeRPC ResTypeAPIGateway ResTypeDBSQL ResTypeCache ResTypeMQ )
type ResourceWrapper ¶
type ResourceWrapper struct {
// contains filtered or unexported fields
}
ResourceWrapper represents the invocation
func NewResourceWrapper ¶
func NewResourceWrapper(name string, classification ResourceType, flowType TrafficType) *ResourceWrapper
func (*ResourceWrapper) Classification ¶
func (r *ResourceWrapper) Classification() ResourceType
func (*ResourceWrapper) FlowType ¶
func (r *ResourceWrapper) FlowType() TrafficType
func (*ResourceWrapper) Name ¶
func (r *ResourceWrapper) Name() string
func (*ResourceWrapper) String ¶
func (r *ResourceWrapper) String() string
type RuleCheckSlot ¶
type RuleCheckSlot interface { // Check function do some validation // It can break off the slot pipeline // Each TokenResult will return check result // The upper logic will control pipeline according to SlotResult. Check(ctx *EntryContext) *TokenResult }
RuleCheckSlot is rule based checking strategy All checking rule must implement this interface.
type SentinelEntry ¶
type SentinelEntry struct {
// contains filtered or unexported fields
}
func NewSentinelEntry ¶
func NewSentinelEntry(ctx *EntryContext, rw *ResourceWrapper, sc *SlotChain) *SentinelEntry
func (*SentinelEntry) Context ¶
func (e *SentinelEntry) Context() *EntryContext
func (*SentinelEntry) Exit ¶
func (e *SentinelEntry) Exit()
func (*SentinelEntry) Resource ¶
func (e *SentinelEntry) Resource() *ResourceWrapper
type SentinelInput ¶
type SentinelOutput ¶
type SentinelOutput struct { LastResult *TokenResult // contains filtered or unexported fields }
type SentinelRule ¶
type SlotChain ¶
type SlotChain struct {
// contains filtered or unexported fields
}
SlotChain hold all system slots and customized slot. SlotChain support plug-in slots developed by developer.
func NewSlotChain ¶
func NewSlotChain() *SlotChain
func (*SlotChain) AddRuleCheckSlotFirst ¶
func (sc *SlotChain) AddRuleCheckSlotFirst(s RuleCheckSlot)
func (*SlotChain) AddRuleCheckSlotLast ¶
func (sc *SlotChain) AddRuleCheckSlotLast(s RuleCheckSlot)
func (*SlotChain) AddStatPrepareSlotFirst ¶
func (sc *SlotChain) AddStatPrepareSlotFirst(s StatPrepareSlot)
func (*SlotChain) AddStatPrepareSlotLast ¶
func (sc *SlotChain) AddStatPrepareSlotLast(s StatPrepareSlot)
func (*SlotChain) AddStatSlotFirst ¶
func (*SlotChain) AddStatSlotLast ¶
func (*SlotChain) Entry ¶
func (sc *SlotChain) Entry(ctx *EntryContext) *TokenResult
The entrance of slot chain Return the TokenResult and nil if internal panic.
func (*SlotChain) GetPooledContext ¶
func (sc *SlotChain) GetPooledContext() *EntryContext
Get a EntryContext from EntryContext pool, if pool doesn't have enough EntryContext then new one.
func (*SlotChain) RefurbishContext ¶
func (sc *SlotChain) RefurbishContext(c *EntryContext)
type StatNode ¶
type StatNode interface { MetricItemRetriever ReadStat WriteStat CurrentGoroutineNum() int32 IncreaseGoroutineNum() DecreaseGoroutineNum() Reset() }
StatNode holds real-time statistics for resources.
type StatPrepareSlot ¶
type StatPrepareSlot interface { // Prepare function do some initialization // Such as: init statistic structure、node and etc // The result of preparing would store in EntryContext // All StatPrepareSlots execute in sequence // Prepare function should not throw panic. Prepare(ctx *EntryContext) }
StatPrepareSlot is responsible for some preparation before statistic For example: init structure and so on
type StatSlot ¶
type StatSlot interface { // OnEntryPass function will be invoked when StatPrepareSlots and RuleCheckSlots execute pass // StatSlots will do some statistic logic, such as QPS、log、etc OnEntryPassed(ctx *EntryContext) // OnEntryBlocked function will be invoked when StatPrepareSlots and RuleCheckSlots fail to execute // It may be inbound flow control or outbound cir // StatSlots will do some statistic logic, such as QPS、log、etc // blockError introduce the block detail OnEntryBlocked(ctx *EntryContext, blockError *BlockError) // onComplete function will be invoked when chain exits. // The request may be executed successful or blocked or internal error OnCompleted(ctx *EntryContext) }
StatSlot is responsible for counting all custom biz metrics. StatSlot would not handle any panic, and pass up all panic to slot chain
type TimePredicate ¶
type TokenResult ¶
type TokenResult struct {
// contains filtered or unexported fields
}
func NewTokenResultBlocked ¶
func NewTokenResultBlocked(blockType BlockType, blockMsg string) *TokenResult
func NewTokenResultBlockedWithCause ¶
func NewTokenResultBlockedWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *TokenResult
func NewTokenResultPass ¶
func NewTokenResultPass() *TokenResult
func NewTokenResultShouldWait ¶
func NewTokenResultShouldWait(waitMs uint64) *TokenResult
func (*TokenResult) BlockError ¶
func (r *TokenResult) BlockError() *BlockError
func (*TokenResult) IsBlocked ¶
func (r *TokenResult) IsBlocked() bool
func (*TokenResult) IsPass ¶
func (r *TokenResult) IsPass() bool
func (*TokenResult) Status ¶
func (r *TokenResult) Status() TokenResultStatus
func (*TokenResult) String ¶
func (r *TokenResult) String() string
func (*TokenResult) WaitMs ¶
func (r *TokenResult) WaitMs() uint64
type TokenResultStatus ¶
type TokenResultStatus int32
const ( ResultStatusPass TokenResultStatus = iota ResultStatusBlocked ResultStatusShouldWait )
type TrafficType ¶
type TrafficType int32
TrafficType describes the traffic type: Inbound or Outbound
const ( // Inbound represents the inbound traffic (e.g. provider) Inbound TrafficType = iota // Outbound represents the outbound traffic (e.g. consumer) Outbound )
func (TrafficType) String ¶
func (t TrafficType) String() string
type WriteStat ¶
type WriteStat interface {
AddMetric(event MetricEvent, count uint64)
}