Skip to content

Kafka Bus Implementation#99

Merged
google-prow-robot merged 12 commits into
knative:masterfrom
ericbottard:issue_83
Jul 10, 2018
Merged

Kafka Bus Implementation#99
google-prow-robot merged 12 commits into
knative:masterfrom
ericbottard:issue_83

Conversation

@ericbottard
Copy link
Copy Markdown
Contributor

@ericbottard ericbottard commented Jun 20, 2018

Fixes Issue #83

Similar to #98, this is effectively #88 with one commit on top.

This introduces an implementation of Bus backed by Kafka.
The bus itself is split between provisioner (which creates/deletes topics on kafka) and dispatcher (which 1. accepts payloads over http and enqueues them in the topic and 2. consumes from topics and broadcasts to subscribers)

A 1-node Kafka broker (that can sit behind a service) setup is provided in kafka-broker.yaml. It is expected to be applied in namespace kafka (change the broker address in the bus declaration accordingly if it is not)

@google-prow-robot google-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 20, 2018
@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@ericbottard ericbottard changed the title Issue 83 [DNM] Kafka Bus Implementation Jun 20, 2018
@ericbottard
Copy link
Copy Markdown
Contributor Author

/check-cla

@scothis scothis mentioned this pull request Jun 21, 2018
@ericbottard ericbottard force-pushed the issue_83 branch 3 times, most recently from 7c97c14 to 078ba14 Compare June 25, 2018 13:36
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@ericbottard ericbottard force-pushed the issue_83 branch 2 times, most recently from 4e7e396 to 848bf9e Compare June 26, 2018 08:48
@ericbottard ericbottard changed the title [DNM] Kafka Bus Implementation Kafka Bus Implementation Jun 26, 2018
@ericbottard
Copy link
Copy Markdown
Contributor Author

Rebased on latest master that now includes #88

Comment thread config/buses/kafka.yaml Outdated
env:
- name: KAFKA_BROKERS
value: "kafkabroker.kafka:9092"
- name: BUS_NAME
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.

BUS_NAME and BUS_NAMESPACE are set by the controller

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.

Fixing

*out = new(InjectDelay)
**out = **in
}
*out = new(InjectDelay)
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.

Why is codegen updating istio types?

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.

I really don't know. Maybe we don't reference a fixed version for Istio (or for codegen)?


import (
"flag"
"github.com/golang/glog"
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.

did gofmt do this?

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.

No, somehow Goland did this. Fixing


func main() {

kubeconfig := flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
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.

the convention is to define flags in the init func.

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.

That's only relevant if flags are not in the main package (which really shouldn't ever happen if you ask me), in case the package ends up being imported several times.

Putting flag declarations in init really has no benefit whatsoever. Worse, it encourages global vars

@scothis
Copy link
Copy Markdown
Contributor

scothis commented Jun 28, 2018

/retest

@evankanderson
Copy link
Copy Markdown
Member

/assign @scothis
/assign @n3wscott

@@ -0,0 +1,305 @@
/*
* Copyright 2018 the original author or authors.
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.

Knative authors, see #115

} else {
return 0, fmt.Errorf("unsupported initialOffset value. Must be one of %s or %s", Oldest, Newest)
}
return initialOffset, nil
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.

this is not reachable.

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.

Good catch. This is a leftover from when I thought you could pass an actual int offset here, not just Oldest|Newest

Will fix

@ericbottard
Copy link
Copy Markdown
Contributor Author

Rebased on latest master

@jldec
Copy link
Copy Markdown

jldec commented Jul 9, 2018

@evankanderson do you think we could add this PR to be included in the Knative launch project for demos?

@ericbottard
Copy link
Copy Markdown
Contributor Author

Rebased on latest master

@ericbottard
Copy link
Copy Markdown
Contributor Author

@vaikas-google could you please have a look at this PR, having a second non-trivial bus implementation seems valuable for launch

/assign @vaikas-google

Copy link
Copy Markdown
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.

Couple of small questions, nits. Just curious about the failure model for messages that fail to be delivered.

}
req, err := http.NewRequest(http.MethodPost, url.String(), bytes.NewReader(body))
if err != nil {
glog.Errorf("Unable to create subscriber request %v", err)
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.

Are these just dropped on the floor? How do we communicate errors from here and what happens in the error cases?

}

func channelFromHost(host string) (channel string, namespace string) {
chunks := strings.Split(host, ".")
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.

Should we check to make sure the host is valid form? Or check that we actually get two chunks back, otherwise L268 will panic?

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.

Will add code to prevent the panic. Paths that end up returning the zero string for either name of namespace will end up in HTTP 404 thanks to code further down

hs := kafka2HttpHeaders(msg)
svc := fmt.Sprintf("%s.%s", subscription.Spec.Subscriber, subscription.Namespace)
d.dispatchEvent(svc, msg.Value, hs)
consumer.MarkOffset(msg, "") // Mark message as processed
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.

Since dispatchEvent does not return error, seems like any delivery failure will result in dropped messages since we mark them as processed?

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.

True, (for now).

Could change signature to propagate errors, but infinite retry is not better. Would require some retry-and-giveup logic that seems out of scope of this initial PR, wdyt?

Will at least mark as TODO

conf.ClientID = name + "-dispatcher"
kafka_client, err := sarama.NewClient(brokers, conf)
if err != nil {
glog.Fatalf("Error building kafka client: %s", err.Error())
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.

Just curious why not just log this as "...%v", err)

subscriber.

To view logs:
- for the dispatcher `kail -d kafka-bus -c dispatcher`
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.

We should probably add a pointer on how to install kail? Since it's used throughout the examples, wonder if this should be made part of the DEVELOPMENT.md (as optional?).

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.

Adding the same snippet that was just merged in other READMEs

}

func topicNameFromChannel(channel *channelsv1alpha1.Channel) string {
topicName := fmt.Sprintf("%s.%s", channel.Namespace, channel.Name)
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.

maybe just combine these two lines:
return fmt.Sprintf("...

@ericbottard
Copy link
Copy Markdown
Contributor Author

Addressed review comments, rebased on latest master

@ericbottard
Copy link
Copy Markdown
Contributor Author

Created #167 to track dispatch error handling

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jul 10, 2018 via email

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jul 10, 2018

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ericbottard, 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 Jul 10, 2018
@google-prow-robot google-prow-robot merged commit 7dc29a5 into knative:master Jul 10, 2018
@ericbottard
Copy link
Copy Markdown
Contributor Author

Awesome, thanks for you thorough review(s) @vaikas-google

scothis added a commit to scothis/eventing that referenced this pull request Sep 11, 2018
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver):

> Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter

- [First Issue](knative#80). Opened 6/11
- [First PR](knative#66). Opened 5/31
- [First Review](knative#79 (review)) 6/11

> Primary reviewer for at least 10 substantial PRs to the codebase

- knative#422 (review)
- knative#414 (review)
- knative#325 (review)
- knative#225 (review)
- knative#189 (review)
- knative#168 (review)
- knative#165 (review)
- knative#99 (review)
- knative#79 (review)
- knative#111 (review)

> Reviewed or merged at least 30 PRs to the codebase

- [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis)
- [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged)
- [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis)

> Nominated by an area lead

From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events)

/assign @vaikas-google

> With no objections from other leads

🤞

/cc @evankanderson @grantr @inlined @mattmoor
knative-prow-robot pushed a commit that referenced this pull request Sep 12, 2018
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver):

> Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter

- [First Issue](#80). Opened 6/11
- [First PR](#66). Opened 5/31
- [First Review](#79 (review)) 6/11

> Primary reviewer for at least 10 substantial PRs to the codebase

- #422 (review)
- #414 (review)
- #325 (review)
- #225 (review)
- #189 (review)
- #168 (review)
- #165 (review)
- #99 (review)
- #79 (review)
- #111 (review)

> Reviewed or merged at least 30 PRs to the codebase

- [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis)
- [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged)
- [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis)

> Nominated by an area lead

From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events)

/assign @vaikas-google

> With no objections from other leads

🤞

/cc @evankanderson @grantr @inlined @mattmoor
matzew pushed a commit to matzew/eventing that referenced this pull request Apr 11, 2019
* Introduce bus backed by Kafka

Don't version IDE files

Add sarama + sarama-cluster

Handle initialOffset

* Address review comments

* Anticipate ClusterBus

* Less invasive update-deps

* Rebase on latest master

* Update old copyright headers

* Remove unreachable code

* Adapt to latest bus changes

* Rebase against latest master

* Use separate directory for kafka bus. Add README.

* Address review comments

* Add embryo of error handling while dispatching
matzew pushed a commit to matzew/eventing that referenced this pull request Apr 11, 2019
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver):

> Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter

- [First Issue](knative#80). Opened 6/11
- [First PR](knative#66). Opened 5/31
- [First Review](knative#79 (review)) 6/11

> Primary reviewer for at least 10 substantial PRs to the codebase

- knative#422 (review)
- knative#414 (review)
- knative#325 (review)
- knative#225 (review)
- knative#189 (review)
- knative#168 (review)
- knative#165 (review)
- knative#99 (review)
- knative#79 (review)
- knative#111 (review)

> Reviewed or merged at least 30 PRs to the codebase

- [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis)
- [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged)
- [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis)

> Nominated by an area lead

From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events)

/assign @vaikas-google

> With no objections from other leads

🤞

/cc @evankanderson @grantr @inlined @mattmoor
matzew pushed a commit to matzew/eventing that referenced this pull request May 16, 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants