Skip to content

Add Cloud Events support for #55 - #56

Merged
grant merged 50 commits into
GoogleCloudPlatform:2.0.0-devfrom
joelgerard:master
Jun 19, 2020
Merged

grant merged 50 commits into
GoogleCloudPlatform:2.0.0-devfrom
joelgerard:master

Conversation

@joelgerard

@joelgerard joelgerard commented Jun 10, 2020 •

Copy link
Copy Markdown
Contributor

Adds support for Cloud Events per #55.

Joel Gerard and others added 5 commits June 5, 2020 17:07
…o be run from anywhere and enables IDE debugger
I will squash a bunch of these interim commits before submitting the PR.

DO NOT SUBMIT
…e error handling.

Please see all the TODO questions before I finish off this PR.

DO NOT SUBMIT
@joelgerard
joelgerard requested review from di and grant June 10, 2020 18:45
@grant

grant commented Jun 10, 2020

Copy link
Copy Markdown
Contributor

FYI @cumason123

@grant
grant requested a review from roffjulie June 10, 2020 21:36

@grant grant left a comment •

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.

Thanks for the PR @joelgerard! I like the tests and think this is close to mergeable.
I added a detailed review.

There are a couple scenarios we're in that make it tricky, that we faced. Hope this will give background:

  • The CloudEvents SDK is pretty clunky and not ideal. It looks like we've been able to use it here though.
  • The legacy (event) signature (elif signature_type == "event":) and _event_view_func_wrapper is pretty wrong as GCF legacy events are not CloudEvents and are a separate payload type.
    • I don't think the _is_binary_cloud_event codepath is touched. We should remove all cloudevent parsing logic from the event signature.

Comment thread tests/test_functions/events/main.py Resolved
Comment thread tests/test_functions/events/main.py Resolved
Comment thread tests/test_functions/events/main.py Resolved
Comment thread tests/test_functions.py Resolved
Comment thread tests/test_functions.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved

@roffjulie roffjulie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a good starting point, but it misses one of the key points of the CloudEvent proposal, which is that the function signature containing a CloudEvent has a different signature type.

In brief, there are three types of function signatures: http, which is the function that handles an HTTP request directly, event, which is the function that accepts legacy events parsed by the framework into (data, context) parameters, and cloudevent, which is the function that accepts CloudEvents parsed by the framework into an event as defined by the CloudEvents SDK. See the framework contract (https://github.com/GoogleCloudPlatform/functions-framework#supported-function-types) for more depth, but that's the broad summary.

It'd be great if this could be reworked to introduce the cloudevent signature type as a separate type from the existing legacy event type.

Comment thread tests/test_functions/events/main.py Resolved

@di di left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this @joelgerard!

Comment thread .gitignore Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread tests/test_functions.py Resolved
Comment thread tests/test_functions/events/main.py Resolved
Comment thread tests/test_functions/events/main.py Resolved
Comment thread tests/test_functions/events/main.py Resolved
Comment thread tests/test_functions.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread setup.py Resolved
Comment thread tests/test_cloudevent_functions.py Resolved
Comment thread tests/test_cloudevent_functions.py Resolved
Comment thread tests/test_cloudevent_functions.py Resolved
Comment thread tests/test_cloudevent_functions.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread tests/test_view_functions.py Resolved
joelgerard and others added 10 commits June 15, 2020 16:56
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Comment thread src/functions_framework/__init__.py Resolved
Comment thread src/functions_framework/__init__.py Resolved
Comment thread README.md Resolved
Comment thread examples/README.md Resolved
Comment thread examples/cloudevents/README.md Resolved
Comment thread examples/cloudevents/README.md Resolved
Comment thread examples/cloudevents/README.md Resolved
Comment thread examples/cloudevents/main.py Resolved
Comment thread tests/test_view_functions.py Resolved
joelgerard and others added 10 commits June 17, 2020 15:33
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread examples/README.md Resolved
joelgerard and others added 3 commits June 18, 2020 09:15

ghost left a comment

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.

3 non-critical requested changes.

Comment thread examples/README.md Outdated
Comment on lines +6 to +8



ghost Jun 18, 2020

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.

nit: Here and in the main README there >1 blank lines in the file. Remove these extra blank lines.

Comment thread src/functions_framework/__init__.py Outdated
class _EventType(enum.Enum):
LEGACY = 1
CLOUDEVENT_BINARY = 2
CLOUDEVENT_TEXT = 3

ghost Jun 18, 2020

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.

As mentioned before, CloudEvent Text is not an event type.

The logic used here is for a CloudEvent Structured event.
This is the spec: https://github.com/cloudevents/spec/blob/master/http-protocol-binding.md#32-structured-content-mode

CLOUDEVENT_TEXT should be CLOUDEVENT_STRUCTURED.

Comment thread src/functions_framework/__init__.py Outdated
function(event)


def _run_text_cloudevent(function, request, cloudevent_def):

ghost Jun 18, 2020

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.

Should be _run_structured_cloudevent.

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM pending @grant's changes.

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for seeing this through!

@grant

ghost commented Jun 19, 2020

Copy link
Copy Markdown
Contributor

Cool, looks like we're all good/approved. :)

@grant
grant merged commit eddbc7e into GoogleCloudPlatform:2.0.0-dev Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants