Skip to content

Filtering fix for consistency in handling empty string as value#5273

Merged
knative-prow-robot merged 5 commits into
knative:mainfrom
Shashankft9:filter-fix
Apr 19, 2021
Merged

Filtering fix for consistency in handling empty string as value#5273
knative-prow-robot merged 5 commits into
knative:mainfrom
Shashankft9:filter-fix

Conversation

@Shashankft9
Copy link
Copy Markdown
Contributor

@Shashankft9 Shashankft9 commented Apr 19, 2021

Fixes #4847

Proposed Changes

  • setting dataschema - an optional attribute in v1.0 CE spec
  • added check if empty string value is used in filter for optional attributes and extensions.
  • added specific test cases for extensions and optional attribute - subject. Let me know if its better without some of them, I'll remove.

Release Note


Docs

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 19, 2021
@google-cla google-cla Bot added the cla: yes Indicates the PR's author has signed the CLA. label Apr 19, 2021
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 19, 2021
@knative-prow-robot
Copy link
Copy Markdown
Contributor

Hi @Shashankft9. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@Shashankft9 Shashankft9 changed the title Filter fix Filtering fix for consistency in handling empty string as value Apr 19, 2021
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2021

Codecov Report

Merging #5273 (9838781) into main (97c0d30) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5273      +/-   ##
==========================================
+ Coverage   83.34%   83.39%   +0.04%     
==========================================
  Files         243      243              
  Lines        6882     6883       +1     
==========================================
+ Hits         5736     5740       +4     
+ Misses        797      795       -2     
+ Partials      349      348       -1     
Impacted Files Coverage Δ
pkg/eventfilter/attributes/filter.go 100.00% <100.00%> (+13.63%) ⬆️

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 97c0d30...9838781. Read the comment docs.

@Shashankft9
Copy link
Copy Markdown
Contributor Author

/assign @zhongduo

@zhongduo
Copy link
Copy Markdown
Contributor

@pierDipi might have more context and opinion on this.

@zhongduo
Copy link
Copy Markdown
Contributor

/assign @pierDipi

@pierDipi
Copy link
Copy Markdown
Member

pierDipi commented Apr 19, 2021

I'm gonna take a look at this soon! Thanks!

/cc

"dataschema": event.DataSchema(),
"schemaurl": event.DataSchema(),
"datacontenttype": event.DataContentType(),
"datamediatype": event.DataMediaType(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

datamediatype is not a real attribute.

@@ -59,8 +60,10 @@ func (attrs attributesFilter) Filter(ctx context.Context, event cloudevents.Even
for k, v := range attrs {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This entire method should be rewritten to me more performant. No need to explode the event for filters that do not care about most of the attributes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(this comment was not about this PR, but the code in general. I used it to make a new issue)

// If the attribute does not exist in the event (extension context attributes) or if the event attribute
// has an empty string value (optional attributes) - which means it was never set in the incoming event,
// return false.
if !ok || (v == eventingv1.TriggerAnyFilter && value == "") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks correct.

event: makeEventWithExtension(extensionName, extensionValue),
want: eventfilter.PassFilter,
},
"Any Extension with attribs - without Extension in Event": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the tests 👍

@n3wscott
Copy link
Copy Markdown
Contributor

/ok-to-test

Looks good to me!
/lgtm
/approve

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. lgtm Indicates that a PR is ready to be merged. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 19, 2021
@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: n3wscott

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

The pull request process is described here

Details 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 Apr 19, 2021
@knative-metrics-robot
Copy link
Copy Markdown

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

File Old Coverage New Coverage Delta
pkg/eventfilter/attributes/filter.go 86.7% 100.0% 13.3

@knative-prow-robot knative-prow-robot merged commit 0452204 into knative:main Apr 19, 2021
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. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consistently handle filters with empty string as value on optional attributes and extensions

6 participants