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

Method evalBoundSequence

pkg/filter/filter.go:256–337  ·  view source on GitHub ↗

evalBoundSequence evaluates the sequence with bound fields and returns true if the sequence expression matches or false otherwise.

(
	e *event.Event,
	seqID int,
	expr *ql.SequenceExpr,
	partials map[int][]*event.Event,
	valuer ql.MapValuer,
)

Source from the content-addressed store, hash-verified

254// and returns true if the sequence expression matches or false
255// otherwise.
256func (f *filter) evalBoundSequence(
257 e *event.Event,
258 seqID int,
259 expr *ql.SequenceExpr,
260 partials map[int][]*event.Event,
261 valuer ql.MapValuer,
262) bool {
263 // map all partials to their sequence aliases
264 maxSlots := len(partials[seqID])
265 aliasEvents := make(map[string][]*event.Event, seqID)
266 for i := range seqID {
267 alias := f.seq.Expressions[i].Alias
268 if alias == "" {
269 continue
270 }
271 aliasEvents[alias] = partials[i]
272 if l := len(partials[i]); l > maxSlots {
273 maxSlots = l
274 }
275 }
276
277 // retrieve or compute bound fields for this sequence expression
278 flds, ok := f.seqBoundFields[seqID]
279 if !ok {
280 flds = f.addSeqBoundFields(seqID, expr.BoundFields)
281 }
282
283 // iterate slot-by-slot across all bound aliases
284 for slot := 0; slot < maxSlots; slot++ {
285 // process each bound field in this sequence expression
286 var evt *event.Event
287 for _, fld := range flds {
288 evts := aliasEvents[fld.BoundVar]
289 switch {
290 case len(evts) == 0:
291 continue
292 case slot >= len(evts):
293 // pick the latest event if all
294 // events for this slot are consumed
295 evt = evts[len(evts)-1]
296 default:
297 evt = evts[slot]
298 }
299
300 // extract bound variable value
301 accessor := fld.Accessor(f)
302 if accessor == nil {
303 continue
304 }
305 v, err := accessor.Get(fld.Field, evt)
306 if v == nil || err != nil {
307 if v == nil {
308 valuer[fld.Value] = defaultAccessorValue(fld.Field)
309 }
310 if err != nil && !errs.IsParamNotFound(err) {
311 valuer[fld.Value] = defaultAccessorValue(fld.Field)
312 accessorErrors.Add(err.Error(), 1)
313 }

Callers 1

RunSequenceMethod · 0.95

Calls 9

addSeqBoundFieldsMethod · 0.95
AddSequenceLinkMethod · 0.95
EvalFunction · 0.92
defaultAccessorValueFunction · 0.85
hashFieldsFunction · 0.85
AccessorMethod · 0.80
GetMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected