Skip to content

Commit

Permalink
docs: Enhance the filters tutorial for #1097 (#1130)
Browse files Browse the repository at this point in the history
* docs: Enhance the filters tutorial for #1097

Signed-off-by: Tim Collins <[email protected]>
  • Loading branch information
tico24 authored and whynowy committed Mar 24, 2021
1 parent 460d5bd commit 5687b59
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions docs/tutorials/07-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Argo Events offers 3 types of filters:
Webhook event-source must be set up.

## Data Filter
Data filter as the name suggests are applied on the event data. A CloudEvent from Webhook event-source has
Data filters as the name suggests are applied on the event data. A CloudEvent from Webhook event-source has
payload structure as,


Expand All @@ -35,7 +35,7 @@ payload structure as,
}
}

Data Filter are applied on `data` within the payload. We will make a simple HTTP request
Data Filters are applied on `data` within the payload. We will make a simple HTTP request
to webhook event-source with request data as `{"message":"this is my first webhook"}` and apply
data filter on `message`.

Expand All @@ -54,13 +54,13 @@ The data filter offers `comparator` “>=”, “>”, “=”, “!=”, “<

e.g.,

filters:
data:
- path: body.value
type: number
comparator: ">"
value:
- "50.0"
filters:
data:
- path: body.value
type: number
comparator: ">"
value:
- "50.0"

<br/>

Expand All @@ -84,6 +84,42 @@ If data types is bool or float, then you need to pass the exact value.

5. Watch for a workflow with name `data-workflow-xxxx`.

### Multiple Paths

If the HTTP request was less simple and contained multiple paths that we would like to filter against,
we can make use of [multipaths](https://github.com/tidwall/gjson/blob/master/SYNTAX.md#multipaths) to combine
multiple data paths in the payload into one string.

For a given payload such as:

{
"body": {
"action":"opened",
"labels": [
{"id":"1234", "name":"Webhook"},
{"id":"5678", "name":"Approved"}
]
}
}

We want our sensor to fire if the action is "opened" and it has a label of "Webhook" or if the action is "closed"
and it has a label of "Webhook" and "Approved". We could therefore define the path as:

filters:
data:
- path: "[body.action,body.labels.#(name=="Webhook").name,body.labels.#(name=="Approved").name]"
type: string
...

This would return a string like: `["opened","Webhook","Approved"]`. As the resulting data type will be a
`string`, we can pass a regex over it:

filters:
data:
- path: "[body.action,body.labels.#(name=="Webhook").name,body.labels.#(name=="Approved").name]"
type: string
value:
- "(\bopened\b.*\bWebhook\b)|(\blabeled\b.*(\bWebhook\b.*\bApproved\b))"
### Template

The data filter offers `template`.
Expand Down

0 comments on commit 5687b59

Please sign in to comment.