-
Notifications
You must be signed in to change notification settings - Fork 63
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
Conversation
funcframework/framework.go
Outdated
log.Fatalf("failed to create protocol: %s", err.Error()) | ||
} | ||
|
||
handleFn, err := cloudevents.NewHTTPReceiveHandler(context.Background(), p, fn) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this makes sense (ctx, ce).
Example function:
https://knative.dev/docs/eventing/samples/helloworld/helloworld-go/#recreating-the-sample-code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!)
There was a problem hiding this 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.)
There was a problem hiding this 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.
There was a problem hiding this 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.
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. |
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. |
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.) |
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: |
ping @tbpg |
funcframework/framework.go
Outdated
log.Fatalf("failed to create protocol: %s", err.Error()) | ||
} | ||
|
||
handleFn, err := cloudevents.NewHTTPReceiveHandler(context.Background(), p, fn) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:party-scott:
funcframework/framework.go
Outdated
return nil | ||
} | ||
|
||
func registerCloudEventFunction(path string, fn func(context.Context, cloudevents.Event), h *http.ServeMux) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is coming from the sample: https://github.com/cloudevents/sdk-go/blob/master/samples/http/receiver-direct/main.go
There was a problem hiding this comment.
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?
@tbpg Ping for review |
Co-authored-by: Tyler Bui-Palsulich <[email protected]>
We're approved @juliehockett. Let's merge. |
since this was merged yesterday, pubsub functions on google functions with vendoring is failing: https://issuetracker.google.com/issues/159732630 could this be related? |
…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
…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
Fixes #27