github.com/argoproj/argo-events@v1.9.1/docs/eventsources/filtering.md (about)

     1  # Filtering EventSources
     2  
     3  When event sources watch events from external data sources (ie. Kafka topics), it will ingest all messages.
     4  With filtering, we are able to apply constraints and determine if the event should be published or skipped.
     5  This is achieved by evaluating an expression in the EventSource spec.
     6  
     7  # Fields
     8  
     9  A `filter` in an example Kafka EventSource:
    10  
    11  ```yaml
    12  apiVersion: argoproj.io/v1alpha1
    13  kind: EventSource
    14  metadata:
    15    name: kafka
    16  spec:
    17    kafka:
    18      example:
    19        url: kafka.argo-events:9092
    20        topic: topic-2
    21        jsonBody: true
    22        partition: "1"
    23        filter: # filter field 
    24          expression: "(body.id == 4) && (body.name != 'Joe')" #expression to be evaluated
    25        connectionBackoff:
    26          duration: 10s
    27          steps: 5
    28          factor: 2
    29          jitter: 0.2
    30  ```
    31  
    32  The `expression` string is evaluated with the [expr](https://github.com/antonmedv/expr) package which offers a wide set of basic operators and comparators.
    33  
    34  # Example
    35  
    36  1. Creating a Kafka EventSource with filter field present
    37  
    38  ```
    39  kubectl apply -f examples/event-sources/kafka.yaml -n argo-events
    40  ```
    41  
    42  2. Sending an event with passing filter conditions to kafka
    43  
    44  ```
    45  echo '{"id": 4,"name": "John", "email": "john@intuit.com", "department":{"id": 1,"name": "HR","bu":{"id": 2,"name" : "devp"}}}' | kcat -b localhost:9092 -P -t topic-2
    46  ```
    47  
    48  3. Sending an event with failing filter conditions
    49  
    50  ```
    51  echo '{"id": 2,"name": "Johnson", "email": "john@intuit.com", "department":{"id": 1,"name": "HR","bu":{"id": 2,"name" : "devp"}}}' | kcat -b localhost:9092 -P -t topic-2
    52  ```
    53  
    54  # Output
    55  
    56  Successful logs from kafka event source pod:
    57  
    58  ```
    59  {"level":"info","ts":1644017495.0711913,"logger":"argo-events.eventsource","caller":"kafka/start.go:217","msg":"dispatching event on the data channel...","eventSourceName":"kafka","eventSourceType":"kafka","eventName":"example","partition-id":"0"}
    60  {"level":"info","ts":1644017495.1374986,"logger":"argo-events.eventsource","caller":"eventsources/eventing.go:514","msg":"succeeded to publish an event","eventSourceName":"kafka","eventName":"example","eventSourceType":"kafka","eventID":"kafka:example:kafka-broker:9092:topic-2:0:7"}
    61  ```