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

Implement new trigger filters experimental feature (SubscriptionsAPI Filters) #1922

Merged
merged 11 commits into from
Mar 10, 2022

Conversation

devguyio
Copy link
Contributor

@devguyio devguyio commented Feb 17, 2022

Implementation of the new filters experimental feature

Based on #1921 , #1977 & #1978

Fixes #1763

Proposed Changes

  • Implement SubscriptionsAPI Filters / aka new trigger filters experimental feature.

TODO

  • Contract tests

Release Note

- 🎁 Add new `new-trigger-filters` experimental feature. When enabled, Triggers support a new `filters` field that conforms to the filters API field defined in the [`CloudEvents Subscriptions API`](https://github.com/cloudevents/spec/blob/main/subscriptions/spec.md#324-filters). It allows you to specify a set of powerful filter expressions, where each expression evaluates to either true or false for each event.

@devguyio devguyio requested a review from matzew February 17, 2022 02:56
@knative-prow-robot knative-prow-robot added area/data-plane area/test approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 17, 2022
@devguyio
Copy link
Contributor Author

@matzew @aliok @pierDipi you can follow the commits flow for reviewing.

@codecov
Copy link

codecov bot commented Feb 17, 2022

Codecov Report

Merging #1922 (d78f278) into main (4d8f68b) will increase coverage by 0.24%.
The diff coverage is 78.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1922      +/-   ##
============================================
+ Coverage     66.98%   67.23%   +0.24%     
- Complexity      630      632       +2     
============================================
  Files           140      141       +1     
  Lines          6567     6687     +120     
  Branches        179      180       +1     
============================================
+ Hits           4399     4496      +97     
- Misses         1800     1823      +23     
  Partials        368      368              
Flag Coverage Δ
java-unittests 81.97% <78.12%> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
control-plane/pkg/contract/contract.pb.go 8.66% <20.00%> (+0.06%) ⬆️
.../core/reconciler/impl/ResourcesReconcilerImpl.java 90.20% <50.00%> (+0.06%) ⬆️
...r/dispatcher/main/ConsumerVerticleFactoryImpl.java 77.27% <60.00%> (-10.66%) ⬇️
control-plane/pkg/contract/subscriptionsapi.go 77.94% <77.94%> (ø)
control-plane/pkg/reconciler/trigger/controller.go 85.00% <83.33%> (-0.30%) ⬇️
control-plane/pkg/reconciler/trigger/trigger.go 73.41% <100.00%> (+1.60%) ⬆️
...roker/dispatcher/impl/filter/AttributesFilter.java 90.00% <100.00%> (+4.81%) ⬆️
...atcher/impl/filter/subscriptionsapi/AllFilter.java 100.00% <100.00%> (ø)
...atcher/impl/filter/subscriptionsapi/AnyFilter.java 100.00% <100.00%> (ø)
...cher/impl/filter/subscriptionsapi/CeSqlFilter.java 100.00% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d8f68b...d78f278. Read the comment docs.

@aliok
Copy link
Member

aliok commented Feb 17, 2022

/rebase

@matzew
Copy link
Contributor

matzew commented Feb 17, 2022

/rebase

does that really work ? 😂

@matzew
Copy link
Contributor

matzew commented Feb 17, 2022

I think, as said on the other PR this looks good

I had only a nit, do to import/format changes.

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 17, 2022
@matzew
Copy link
Contributor

matzew commented Feb 22, 2022

LGTM, as already stated on the other PR.

// https://github.com/cloudevents/spec/blob/main/subscriptions/spec.md#any-filter-dialect
func NewAnyFilter(filters []v1.SubscriptionsAPIFilter) *DialectedFilter {
any := Any{
Filters: []*DialectedFilter{},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Filters: []*DialectedFilter{},
Filters: make(DialectedFilter, 0, len(filters)),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

// https://github.com/cloudevents/spec/blob/main/subscriptions/spec.md#all-filter-dialect
func NewAllFilter(filters []v1.SubscriptionsAPIFilter) *DialectedFilter {
all := All{
Filters: []*DialectedFilter{},
Copy link
Member

Choose a reason for hiding this comment

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

We can pre-allocate this array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 21 to 74
// NewExactFilter converts the SubscriptionsAPIFilter into the exact dialect of
// the DialectedFilter as defined in CloudEvents Subscriptions API.
//
// Exact contains exactly one attribute where the key is the name of the CloudEvent
// attribute and its value is the string value which must exactly match the value
// of the CloudEvent attribute.
//
// See "CNCF CloudEvents Subscriptions API" > "3.2.4.1 Filters Dialects"
// https://github.com/cloudevents/spec/blob/main/subscriptions/spec.md#all-filter-dialect
func NewExactFilter(f v1.SubscriptionsAPIFilter) *DialectedFilter {
return &DialectedFilter{
Filter: &DialectedFilter_Exact{
Exact: &Exact{
Attributes: f.Exact,
},
},
}
}

// NewPrefixFilter converts the SubscriptionsAPIFilter into the suffix dialect of
// the DialectedFilter as defined in CloudEvents Subscriptions API.
//
// Prefix contains exactly one attribute where the key is the name of the CloudEvent
// attribute which value must start with the value specified.
//
// See "CNCF CloudEvents Subscriptions API" > "3.2.4.1 Filters Dialects"
// https://github.com/cloudevents/spec/blob/main/subscriptions/spec.md#prefix-filter-dialect
func NewPrefixFilter(f v1.SubscriptionsAPIFilter) *DialectedFilter {

p := &Prefix{}
// Eventing Trigger API is conforming to the Subscriptions API, so this map has only a single
// key-value pair
for k, v := range f.Prefix {
p.Attribute = k
p.Prefix = v
// We only expect a single element, but let's break anyway
break
}

return &DialectedFilter{
Filter: &DialectedFilter_Prefix{
Prefix: p,
},
}
}

// NewSuffixFilter converts the SubscriptionsAPIFilter into the suffix dialect of
// the DialectedFilter as defined in CloudEvents Subscriptions API.
//
// Suffix contains exactly one attribute where the key is the name of the CloudEvent
// attribute which value must end with the value specified.
//
// See "CNCF CloudEvents Subscriptions API" > "3.2.4.1 Filters Dialects"
// https://github.com/cloudevents/spec/blob/main/subscriptions/spec.md#suffix-filter-dialect
func NewSuffixFilter(f v1.SubscriptionsAPIFilter) *DialectedFilter {

p := &Suffix{}
// Eventing Trigger API is conforming to the Subscriptions API, so this map has only a single
// key-value pair
for k, v := range f.Suffix {
p.Attribute = k
p.Suffix = v
// We only expect a single element, but let's break anyway
break
}

return &DialectedFilter{
Filter: &DialectedFilter_Suffix{
Suffix: p,
},
}
}
Copy link
Member

Choose a reason for hiding this comment

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

As the other comment on the PR, there shouldn't be a difference between these 3 filters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 178 to 195
func FromSubscriptionFilter(f v1.SubscriptionsAPIFilter) *DialectedFilter {
switch {
case len(f.All) > 0:
return NewAllFilter(f.All)
case len(f.Any) > 0:
return NewAnyFilter(f.Any)
case f.Not != nil:
return NewNotFilter(*f.Not)
case f.Exact != nil:
return NewExactFilter(f)
case f.Prefix != nil:
return NewPrefixFilter(f)
case f.Suffix != nil:
return NewSuffixFilter(f)
case f.SQL != "":
return NewCESQLFilter(f)
}
return &DialectedFilter{}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we decouple the one filter constraint from the contract?
I remember making this comment in another PR 🤔

Copy link
Member

Choose a reason for hiding this comment

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

In addition, the CE subscription spec doesn't have this constraint, so I would really avoid designing a contract in this way

Copy link
Contributor Author

@devguyio devguyio Feb 22, 2022

Choose a reason for hiding this comment

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

Can we decouple the one filter constraint from the contract? I remember making this comment in another PR thinking

Yes I'm working on it.

In addition, the CE subscription spec doesn't have this constraint

Yeah while it's not in the spec itself, it's in the reference openapi file and I remember that it was brought up in one of the PRs introducing the spec. But I agree that we shouldn't have it tightly coupled here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@devguyio devguyio changed the title Implement new trigger filters experimental feature (SubscriptionsAPI Filters) [WIP] Implement new trigger filters experimental feature (SubscriptionsAPI Filters) Feb 22, 2022
@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 9, 2022
@devguyio
Copy link
Contributor Author

devguyio commented Mar 9, 2022

/unhold

@knative-prow-robot knative-prow-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 9, 2022
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
@knative-prow-robot knative-prow-robot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 9, 2022
Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-sandbox-eventing-kafka-broker-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
control-plane/pkg/contract/subscriptionsapi.go Do not exist 81.2%
control-plane/pkg/reconciler/trigger/controller.go 76.9% 79.6% 2.7
control-plane/pkg/reconciler/trigger/trigger.go 84.7% 85.8% 1.1

@devguyio
Copy link
Contributor Author

devguyio commented Mar 9, 2022

Seems like the webhook was unavailable

    broker_trigger_sink_test.go:77: 
        	Error Trace:	broker_trigger_sink_test.go:77
        	Error:      	Expected nil, but got: &errors.StatusError{ErrStatus:v1.Status{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ListMeta:v1.ListMeta{SelfLink:"", ResourceVersion:"", Continue:"", RemainingItemCount:(*int64)(nil)}, Status:"Failure", Message:"Internal error occurred: failed calling webhook \"validation.webhook.kafka.eventing.knative.dev\": failed to call webhook: Post \"https://kafka-webhook-eventing.knative-eventing.svc:443/resource-validation?timeout=2s\": EOF", Reason:"InternalError", Details:(*v1.StatusDetails)(0xc007792c00), Code:500}}
        	Test:       	TestBrokerV1TriggersV1SinkV1Alpha1/5

/retest

Copy link
Member

@aliok aliok left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2022
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aliok, devguyio, pierDipi

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:
  • OWNERS [aliok,devguyio,pierDipi]

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 merged commit efa696c into knative-extensions:main Mar 10, 2022
@devguyio devguyio deleted the new-filters branch March 10, 2022 09:28
@devguyio
Copy link
Contributor Author

/cherry-pick release-1.3

@knative-prow-robot
Copy link
Contributor

@devguyio: new pull request created: #2008

In response to this:

/cherry-pick release-1.3

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.

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. area/control-plane area/data-plane area/test lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the new trigger filters experimental feature
6 participants