googleinterns / knative-source-mongodb

Apache License 2.0
3 stars 2 forks source link

Create Receive Adapter #17

Closed nachocano closed 4 years ago

nachocano commented 4 years ago

Problem The data plane piece of sources is typically called Receive Adapter. This issue is to track the creation the of MongoDB receive adapter. We should try to reuse as much as we can from adapters in core eventing and sample source.

Persona: Contributor

Exit Criteria A receive adapter for the MongoDB source

Additional context (optional) Some examples: https://github.com/knative/eventing-contrib/tree/master/couchdb/source/pkg/adapter https://github.com/knative-sandbox/sample-source/tree/master/pkg/adapter

nachocano commented 4 years ago

If you are using adapter/v2 from your shared main, which I think you do, they are already taking care of the creation of the ceClient, based on the K_SINK environment variable... See here: https://github.com/knative/eventing/blob/1cbaa24b1dc5c17685f788d0ff8a98c911f25219/pkg/adapter/v2/main.go#L161

I think from your main you end up calling that piece of code... Try to navigate a bit in the IDE...

So you can just use it the client, as it should have been created already:

if result := a.Client.Send(ctx, event); !cloudevents.IsACK(result) {
   log some error
}
nachocano commented 4 years ago

You will have to pass the K_SINK environment variable as well with the value of your resolved SINK_URI... See https://github.com/knative/eventing/blob/5632b0975a73d4c9196da928ceb9216654284c67/pkg/reconciler/apiserversource/resources/receive_adapter.go#L129 You will probably have to add a new field to ReceiveAdapterArgs to accept the sinkURI and then we you makeEnv you read it from there.

Also, it would be nice if you can add this CloudEventsOverrides as well: https://github.com/knative/eventing/blob/5632b0975a73d4c9196da928ceb9216654284c67/pkg/reconciler/apiserversource/resources/receive_adapter.go#L154

And if you want something extra, that K_LOGGING_CONFIG, K_TRACING_CONFIG, and K_METRICS_CONFIG we had (maybe we just had a couple of them), we could actually try to set them with these helpers:

https://github.com/knative/eventing/blob/5632b0975a73d4c9196da928ceb9216654284c67/pkg/reconciler/apiserversource/resources/receive_adapter.go#L152

See what that args.Configs is, and where is populated, and try to populate it the same way in your ReceiveAdapterArgs...

^^ @selim5