Skip to content

Add support for cloudevent function signatures #29

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 16 commits into from
Jun 22, 2020

Conversation

roffjulie
Copy link
Contributor

Fixes #27

@roffjulie roffjulie requested review from tbpg and grant June 3, 2020 17:46
log.Fatalf("failed to create protocol: %s", err.Error())
}

handleFn, err := cloudevents.NewHTTPReceiveHandler(context.Background(), p, fn)
Copy link

Choose a reason for hiding this comment

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

What is this context used for? Should we pass it as an argument?

Copy link
Contributor Author

@roffjulie roffjulie Jun 3, 2020

Choose a reason for hiding this comment

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

Possibly cancellation? I'm not positive. Adding it would make the function signature func(context.Context, cloudevents.Event). Is that acceptable? @grant

Copy link

Choose a reason for hiding this comment

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

I think if this is something expected by cloudevents, we should pass it through. It would probably come from r.Context() at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@grant do you have an opinion on the function signature? I'm inclined to agree with Tyler, despite the departure from the contract (particularly given that the .NET framework has as similar departure, with additional parameters that are language-idiomatic).

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where?

Copy link

Choose a reason for hiding this comment

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

it is used for shutdown and lifecycle management of the process.

Copy link

Choose a reason for hiding this comment

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

we also use it to pass in options to overload special things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what ctx you're referring to here, Tyler, but if you're referring to why use context.Background(), it's because there is not any other context to use at this point in the code.

Copy link

Choose a reason for hiding this comment

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

It feels like we should plumb a context.Context through as an argument from the user instead of using context.Background().

(Weird -- this was still a pending comment from a couple days ago, even through other comments went through. Sorry!)

Copy link

@tbpg tbpg left a comment

Choose a reason for hiding this comment

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

(Marking as request changes.)

@roffjulie roffjulie requested a review from tbpg June 8, 2020 14:28
Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

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

Marking as request changes per comments above.

@roffjulie roffjulie requested a review from grant June 8, 2020 15:25
Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

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

1 nit. LGTM after that.

@majelbstoat
Copy link

FWIW, I'm not sure this will support cloud events as sent by gcp pubsub push, which doesn't send cloudevents data as headers, but as Attributes in the payload.

see cloudevents/sdk-go#306 (comment) for an example of what pubsub sends, and a later comment for how i'm currently working around it. You might reasonably call that an upstream issue within cloudevents/sdk-go, (or perhaps this will work and i just haven't grokked it) but i thought i'd mention it as i would consider GCP pubsub a primary use-case of this support.

@grant
Copy link
Contributor

grant commented Jun 9, 2020

Are you using Cloud Functions @majelbstoat? Or Cloud Run? Or how exactly are you receiving Pub/Sub push? (Create an issue rather than PR comment?)

This PR is tangential to non CloudEvent payloads.

@majelbstoat
Copy link

majelbstoat commented Jun 9, 2020

I did open an issue, you closed it today ;) #26

This was using google cloud functions, but i also tried with cloud run. If you use the standard cloudevents sdk and the pubsub protocol, and then create a push subscription (which is what gcp documentation says to do for cloud functions/cloud run) you will get data back from pubsub in the format i described above.

(Might just be a mismatch of expectations, but if i emit cloudevents from the standard sdk, and i'm using a library to receive that says it unmarshals cloudevents, i expect to be able to receive structured cloud events, regardless of the transport. it feels like kind of the point of cloudevents. and especially as it's all GCP services.)

@grant
Copy link
Contributor

grant commented Jun 9, 2020

I'd rather talk in an issue than a tangential PR comment.

Issue around supporting CEs (#26) was a duplicate of #27 which talks about supporting CEs more.

No public GCP product delivers CEs right now. I can check what samples might be wrong in a GitHub issue.

You can sign up for an alpha of delivering CEs from Pub/Sub to Run here:
https://forms.gle/ZhQoHYXo7ZFLWTRV6

@roffjulie
Copy link
Contributor Author

ping @tbpg

log.Fatalf("failed to create protocol: %s", err.Error())
}

handleFn, err := cloudevents.NewHTTPReceiveHandler(context.Background(), p, fn)
Copy link

Choose a reason for hiding this comment

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

Use ctx here?

@@ -29,6 +29,7 @@ import (
"strings"

"cloud.google.com/go/functions/metadata"
cloudevents "github.com/cloudevents/sdk-go/v2"
Copy link

Choose a reason for hiding this comment

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

:party-scott:

return nil
}

func registerCloudEventFunction(path string, fn func(context.Context, cloudevents.Event), h *http.ServeMux) error {
Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is loosely modeled on that sample, yes. Is that a problem?

@roffjulie roffjulie requested a review from tbpg June 10, 2020 20:11
@grant
Copy link
Contributor

grant commented Jun 18, 2020

@tbpg Ping for review

Co-authored-by: Tyler Bui-Palsulich <[email protected]>
@grant
Copy link
Contributor

grant commented Jun 22, 2020

We're approved @juliehockett. Let's merge.

@michaelneale
Copy link

since this was merged yesterday, pubsub functions on google functions with vendoring is failing: https://issuetracker.google.com/issues/159732630 could this be related?

roffjulie pushed a commit to roffjulie/functions-framework-go that referenced this pull request Jun 24, 2020
…ures (GoogleCloudPlatform#29)"

This reverts commit 1989552.

The functions framework buildpack has a bug where it pulls from master
(instead of from the latest pinned release) for vendored builds, and as
this change is breaking, it prevents deployment.

Fixes GoogleCloudPlatform#30, https://b.corp.google.com/issues/159732630
roffjulie added a commit that referenced this pull request Jun 24, 2020
…ures (#29)" (#32)

This reverts commit 1989552.

The functions framework buildpack has a bug where it pulls from master
(instead of from the latest pinned release) for vendored builds, and as
this change is breaking, it prevents deployment.

Fixes #30, https://b.corp.google.com/issues/159732630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Signature Type: CloudEvent
6 participants