@@ -112,7 +112,7 @@ func (n *Node) validate(ectx EnricherCtx) error {
112
112
}
113
113
}
114
114
115
- for idx := range n .Stash {
115
+ for idx := range n .Stash {
116
116
// pointer not value, to avoid throwing away the defaults
117
117
stash := & n .Stash [idx ]
118
118
@@ -337,6 +337,46 @@ func (n *Node) processStash(p *types.Event, cachedExprEnv map[string]any, logger
337
337
return nil
338
338
}
339
339
340
+ func (n * Node ) processLeaves (
341
+ p * types.Event ,
342
+ ctx UnixParserCtx ,
343
+ cachedExprEnv map [string ]any ,
344
+ initialState bool ,
345
+ nodeHasOKGrok bool ,
346
+ ) (bool , error ) {
347
+ nodeState := initialState
348
+
349
+ for idx := range n .LeavesNodes {
350
+ child := & n .LeavesNodes [idx ]
351
+
352
+ ret , err := child .process (p , ctx , cachedExprEnv )
353
+ if err != nil {
354
+ n .Logger .Tracef ("\t Node (%s) failed: %v" , child .rn , err )
355
+ n .Logger .Debugf ("Event leaving node: ko" )
356
+ return false , err
357
+ }
358
+
359
+ n .Logger .Tracef ("\t sub-node (%s) ret: %v (strategy:%s)" , child .rn , ret , n .OnSuccess )
360
+
361
+ if ret {
362
+ nodeState = true
363
+ /* if child is successful, stop processing */
364
+ if n .OnSuccess == "next_stage" {
365
+ n .Logger .Debugf ("child is success, OnSuccess=next_stage, skip" )
366
+ break
367
+ }
368
+ } else if ! nodeHasOKGrok {
369
+ /*
370
+ If the parent node has a successful grok pattern, its state will stay successful even if one or more childs fail.
371
+ If the parent node is a skeleton node (no grok pattern), then at least one child must be successful for it to be a success.
372
+ */
373
+ nodeState = false
374
+ }
375
+ }
376
+
377
+ return nodeState , nil
378
+ }
379
+
340
380
func (n * Node ) process (p * types.Event , ctx UnixParserCtx , expressionEnv map [string ]any ) (bool , error ) {
341
381
clog := n .Logger
342
382
@@ -374,34 +414,13 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[stri
374
414
}
375
415
}
376
416
377
- // Iterate on leafs
378
- leaves := n .LeavesNodes
379
- for idx := range leaves {
380
- ret , err := leaves [idx ].process (p , ctx , cachedExprEnv )
381
- if err != nil {
382
- clog .Tracef ("\t Node (%s) failed : %v" , leaves [idx ].rn , err )
383
- clog .Debugf ("Event leaving node : ko" )
384
-
385
- return false , err
386
- }
417
+ leafState , err := n .processLeaves (p , ctx , cachedExprEnv , nodeState , nodeHasOKGrok )
418
+ if err != nil {
419
+ return false , err
420
+ }
387
421
388
- clog . Tracef ( " \t sub-node (%s) ret : %v (strategy:%s)" , leaves [ idx ]. rn , ret , n . OnSuccess )
422
+ nodeState = leafState
389
423
390
- if ret {
391
- nodeState = true
392
- /* if child is successful, stop processing */
393
- if n .OnSuccess == "next_stage" {
394
- clog .Debugf ("child is success, OnSuccess=next_stage, skip" )
395
- break
396
- }
397
- } else if ! nodeHasOKGrok {
398
- /*
399
- If the parent node has a successful grok pattern, it's state will stay successful even if one or more chil fails.
400
- If the parent node is a skeleton node (no grok pattern), then at least one child must be successful for it to be a success.
401
- */
402
- nodeState = false
403
- }
404
- }
405
424
/*todo : check if a node made the state change ?*/
406
425
/* should the childs inherit the on_success behavior */
407
426
0 commit comments