Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Adding transformer field to GCPPubSubSource CRD. #398

Merged
merged 32 commits into from
May 13, 2019

Conversation

nachocano
Copy link
Contributor

@nachocano nachocano commented May 6, 2019

Proposed Changes

  • Adding an optional addressable to GCPPubSubSource CRD called transformer to be able to transform GCP events.

Pending

  • Default transformer.
  • Cleanup "ce-type" logic.

Release Note

GCPPubSubSource includes an optional `transformer` Addressable field that can be configured to do custom CloudEvents transformations.

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 6, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label May 6, 2019
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 6, 2019
@nachocano
Copy link
Contributor Author

/cc @Harwayne @vaikas-google
still WIP but it would be nice if you can start looking at it...

@knative-prow-robot knative-prow-robot requested a review from vaikas May 6, 2019 22:18
nachocano added 2 commits May 6, 2019 22:02
…nto transformer

# Conflicts:
#	contrib/gcppubsub/pkg/adapter/adapter.go
#	contrib/gcppubsub/pkg/reconciler/gcppubsubsource.go
@nachocano nachocano changed the title [WIP] Adding transformer for GCP events. Adding transformer field to GCPPubSubSource CRD. May 7, 2019
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 7, 2019
@nachocano
Copy link
Contributor Author

nachocano commented May 7, 2019

Removed the default transformer for now until we further agree how it should behave.
Just added the transformer addressable field to GCPPubSubSource.

event.SetDataContentType(*cloudevents.StringOfApplicationJSON())
event.SetSource(a.source)
event.SetData(m.Message())

// TODO: this will break when the upstream sender updates cloudevents versions.
// The correct thing to do would be to convert the message to a cloudevent if it is one.
et := sourcesv1alpha1.GcpPubSubSourceEventType
if override, ok := m.Message().Attributes[eventTypeOverrideKey]; ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO we should remove this asap. If a particular source wants to do something like this (e.g., the gcs source), it should actually do it in the transformer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

Copy link
Contributor

@vaikas vaikas left a comment

Choose a reason for hiding this comment

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

Thanks!! Couple of questions/suggestions.

// Update the event with the transformed one.
event = *resp
} else {
logger.Warnf("cloud event %q was not transformed", event.ID())
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this return an error?

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 was leaving it as in case the transformer does not populate properly the response. If so, then we at least send the //google.pubsub.topic.publish event. As we might not control the transformer code, I'm assuming it can be wrong.
Do you prefer to return an error instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea that the transformer can hide events. For example, events that are not on an allowed list or those that do not pass schema validation. I think our 'canonical' filtering of events is to return a 2XX with an empty body.

So I wouldn't return an error here, I would just return nil.

TopicID: env.Topic,
SinkURI: env.Sink,
SubscriptionID: env.Subscription,
TransformerURI: env.Transformer,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we at least validate the URI to make sure it's a valid URI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we are not doing that for the sinkURI. I guess if it's not valid it will break when trying to create the httpClient. And it can be empty right? in that case we do not create any client...

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-sources-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
contrib/gcppubsub/pkg/adapter/adapter.go 60.0% 63.6% 3.6
contrib/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types.go 93.8% 71.4% -22.3
contrib/gcppubsub/pkg/reconciler/gcppubsubsource.go 90.0% 90.6% 0.6

@vaikas
Copy link
Contributor

vaikas commented May 13, 2019

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label May 13, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nachocano, vaikas-google

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 13, 2019
@knative-prow-robot knative-prow-robot merged commit 34b8477 into knative:master May 13, 2019
@@ -64,11 +58,17 @@ func main() {
log.Fatalf("Unable to create logger: %v", err)
}

var env envConfig
if err := envconfig.Process("", &env); err != nil {
log.Fatal("Failed to process env var", zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a sugared logger? If so, it should be Fatalw (my preference is just switch to a desugared logger to make sure these bugs don't occur).

googleCloudProject:
type: string
description: "ID of the Google Cloud Project that the PubSub Topic exists in."
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add an example here, as historically GCP project name vs ID vs display name has been very confusing.

description: "ID of the Google Cloud Project that the PubSub Topic exists in. E.g. 'my-project-1234' rather than its display name, 'My Project' or its number '1234567890'."

serviceAccountName:
type: string
description: "Name of the ServiceAccount that will be used to run the Receive Adapter Deployment."
Copy link
Contributor

Choose a reason for hiding this comment

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

Give an example. Is this the full email address? Just the name before the '@'?

event.SetDataContentType(*cloudevents.StringOfApplicationJSON())
event.SetSource(a.source)
event.SetData(m.Message())

// TODO: this will break when the upstream sender updates cloudevents versions.
// The correct thing to do would be to convert the message to a cloudevent if it is one.
et := sourcesv1alpha1.GcpPubSubSourceEventType
if override, ok := m.Message().Attributes[eventTypeOverrideKey]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

// Update the event with the transformed one.
event = *resp
} else {
logger.Warnf("cloud event %q was not transformed", event.ID())
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea that the transformer can hide events. For example, events that are not on an allowed list or those that do not pass schema validation. I think our 'canonical' filtering of events is to return a 2XX with an empty body.

So I wouldn't return an error here, I would just return nil.

@@ -83,7 +87,7 @@ const (
)

// GetGcpPubSubSource returns the GcpPubSub CloudEvent source value.
Copy link
Contributor

Choose a reason for hiding this comment

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

GetGcpPubSubSource -> GcpPubSubSource

if len(uri) > 0 {
gcpPubSubSourceCondSet.Manage(s).MarkTrue(GcpPubSubConditionTransformerProvided)
} else {
gcpPubSubSourceCondSet.Manage(s).MarkUnknown(GcpPubSubConditionTransformerProvided, "TransformerEmpty", "Transformer has resolved to empty.%s", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the trailing "%s" that has an empty string arg?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants