Skip to content

GCP Pub/Sub Knative Bus#98

Merged
google-prow-robot merged 2 commits into
knative:masterfrom
scothis:cloud-pubsub-bus
Jun 28, 2018
Merged

GCP Pub/Sub Knative Bus#98
google-prow-robot merged 2 commits into
knative:masterfrom
scothis:cloud-pubsub-bus

Conversation

@scothis
Copy link
Copy Markdown
Contributor

@scothis scothis commented Jun 20, 2018

A Knative Bus implementation backed by GCP Cloud Pub/Sub.

Deployment steps:

  1. Setup Knative Eventing
  2. Create a service account with the 'Pub/Sub Editor' role, and download a new JSON private key.
  3. Create a secret for the downloaded key kubectl create secret generic gcppubsub-bus-key --from-file=key.json=PATH-TO-KEY-FILE.json
  4. Replace $PROJECT_ID in config/buses/gcppubsub.yaml with your GCP Project ID
  5. Apply the 'gcppubsub' Bus ko apply -f config/buses/gcppubsub.yaml
  6. Create Channels that reference the 'gcppubsub' Bus

The bus has an independent provisioner and dispatcher.

The provisioner will create GCP Pub/Sub Topics and Subscriptions for each Knative Channel and Subscription (respectively) targeting the Bus. Clients should avoid interacting with topics and subscriptions provisioned by the Bus.

The dispatcher can receive events via the Channel Ingress from outside the cluster, or the Channel Service from inside the cluster. Events on the Pub/Sub topic for an active subscription are forwarded via HTTP to the subscriber. HTTP responses with a 2xx status code are acknowledge while all other status code will have delivery reattempted.

Note: Cloud Pub/Sub does not guarantee exactly once delivery, subscribers must guard against multiple deliveries of the same event.

To view logs:

  • for the dispatcher kail -d gcppubsub-bus -c dispatcher
  • for the provisioner kail -d gcppubsub-bus-provisioner -c provisioner

Resolves #80

This PR is effectively adds a single commit on top of #88, and will be rebased after it merges.

@google-prow-robot google-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 20, 2018
@scothis scothis mentioned this pull request Jun 21, 2018
@google-prow-robot google-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 25, 2018
@scothis scothis changed the title [DNM] GCP Pub/Sub Knative Bus GCP Pub/Sub Knative Bus Jun 25, 2018
@scothis
Copy link
Copy Markdown
Contributor Author

scothis commented Jun 25, 2018

Rebased on master now that #88 is merged

scothis added 2 commits June 26, 2018 08:25
A Knative Bus implementation backed by GCP Cloud Pub/Sub.

Deployment steps:
1. Setup Knative Eventing
2. [Create a service account](https://console.cloud.google.com/iam-admin/serviceaccounts/project) with the 'Pub/Sub Editor' role, and download a new JSON private key.
3. Create a secret for the downloaded key `kubectl create secret generic gcppubsub-bus-key --from-file=key.json=PATH-TO-KEY-FILE.json`
4. Replace `$PROJECT_ID` in `config/buses/gcppubsub.yaml` with your GCP Project ID
5. Apply the 'gcppubsub' Bus `ko apply -f config/buses/gcppubsub.yaml`
6. Create Channels that reference the 'gcppubsub' Bus

The bus has an independent provisioner and dispatcher.

The provisioner will create GCP Pub/Sub Topics and Subscriptions for each Knative Channel and Subscription (respectively) targeting the Bus. Clients should avoid interacting with topics and subscriptions provisioned by the Bus.

The dispatcher can receive events via the Channel Service from inside the cluster. Events on the Pub/Sub topic for an active subscription are forwarded via HTTP to the subscriber. HTTP responses with a 2xx status code are acknowledge while all other status code will have delivery reattempted.

Note: Cloud Pub/Sub does not guarantee exactly once delivery, subscribers must guard against multiple deliveries of the same event.

To view logs:
- for the dispatcher `kail -d gcppubsub-bus -c dispatcher`
- for the provisioner `kail -d gcppubsub-bus-provisioner -c provisioner`
Comment thread config/buses/gcppubsub.yaml Outdated
@@ -0,0 +1,62 @@
# Copyright 2018 Google, Inc. All rights reserved.
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.

Can you change the headers to match:
#115

topicID := b.topicID(channel)
topic := b.pubsubClient.Topic(topicID)

// check if topic exists before creating
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.

I'm just curious about the pattern of checking for existence before trying these operations and why it's being done in every case. With this check then do something else, there's a race condition anyways, so like I said, just curious about this pattern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The call to create a topic will return an error if the topic already exists. Rather than try to inspect the error I found it easier to check if the topic exists before creating.

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.

Sorry, I meant the pattern in each of these, like delete for example and so forth. Same deal there?

Copy link
Copy Markdown
Contributor Author

@scothis scothis Jun 28, 2018

Choose a reason for hiding this comment

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

Each operation will return an error unless the client was directly responsible for achieving the desired effect. So deleting a topic that doesn't exist will return an error. The published doc doesn't distinguish between different types of errors. There are a few hint in the codebase that NOT_FOUND is distinguished from ALREADY_EXISTS and other errors, but it's not part of the public interface from what I can see.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To your comment about a race condition, the provisioner is a singleton, and the workqueue guarantees that any given resource will never be processed more than once concurrently.

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jun 28, 2018

/lgtm
/approve

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 28, 2018
@google-prow-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Details 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

@google-prow-robot google-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 28, 2018
@google-prow-robot google-prow-robot merged commit ad2cd51 into knative:master Jun 28, 2018
matzew pushed a commit to matzew/eventing that referenced this pull request May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants