if

if #

CategoryScope
Routingrecord (sub-chain host)

Conditional branch: when the condition matches, records run the then sub-chain; otherwise the else sub-chain. After the branch completes, the event returns to the main chain. The condition body is written directly under the if key; then/else are sibling keys holding processor objects.

Conditions use the conditions DSL — field comparisons, patterns, ranges, network membership, and logical and/or/not combinations, nestable arbitrarily.

Structure #

- if:
    <condition>            # any condition operator, see Conditions
  then:
    - <processor>...       # runs when the condition matches
  else:
    - <processor>...       # optional; runs when it does not
KeyDescription
<condition>Condition operator at the if key (equals, regexp, range, and, …).
thenSub-chain for matching records. An empty then fails compile validation.
elseOptional sub-chain for non-matching records.
whenPer-processor conditional execution is the same mechanism declared on any processor (evaluates the condition, skips the step when it does not match).

Example #

- if:
    equals:
      log_level: error
  then:
    - drop_event:
  else:
    - mutate:
        add:
          routed: non-error

Notes #

  • Branch execution returns to the main chain afterwards; a branch terminal processor (e.g. drop_event) ends the event instead.
  • Sub-chain processors must be safe for concurrent Process calls when the surrounding for_each runs with parallel > 1 (each processor only touches its own record).
Edit Edit this page