Kafka Channel Dispatcher#589
Conversation
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
|
cc @matzew This is still missing unit tests which I am happy to add once the dispatcher design is validated by others. |
|
/test pull-knative-eventing-build-tests |
|
@neosab Is that based on latest of master ? |
|
/assign matzew will take a look at this PR |
|
/lgtm as said, I got this working end-to-end, also nice to see messages in the kafka topics, using NOTE: other mentioned PRs need to go in first |
eba5235 to
b60006b
Compare
|
/assign @evankanderson Tested that this works for me. I will work on moving the common code to helpers in a subsequent PR. |
👍 @neosab let's create an issue in Github for that |
3302cf1 to
8ee2bf1
Compare
|
CLAs look good, thanks! |
|
/hold cancel |
|
/cc @adamharwayne |
|
@neosab: GitHub didn't allow me to request PR reviews from the following users: adamharwayne. Note that only knative members and repo collaborators can review this PR, and authors cannot review their own PRs. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/cc @Harwayne Didn't realize your github username changed :) |
evankanderson
left a comment
There was a problem hiding this comment.
This looks fairly good, but I had a few comments on kubernetes interactions, including with the configmaps.
| - apiGroups: | ||
| - "" # Core API group. | ||
| resources: | ||
| - configmaps |
There was a problem hiding this comment.
Should this be all configmaps, or just the one?
There was a problem hiding this comment.
The dispatcher uses github.com/knative/pkg/configmap watcher that needs these cluster-scoped privileges.
| volumes: | ||
| - name: kafka-channel-controller-config | ||
| configMap: | ||
| name: kafka-channel-controller-config |
There was a problem hiding this comment.
If you don't mark this optional and the ConfigMap isn't defined above, I think the pod will fail until the configmap is defined.
There was a problem hiding this comment.
kafka-channel-controller-config is required as it contains the broker info and we check if it is defined while starting up https://github.com/knative/eventing/pull/589/files#diff-8634243f0697f44c13a150873e6cc457R72. Do you want to change this behavior?
There was a problem hiding this comment.
I was wondering about crash-looping vs sitting and waiting for configuration, vs shipping a default configuration that the user might update later. I guess the current ClusterChannelProvisioner only supports a single set of bootstrap servers, so it may be that crash looping is the right choice for now. At some point in the future, it seems like we might want to support multiple Kafka clusters, at which point 0 clusters would be a valid configuration.
For now, this may be fine, but I have a sort of knee-jerk reaction to configs which fail unless the user has followed a precondition. Maybe a comment here or near the top of the file that creating this ConfigMap should be a precondition to applying this yaml?
There was a problem hiding this comment.
The yaml actualy creates the kafka-channel-controller-config configmap in L78. It defaults to a broker URL that one would get if they created the kafka cluster using the sample in ./broker/kafka-broker.yaml. I will add a comment for the end-user to update this config map in cases where they use a different kafka cluster.
|
|
||
| if value, ok := configMap[BrokerConfigMapKey]; ok { | ||
| bootstrapServers := strings.Split(value, ",") | ||
| if len(bootstrapServers) == 0 { |
There was a problem hiding this comment.
strings.Split will never return a zero-length array (it always returns at least one entry). I think you want to validate that all entries are non-empty (and add a test)?
There was a problem hiding this comment.
A test would have caught it :). I added it now.
|
|
||
| config := &KafkaProvisionerConfig{} | ||
|
|
||
| if value, ok := configMap[BrokerConfigMapKey]; ok { |
There was a problem hiding this comment.
Access to a non-existent value in a map will return a default value, so you could write this as simply:
config.Brokers := strings.Split(configMap[BrokerConfigMapKey], ",")
for _, s := range(config.Brokers) {
if len(s) == 0 {
return nil, fmt.Errorf("Empty bootstrap_servers in configuration %s: %q", path, configMap[BrokerConfigMapKey])
}
}
return config, nilThere was a problem hiding this comment.
Ah, I misread it. Thanks! I am fixing it.
| if _, ok := d.kafkaConsumers[channelRef][sub]; ok { | ||
| // subscribe can be called multiple times for the same subscription, | ||
| //unsubscribe before we resubscribe | ||
| err := d.unsubscribe(channelRef, sub) |
There was a problem hiding this comment.
If we unsubscribe and resubscribe, will we potentially drop messages?
Again, this may be another TODO at the moment.
There was a problem hiding this comment.
Actually, I am not sure why we need to unsubscribe and re-subscribe in case of existing subscription. I retained this from the original kafka bus implementation. cc @markfisher @scothis @matzew if they know.
There was a problem hiding this comment.
Feel free to TODO and file an issue for this. At some point, we'll want to actually write some tests to stress this, I expect.
| d.updateLock.Lock() | ||
| defer d.updateLock.Unlock() | ||
|
|
||
| if diff := d.ConfigDiff(config); diff != "" { |
There was a problem hiding this comment.
Presumably if we end up running more than one replica, we'll need to change this to filter the subscriptions by some sort of hash of the replica ID? (Fine to leave as a TODO.)
There was a problem hiding this comment.
Similar to the comment on duplicate subscribers, if we run more replicas, the kafka consumer/subscription/replica will still be added to the same consumer group that will ensure exactly one of them consumes a partition. Wouldn't this eliminate the need to filter subscriptions for each replica?
There was a problem hiding this comment.
Hmm, if you have multiple replicas, won't they each attempt to consume from the same consumer group? Will all but one block (I'm not familiar enough with Kafka and this library to be sure, it's possible that this is simply a competing consumer model)?
Obviously, with only 1 partition, the benefit of replicas will be limited, but I'm guessing that we'll support wider fanout soon.
There was a problem hiding this comment.
The sarama-cluster library provides a balanced consumer group implementation on top of sarama. Even with multiple replicas, since consumer instances are part of the same consumer group, they coordinate so that at most one consumer will have access to a partition in a topic subscribed by the group.
Obviously, with only 1 partition, the benefit of replicas will be limited, but I'm guessing that we'll support wider fanout soon.
We already support NumPartitions as a channel argument.
6ba0991 to
14bb019
Compare
|
@evankanderson I pushed an update and responded to your comments. Please take a look when it's possible. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: evankanderson, neosab The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
The following is the coverage report on pkg/.
|
|
/lgtm there are a few minor things, there are some issues filed for that... I tested (on Minishift) the k8sevent source demo, and used this channel: REceiving messages on the |
Fixes #441
Proposed Changes
TODO (in a subsequent PR)
Release Note