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

Advanced Trigger Filtering Design Proposal #1047

Merged
merged 21 commits into from
May 7, 2019

Conversation

grantr
Copy link
Contributor

@grantr grantr commented Apr 11, 2019

Rendered

This document proposes a design for advanced trigger filtering to complete #930.

/cc @bbrowning @Harwayne since I believe you've expressed interest in this topic.

/kind proposal

@knative-prow-robot knative-prow-robot added kind/proposal Issues or PRs related to proposals. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 11, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Apr 11, 2019
@grantr
Copy link
Contributor Author

grantr commented Apr 11, 2019

/approve cancel

Removing my approval to ensure another approver signs off.

@knative-prow-robot knative-prow-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 11, 2019
docs/broker/filtering.md Outdated Show resolved Hide resolved
docs/broker/filtering.md Outdated Show resolved Hide resolved
docs/broker/filtering.md Outdated Show resolved Hide resolved
docs/broker/filtering.md Show resolved Hide resolved
docs/broker/filtering.md Outdated Show resolved Hide resolved
docs/broker/filtering.md Outdated Show resolved Hide resolved
docs/broker/filtering.md Outdated Show resolved Hide resolved
docs/broker/filtering.md Outdated Show resolved Hide resolved
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no Indicates the PR's author has not signed the CLA. and removed cla: yes Indicates the PR's author has signed the CLA. labels Apr 12, 2019
@devguyio
Copy link
Contributor

devguyio commented Apr 12, 2019

@grantr can you please rebase? web based commit used wrong email that has no CLA.

(From Ahmed)
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Indicates the PR's author has signed the CLA. and removed cla: no Indicates the PR's author has not signed the CLA. labels Apr 12, 2019
@grantr
Copy link
Contributor Author

grantr commented Apr 30, 2019

I've made a few changes to the proposal. Feedback encouraged!

Removed the parseExtensions field. Extensions are always parsed by the SDK, so setting this to false would not actually have an efficiency benefit. The default of false was likely to confuse new users.

Removed the parseData field. The filtering implementation can choose to parse event data only if the data field is used in the expression. This is made possible by CEL's expression parsing and inspection features.

Brought the expression string field up one level. Expressions have one less level of nesting and no longer allow sibling fields.

spec:
  filter:
    expression: ce.type == "com.github.pull.create"

If the need to specify sibling fields returns, we can add a parameterizedExpression filter that allows for them in advanced cases:

### This example is totally made up ###
spec:
  filter:
    parameterizedExpression:
      expression: data.foo.bar == "baz"
      schemaRegistry: "https://example.com/schemas"

Added an attributes map to replace SourceAndType. This can be used to filter any context attribute, including CloudEvents extensions. SourceAndType will be deprecated.

spec:
  filter:
    attributes:
      type: com.github.issue.create
      repository: proposals

Clarified that only one top-level filter is allowed. This eliminates implicit composition semantics which could mislead the user about the filter's output. Top-level composition filters could be added later if we want to enable that functionality:

### This example is for illustration only and is not actually being proposed ###
spec:
  filter:
    and:
    - attributes:
        type: com.github.pull.create
    - expression: ce.source.match("knative")

Thanks everyone for all your feedback so far! Keep it coming. 😄

/milestone v0.6

@knative-prow-robot
Copy link
Contributor

@grantr: The provided milestone is not valid for this repository. Milestones in this repository: [v0.6.0]

Use /milestone clear to clear the milestone.

In response to this:

I've made a few changes to the proposal. Feedback encouraged!

Removed the parseExtensions field. Extensions are always parsed by the SDK, so setting this to false would not actually have an efficiency benefit. The default of false was likely to confuse new users.

Removed the parseData field. The filtering implementation can choose to parse event data only if the data field is used in the expression. This is made possible by CEL's expression parsing and inspection features.

Brought the expression string field up one level. Expressions have one less level of nesting and no longer allow sibling fields.

spec:
 filter:
   expression: ce.type == "com.github.pull.create"

If the need to specify sibling fields returns, we can add a parameterizedExpression filter that allows for them in advanced cases:

### This example is totally made up ###
spec:
 filter:
   parameterizedExpression:
     expression: data.foo.bar == "baz"
     schemaRegistry: "https://example.com/schemas"

Added an attributes map to replace SourceAndType. This can be used to filter any context attribute, including CloudEvents extensions. SourceAndType will be deprecated.

spec:
 filter:
   attributes:
     type: com.github.issue.create
     repository: proposals

Clarified that only one top-level filter is allowed. This eliminates implicit composition semantics which could mislead the user about the filter's output. Top-level composition filters could be added later if we want to enable that functionality:

### This example is for illustration only and is not actually being proposed ###
spec:
 filter:
   and:
   - attributes:
       type: com.github.pull.create
   - expression: ce.source.match("knative")

Thanks everyone for all your feedback so far! Keep it coming. 😄

/milestone v0.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@grantr
Copy link
Contributor Author

grantr commented Apr 30, 2019

/milestone v0.6.0

@knative-prow-robot knative-prow-robot added this to the v0.6.0 milestone Apr 30, 2019
@grantr
Copy link
Contributor Author

grantr commented May 1, 2019

user.id == "abc123"
```

### Exact match on data number field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Header says Exact match, but the example on L372 is a comparison. Given the L362 note, consider changing this to:
data.latency = 300.0

Though, are there rounding errors, or things like that to worry about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll fix that.

In CEL numbers are 64 bit integers or doubles. I guess if you're doing arithmetic in the expression you might have to worry about rounding, but doesn't seem relevant if you're just comparing values.

@vaikas
Copy link
Contributor

vaikas commented May 2, 2019

/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vaikas-google

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 2, 2019
grantr added 2 commits May 2, 2019 12:27
Add open questions related to evaluation errors.
[upstream propagation solution](https://github.com/knative/eventing/issues/934)
for delivery efficiency at scale.

Filters should be easy for the user to specify and simple to interpret at a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filters should be easy for the user to specify and simple to interpret at a glance.

lol, said regex, never... 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With great power comes great responsibility

- expression: ce.source.match("knative")
```

## Alternatives Considered
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see the alternative of just a function. Did you consider implementing a service service wrapper that implements CEL parser and then use that as a ref in the filter spec? It would use the same mechanize as the subscriptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, use this entire proposal but make a new trigger type?

TriggerCEL -makes-> a serving.service + a trigger with a function ref. And then promote the CEL syntax up to to the spec level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a useful addition to this section, but I'm a little unclear what UI is being proposed. Can you give an example of the API? Can you briefly describe the benefits and disadvantages from the user's perspective?

@mikehelmick
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 7, 2019
@knative-prow-robot knative-prow-robot merged commit c0d555a into knative:master May 7, 2019
@grantr grantr deleted the filtering-proposal branch May 7, 2019 21:46
chizhg pushed a commit to chizhg/eventing that referenced this pull request May 13, 2019
* Add a proposal for advanced filtering

* fix typo in example

* Add caveat about variable prefixes

* pluralize CloudEvents

* fix formatting formatted by formatter

* Improve readability of complex expression example

* CloudEvents fields are called attributes

* Fix table formatting

(From Ahmed)

* Move extensions to the `ce` prefix

This makes extension attributes easier to use and promote to official
attributes. The `ext` prefix has been removed.

* Expand prefix match example

Mention startsWith, match, and matches functions.

* Check expression syntax in the Trigger webhook

* Add versioning caveat

* Reimplement SourceAndType as an expression

* Remove parse flags

Extensions are always parsed anyway by the CloudEvents SDK, so setting
parseExtensions to false has no efficiency benefit. Removing the field
improves the approachability of the filtering interface.

We can detect when parsing the expression whether data fields are used.
This provides a more reliable signal than the parseData flag, so the
flag is unnecessary.

* Simplify syntax and add attributes filter

The `cel` level of the expression filter is removed and `expression` is
moved up to its place.

An `attributes` filter is added to replace `sourceAndType` (now
deprecated).

Filter combination at the top level is explicitly disallowed.

Examples have been added to clarify some unusual cases.

* Note that CloudEvents is vague and in flux

CloudEvents is still figuring out whether it wants to support numeric
values in extensions. Note that there will probably be dragons for a
while.

* Clarify structured filters alternative

This "alternative considered" is about using structured filters
exclusively, without an expression language. Be clear that structured
filters are fine as long as they compile down to an expression.

* Explain choice of exclusive top-level filter

* Add filter spec alternatives considered

* Correct inequality example

* Add open questions section

Add open questions related to evaluation errors.
@grantr
Copy link
Contributor Author

grantr commented May 13, 2019

We had some late feedback from teams inside Google suggesting that this proposal might be difficult to implement efficiently at high-scale (for Google and other event providers). I'm recommending that the implementation of this feature be delayed so we can take more time to validate its feasibility for implementers.

@grantr
Copy link
Contributor Author

grantr commented May 13, 2019

Also, the voting process indicated disagreement about inclusion of the attributes filter, with approve, neutral, and disapprove votes. I think this requires further usability review and thus should not be included in the 0.6 API.

grantr added a commit to grantr/eventing that referenced this pull request May 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. kind/proposal Issues or PRs related to proposals. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet