MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / initFSM

Method initFSM

pkg/rules/sequence.go:166–199  ·  view source on GitHub ↗

initFSM initializes the state machine and installs transition callbacks that are triggered when the expression in the sequence matches, it expires or the deadline occurs.

()

Source from the content-addressed store, hash-verified

164// that are triggered when the expression in the sequence matches, it expires
165// or the deadline occurs.
166func (s *sequenceState) initFSM() {
167 s.fsm = fsm.NewStateMachine(s.initialState)
168 s.fsm.OnTransitioned(func(ctx context.Context, transition fsm.Transition) {
169 // schedule span deadline for the current state unless initial/meta states
170 if s.maxSpan != 0 && s.isStateSchedulable(s.currentState()) {
171 log.Debugf("scheduling max span deadline of %v for expression [%s] of sequence [%s]", s.maxSpan, s.expr(s.currentState()), s.name)
172 s.scheduleMaxSpanDeadline(s.currentState(), s.maxSpan)
173 }
174 // if the sequence was deadlined/expired, we can disable the deadline
175 // status when the first expression in the sequence is reevaluated
176 if transition.Source == s.initialState && s.inDeadline.Load() {
177 s.inDeadline.Store(false)
178 }
179 if transition.Source == s.initialState && s.inExpired.Load() {
180 s.inExpired.Store(false)
181 }
182 // clear state in case of expire/deadline transitions
183 if transition.Trigger == expireTransition || transition.Trigger == cancelTransition {
184 s.clear()
185 }
186 if transition.Trigger == matchTransition {
187 log.Debugf("state trigger from expression [%s] of sequence [%s]", s.expr(transition.Source), s.name)
188 // a match occurred from current to next state.
189 // Stop deadline execution for the old current state
190 if span, ok := s.spanDeadlines[transition.Source]; ok {
191 log.Debugf("stopped max span deadline for expression [%s] of sequence [%s]", s.expr(transition.Source), s.name)
192 span.Stop()
193 delete(s.spanDeadlines, transition.Source)
194 }
195 // save expression match
196 s.states[transition.Source] = true
197 }
198 })
199}
200
201// configureFSM sets up the states and transitions of the state automata.
202// A simplified representation of the constructed automata is better

Callers 1

newSequenceStateFunction · 0.95

Calls 7

isStateSchedulableMethod · 0.95
currentStateMethod · 0.95
exprMethod · 0.95
clearMethod · 0.95
StoreMethod · 0.80
StopMethod · 0.45

Tested by

no test coverage detected