Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Enhance the filters tutorial for #1097 #1130

Merged
merged 3 commits into from
Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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