KC-1368 & KC-1372: Support cluster linking Link/Mirror operation #791 - #793
Conversation
Cheng (ctan888)
commented
Feb 22, 2021
- Adapting the existing "link command" to Rest proxy v3. Will fall back to the old Kafka Api path if rest proxy is not available.
- Create a new "mirror command" which will use rest proxy v3. The old "mirror" related operation in "topic command" will remain the same behavior and will be deprecated in the future
- Unit test for mirror/link command. (Not sure we need the golden file tests, since we will have cc system test covering in the near future)
Miles Todzo (mtodzo)
left a comment
There was a problem hiding this comment.
Few minor comments, but mostly looks good!
I'm requesting changes for the testing though (repasting comment here):
Right now these unit tests are only verifying that no error is occurring - I'd ask that we have the tests also doing one of the following or both:
- add the expected request data into the expect chan (see ListTopicTest in kafka/command_test.go), and then in the mock/kafka_rest.go compare the expected data against the actual request data to make sure they are equal (see CreateACLs and assertEqualBindings in mock/kafka.go)
- Change the command output to be buffer that we can verify the contains the correct output (see TestShouldNotConfigureOnDryRun in ksql/command_test.go) and check to see that the proper output is being printed.
Also, it would be great to add some integration tests (the ones with the .golden files) since sometimes cc-system tests is broken for a non-CLI reason and this way we can ensure there's still some e-2-e testing. These are quick to add if you follow the ones in test/kafka_test.go that use the env var XX_CCLOUD_USE_KAFKA_REST.
|
Miles Todzo (@mtodzo) Thanks for the review. I've addressed all the comments and added the new set of tests following your suggestion. Could you take another look and let me know if there's anything else to change? Thanks. |
| expect := make(chan interface{}) | ||
| for _, link := range Links { | ||
| cmd := newCmd(expect, false) | ||
| cmd := newCmd(expect, true) |
There was a problem hiding this comment.
should there be tests for both newCmd(expect, true) and newCmd(expect, false) so that link commands are tested using rest proxy AND using kafka api?
There was a problem hiding this comment.
I don't think we need tests for kafka-api in cluster linking, as the rest proxy is guaranteed to be enabled for all cluster linking clusters.
fb5364a to
f3134db
Compare
|
Hi Miles Todzo (@mtodzo) . Thanks for the review again. Sorry for the wrongly pushed branch confusion for the tests. I've addressed all your new comments. Let me know if we're good to go now. |
43b6cc4 to
55a23ea
Compare
55a23ea to
caeaed7
Compare
b6b4fa3 to
0dd9e05
Compare
Miles Todzo (mtodzo)
left a comment
There was a problem hiding this comment.
good to merge after nit comments and sdk update/CI passes
| linkName := args[0] | ||
| kafkaREST, _ := c.GetKafkaREST() | ||
| if kafkaREST == nil { | ||
| fmt.Println("rest proxy not available") |
There was a problem hiding this comment.
remove print statement
| utils.Printf(cmd, errors.DeletedLinkMsg, linkName) | ||
| } | ||
|
|
||
| return err |
There was a problem hiding this comment.
can we just do a return nil for clarity
| @@ -1,3 +1,4 @@ | |||
| rest proxy not available | |||
There was a problem hiding this comment.
from the printed line commented on earlier
| rpLinks = "/kafka/v3/clusters/{cluster}/links" | ||
| rpLinkConfigs = "/kafka/v3/clusters/{cluster}/links/{link}/configs" | ||
| rpMirror = "/kafka/v3/clusters/{cluster}/links/{link}/mirrors/{destination_topic_name}" | ||
| rpAllMirrors = "/kafka/v3/clusters/{cluster}/links/-/mirrors" |
There was a problem hiding this comment.
if you run make fmt it should fix indents
| {args: "kafka link list --cluster lkc-describe-topic", fixture: "kafka/cluster-linking/list-link-plain.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link list --cluster lkc-describe-topic -o json", fixture: "kafka/cluster-linking/list-link-json.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link list --cluster lkc-describe-topic -o yaml", fixture: "kafka/cluster-linking/list-link-yaml.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link describe --cluster lkc-describe-topic link-1", fixture: "kafka/cluster-linking/describe-link-plain.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link describe --cluster lkc-describe-topic link-1 -o json", fixture: "kafka/cluster-linking/describe-link-json.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link describe --cluster lkc-describe-topic link-1 -o yaml", fixture: "kafka/cluster-linking/describe-link-yaml.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link list-configs --cluster lkc-describe-topic link-1", fixture: "kafka/cluster-linking/list-link-configs-plain.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link list-configs --cluster lkc-describe-topic link-1 -o json", fixture: "kafka/cluster-linking/list-link-configs-json.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka link list-configs --cluster lkc-describe-topic link-1 -o yaml", fixture: "kafka/cluster-linking/list-link-configs-yaml.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
|
|
||
| {args: "kafka mirror list --cluster lkc-describe-topic --link-name link-1", fixture: "kafka/cluster-linking/list-mirror.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror list --cluster lkc-describe-topic --link-name link-1 -o json", fixture: "kafka/cluster-linking/list-mirror-json.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror list --cluster lkc-describe-topic --link-name link-1 -o yaml", fixture: "kafka/cluster-linking/list-mirror-yaml.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror list --cluster lkc-describe-topic", fixture: "kafka/cluster-linking/list-all-mirror.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror list --cluster lkc-describe-topic -o json", fixture: "kafka/cluster-linking/list-all-mirror-json.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror list --cluster lkc-describe-topic -o yaml", fixture: "kafka/cluster-linking/list-all-mirror-yaml.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror promote topic1 topic2 --cluster lkc-describe-topic --link-name link-1", fixture: "kafka/cluster-linking/promote-mirror.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror promote topic1 topic2 --cluster lkc-describe-topic --link-name link-1 -o json", fixture: "kafka/cluster-linking/promote-mirror-json.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, | ||
| {args: "kafka mirror promote topic1 topic2 --cluster lkc-describe-topic --link-name link-1 -o yaml", fixture: "kafka/cluster-linking/promote-mirror-yaml.golden", wantErrCode: 0, useKafka: "lkc-describe-topic", env: []string{"XX_CCLOUD_USE_KAFKA_REST=true"}}, |
There was a problem hiding this comment.
sorry i know they're all under TestKafka right now, but would you might moving these under there own test? TestKafkaMirror TestKafkaLink
| return normalized | ||
| } | ||
|
|
||
| func RemoveSpace(s string) string { |
There was a problem hiding this comment.
when is this used?
| outputWriter.AddElement(&alterMirrorWrite{ | ||
| DestinationTopicName: result.DestinationTopicName, | ||
| ErrorMessage: msg, | ||
| ErrorCode: code, |
There was a problem hiding this comment.
is there anything else that should be printed? like something about the actual operation that was done? I'm thinking about the case where it's a success and the user then sees the destination topic, and "" for the error fields. But there's nothing that indicates what the change was? I don't really have an understanding of what the mirroring functionality is so this might not be relevant
| UpdatedLinkMsg = "Updated cluster link \"%s\".\n" | ||
|
|
||
| // kafka mirror commands | ||
| RestProxyNotAvailableMsg = "Operation not supported: rest proxy is not available in the destination cluster." |
There was a problem hiding this comment.
nit: could we make the error message more generic ("Operation not supported: rest proxy is not available") so that it can be used in non-cluster linking contexts? I'm implementing CLI commands for consumer lag, and they won't fall back to using kafka API either. If the rest proxy isn't available, I would also be returning a rest-proxy-not-available error
|
|
||
| /*************** TEST setup/helpers ***************/ | ||
| func newCmd(expect chan interface{}, enableREST bool) *cobra.Command { | ||
| func newMockCmd(kafkaExpect chan interface{}, kafkaRestExpect chan interface{}, enableREST bool) *cobra.Command { |
There was a problem hiding this comment.
I'm going to merge in these helper method changes (L985-L1029) so I can use it for my consumer group PR, thank you Cheng!
https://github.com/confluentinc/cli/pull/820/files#r604433061
7675e6d to
8f086e7
Compare
…mments beginning by #, in the config file parsing process
7071d22 to
9825de0
Compare