Documentation ¶
Index ¶
- Constants
- type BlockError
- func NewBlockError(blockType BlockType) *BlockError
- func NewBlockErrorFromDeepCopy(from *BlockError) *BlockError
- func NewBlockErrorWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *BlockError
- func NewBlockErrorWithMessage(blockType BlockType, message string) *BlockError
- type BlockType
- type EntryContext
- func (ctx *EntryContext) Entry() *SentinelEntry
- func (ctx *EntryContext) Err() error
- func (ctx *EntryContext) IsBlocked() bool
- func (ctx *EntryContext) PutRt(rt uint64)
- func (ctx *EntryContext) Reset()
- func (ctx *EntryContext) Rt() uint64
- func (ctx *EntryContext) SetEntry(entry *SentinelEntry)
- func (ctx *EntryContext) SetError(err error)
- func (ctx *EntryContext) StartTime() uint64
- type ExitHandler
- type ExitOption
- type ExitOptions
- type MetricEvent
- type MetricItem
- type MetricItemRetriever
- type ReadStat
- type ResourceType
- type ResourceWrapper
- type RuleCheckSlot
- type SentinelEntry
- type SentinelInput
- 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) *TokenResult
- func NewTokenResultBlockedWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *TokenResult
- func NewTokenResultBlockedWithMessage(blockType BlockType, blockMsg string) *TokenResult
- func NewTokenResultPass() *TokenResult
- func NewTokenResultShouldWait(waitMs uint64) *TokenResult
- func (r *TokenResult) BlockError() *BlockError
- func (r *TokenResult) DeepCopyFrom(newResult *TokenResult)
- func (r *TokenResult) IsBlocked() bool
- func (r *TokenResult) IsPass() bool
- func (r *TokenResult) ResetToBlocked(blockType BlockType)
- func (r *TokenResult) ResetToBlockedWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{})
- func (r *TokenResult) ResetToBlockedWithMessage(blockType BlockType, blockMsg string)
- func (r *TokenResult) ResetToPass()
- func (r *TokenResult) Status() TokenResultStatus
- func (r *TokenResult) String() string
- func (r *TokenResult) WaitMs() uint64
- 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) *BlockError
func NewBlockErrorFromDeepCopy ¶
func NewBlockErrorFromDeepCopy(from *BlockError) *BlockError
func NewBlockErrorWithCause ¶
func NewBlockErrorWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *BlockError
func NewBlockErrorWithMessage ¶
func NewBlockErrorWithMessage(blockType BlockType, message string) *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 // the result of rule slots check RuleCheckResult *TokenResult // reserve for storing some intermediate data from the Entry execution process Data map[interface{}]interface{} // contains filtered or unexported fields }
func NewEmptyEntryContext ¶
func NewEmptyEntryContext() *EntryContext
func (*EntryContext) Entry ¶
func (ctx *EntryContext) Entry() *SentinelEntry
func (*EntryContext) Err ¶
func (ctx *EntryContext) Err() error
func (*EntryContext) IsBlocked ¶
func (ctx *EntryContext) IsBlocked() bool
func (*EntryContext) PutRt ¶
func (ctx *EntryContext) PutRt(rt uint64)
func (*EntryContext) Rt ¶
func (ctx *EntryContext) Rt() uint64
func (*EntryContext) SetEntry ¶
func (ctx *EntryContext) SetEntry(entry *SentinelEntry)
func (*EntryContext) SetError ¶
func (ctx *EntryContext) SetError(err error)
func (*EntryContext) StartTime ¶
func (ctx *EntryContext) StartTime() uint64
type ExitHandler ¶
type ExitHandler func(entry *SentinelEntry, ctx *EntryContext) error
type ExitOption ¶
type ExitOption func(*ExitOptions)
func WithError ¶
func WithError(err error) ExitOption
type ExitOptions ¶
type ExitOptions struct {
// contains filtered or unexported fields
}
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 GetPreviousQPS(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(exitOps ...ExitOption)
func (*SentinelEntry) Resource ¶
func (e *SentinelEntry) Resource() *ResourceWrapper
func (*SentinelEntry) SetError ¶
func (e *SentinelEntry) SetError(err error)
func (*SentinelEntry) WhenExit ¶
func (e *SentinelEntry) WhenExit(exitHandler ExitHandler)
type SentinelInput ¶
type SentinelInput struct { AcquireCount uint32 Flag int32 Args []interface{} // store some values in this context when calling context in slot. Attachments map[interface{}]interface{} }
The input data of sentinel
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 ctxPool, if ctxPool 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) // OnCompleted function will be invoked when chain exits. // The semantics of OnCompleted is the entry passed and completed // Note: blocked entry will not call this function 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) *TokenResult
func NewTokenResultBlockedWithCause ¶
func NewTokenResultBlockedWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{}) *TokenResult
func NewTokenResultBlockedWithMessage ¶
func NewTokenResultBlockedWithMessage(blockType BlockType, blockMsg string) *TokenResult
func NewTokenResultPass ¶
func NewTokenResultPass() *TokenResult
func NewTokenResultShouldWait ¶
func NewTokenResultShouldWait(waitMs uint64) *TokenResult
func (*TokenResult) BlockError ¶
func (r *TokenResult) BlockError() *BlockError
func (*TokenResult) DeepCopyFrom ¶
func (r *TokenResult) DeepCopyFrom(newResult *TokenResult)
func (*TokenResult) IsBlocked ¶
func (r *TokenResult) IsBlocked() bool
func (*TokenResult) IsPass ¶
func (r *TokenResult) IsPass() bool
func (*TokenResult) ResetToBlocked ¶
func (r *TokenResult) ResetToBlocked(blockType BlockType)
func (*TokenResult) ResetToBlockedWithCause ¶
func (r *TokenResult) ResetToBlockedWithCause(blockType BlockType, blockMsg string, rule SentinelRule, snapshot interface{})
func (*TokenResult) ResetToBlockedWithMessage ¶
func (r *TokenResult) ResetToBlockedWithMessage(blockType BlockType, blockMsg string)
func (*TokenResult) ResetToPass ¶
func (r *TokenResult) ResetToPass()
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 uint8
const ( ResultStatusPass TokenResultStatus = iota ResultStatusBlocked ResultStatusShouldWait )
func (TokenResultStatus) String ¶
func (s TokenResultStatus) String() string
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)
}