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

InMemoryChannel receiver validates received events #6511

Merged
merged 2 commits into from
Sep 7, 2022

Conversation

pierDipi
Copy link
Member

@pierDipi pierDipi commented Sep 6, 2022

IMC didn't run validation of the received events.

Signed-off-by: Pierangelo Di Pilato pierdipi@redhat.com

Proposed Changes

  • Validate events received by InMemoryChannels
  • Add conformance test

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • [N/A] Docs PR for any user-facing impact
  • [N/A] Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note

InMemoryChannel receiver validates received events

Docs

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/test-and-release Test infrastructure, tests or release labels Sep 6, 2022
@codecov
Copy link

codecov bot commented Sep 6, 2022

Codecov Report

Merging #6511 (02e4ed5) into main (7f1f49f) will decrease coverage by 0.11%.
The diff coverage is 15.00%.

@@            Coverage Diff             @@
##             main    #6511      +/-   ##
==========================================
- Coverage   82.09%   81.98%   -0.12%     
==========================================
  Files         235      235              
  Lines       11714    11733      +19     
==========================================
+ Hits         9617     9619       +2     
- Misses       1628     1642      +14     
- Partials      469      472       +3     
Impacted Files Coverage Δ
pkg/channel/message_receiver.go 64.22% <15.00%> (-9.82%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines +190 to +211
bufferedMessage, err := buffering.CopyMessage(request.Context(), message)
if err != nil {
r.logger.Warn("Cannot buffer cloudevent message", zap.Error(err))
response.WriteHeader(nethttp.StatusBadRequest)
_ = r.reporter.ReportEventCount(&args, nethttp.StatusBadRequest)
return
}

event, err := binding.ToEvent(request.Context(), bufferedMessage)
if err != nil {
r.logger.Warn("failed to extract event from request", zap.Error(err))
response.WriteHeader(nethttp.StatusBadRequest)
_ = r.reporter.ReportEventCount(&args, nethttp.StatusBadRequest)
return
}

// run validation for the extracted event
if err := event.Validate(); err != nil {
r.logger.Warn("failed to validate extracted event", zap.Error(err))
response.WriteHeader(nethttp.StatusBadRequest)
return
}
Copy link
Member

Choose a reason for hiding this comment

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

could we move this section into a more encapsulated function?

Copy link
Member Author

Choose a reason for hiding this comment

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

what should that function return/do?

Copy link
Member

Choose a reason for hiding this comment

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

The binding, validation?

It's ok to inline and grow the functions, but I sometimes feel our funcs get longer and longer.

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 do in a separate PR, if we want to (of course not a blocker) 😅

@pierDipi pierDipi changed the title [WIP] InMemoryChannel receiver validates received events InMemoryChannel receiver validates received events Sep 7, 2022
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 7, 2022
Copy link
Member

@matzew matzew 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 knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Sep 7, 2022
@knative-prow
Copy link

knative-prow bot commented Sep 7, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: matzew, 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:

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

@matzew
Copy link
Member

matzew commented Sep 7, 2022

/cherry-pick release-1.7

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.7 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.7

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.

@matzew
Copy link
Member

matzew commented Sep 7, 2022

/cherry-pick release-1.6

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.6 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.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.

@matzew
Copy link
Member

matzew commented Sep 7, 2022

/cherry-pick release-1.5

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.5 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.5

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.

@matzew
Copy link
Member

matzew commented Sep 7, 2022

/cherry-pick release-1.4

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.4 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.4

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.

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #6512

In response to this:

/cherry-pick release-1.7

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.

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #6513

In response to this:

/cherry-pick release-1.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.

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #6514

In response to this:

/cherry-pick release-1.5

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.

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #6515

In response to this:

/cherry-pick release-1.4

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.

@pierDipi pierDipi deleted the imc-validate-events branch September 7, 2022 09:42
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/test-and-release Test infrastructure, tests or release lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants