Skip to content

feat: handle CloudEvent and Message responses from function invocation #68

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

Merged
merged 2 commits into from
Oct 30, 2020

Conversation

lance
Copy link
Member

@lance lance commented Oct 29, 2020

We already kind of handled them, but these changes make it more intuitive
for the user. For example, the function author can respond with new CloudEvent(...)
or HTTP.binary(event) and the framework should handle the response correctly.

This partially fixes https://github.com/boson-project/functions/issues/15

Signed-off-by: Lance Ball [email protected]

@lance lance added the enhancement New feature or request label Oct 29, 2020
@lance lance requested a review from a team October 29, 2020 22:32
@lance lance self-assigned this Oct 29, 2020
We already **kind of** handled them, but these changes make it more intuitive
for the user. For example, the function author can respond with `new CloudEvent(...)`
or `HTTP.binary(event)` and the framework should handle the response correctly.

Signed-off-by: Lance Ball <[email protected]>
@lance lance force-pushed the handle-cloud-event-returns branch from 81d47c1 to ff02d8a Compare October 30, 2020 14:59
@@ -7,10 +8,10 @@ module.exports = function invoker(func) {
code: 200,
response: undefined,
headers: {
'Content-Type': 'application/json; charset=utf8',
'Access-Control-Allow-Methods':
'content-type': 'application/json; charset=utf8',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change, shouldn't it be case insensitive?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right - it should be, and it is here where we merge user headers with event headers https://github.com/boson-project/faas-js-runtime/pull/68/files#diff-89ae878b1a78765add577244271796f156213cdd0ab6722f641ef96926f38674R54.

That change to lowercase is kind of immaterial since we do lowercase all headers later. It was left over from some debugging I was doing when I realized that I was not doing case-insensitive comparisons. But I thought it would be fine to keep. 🤷

@@ -226,25 +282,6 @@ test('Successfully handles events with no data', t => {
});
});

test('Responds with error code (4xx or 5xx) to malformed cloud events', t => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why deleting this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I probably should have mentioned that in the description. I don't think we should fail if we can help it. If we can recover by creating a CE that is correct, in spite of the malformation, then I think we should do that.

Copy link
Member Author

@lance lance Oct 30, 2020

Choose a reason for hiding this comment

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

@matejvasek I will elaborate a little more here. The rationale behind this change is rooted in changes that were made in the upstream cloudevents module and which recently landed in v3.2.0. That version bump of the module introduced the HTTP.binary() API method (and others) that I have made use of in this PR.

But a bigger thing that it did was change how the receiver handles malformed events. A summary of the wider community discussion on why receiving a CloudEvent should provide loose validation is in this comment.

Because of this change in the upstream validation behavior, an exception is never thrown on our end when receiving an event. In cloudevents 3.1.x it would have been and was, and was why this test worked. However, in order to maintain the existing behavior in this module, I would need to add a call to event.validate() when receiving them. To me that seems to land more in the user/customer domain. I thought a lot about this while making the upstream changes, and it's been pretty well hashed out in the community. So I think this module should follow the behavior upstream.

@lance lance merged commit 351197f into nodeshift:master Oct 30, 2020
@lance lance deleted the handle-cloud-event-returns branch October 30, 2020 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants