Skip to content

KC-1368 & KC-1372: Support cluster linking Link/Mirror operation #791 - #793

Merged
Cheng (ctan888) merged 34 commits into
masterfrom
linkNmirror
May 3, 2021
Merged

KC-1368 & KC-1372: Support cluster linking Link/Mirror operation #791#793
Cheng (ctan888) merged 34 commits into
masterfrom
linkNmirror

Conversation

@ctan888

Copy link
Copy Markdown
Contributor
  1. Adapting the existing "link command" to Rest proxy v3. Will fall back to the old Kafka Api path if rest proxy is not available.
  2. 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
  3. 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)

@ctan888
Cheng (ctan888) requested a review from a team as a code owner February 22, 2021 18:54
@ctan888 Cheng (ctan888) changed the title Link nmirror KC-1368 & KC-1372: Support cluster linking Link/Mirror operation #791 Feb 22, 2021

@mtodzo Miles Todzo (mtodzo) left a comment

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.

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:

  1. 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)
  2. 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.

Comment thread internal/cmd/kafka/command_link.go Outdated
Comment thread internal/cmd/kafka/command_mirror.go Outdated
Comment thread internal/cmd/kafka/command_link.go Outdated
Comment thread internal/cmd/kafka/command_mirror.go Outdated
Comment thread internal/cmd/kafka/command_mirror.go Outdated
Comment thread internal/cmd/kafka/command_mirror.go
Comment thread internal/cmd/kafka/utils.go Outdated
Comment thread internal/pkg/errors/strings.go Outdated
Comment thread mock/kafka_rest.go Outdated
Comment thread internal/cmd/kafka/command_test.go Outdated
@ctan888

Copy link
Copy Markdown
Contributor Author

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.

Comment thread internal/cmd/kafka/command_test.go Outdated
expect := make(chan interface{})
for _, link := range Links {
cmd := newCmd(expect, false)
cmd := newCmd(expect, true)

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 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?

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 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.

Comment thread mock/kafka_rest.go Outdated
Comment thread internal/cmd/kafka/command_test.go Outdated
Comment thread internal/cmd/kafka/command_mirror.go Outdated
Comment thread internal/cmd/kafka/command_test.go
Comment thread mock/kafka_rest.go Outdated
Comment thread internal/cmd/kafka/command_mirror.go Outdated
@ctan888

Copy link
Copy Markdown
Contributor Author

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.

@mtodzo Miles Todzo (mtodzo) left a comment

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.

good to merge after nit comments and sdk update/CI passes

Comment thread internal/cmd/kafka/command_link.go Outdated
linkName := args[0]
kafkaREST, _ := c.GetKafkaREST()
if kafkaREST == nil {
fmt.Println("rest proxy not available")

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.

remove print statement

utils.Printf(cmd, errors.DeletedLinkMsg, linkName)
}

return 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.

can we just do a return nil for clarity

@@ -1,3 +1,4 @@
rest proxy not available

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.

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"

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.

if you run make fmt it should fix indents

Comment thread test/kafka_test.go
Comment on lines +110 to +128
{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"}},

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 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 {

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.

when is this used?

Comment thread internal/cmd/kafka/command_mirror.go Outdated
Comment on lines +523 to +526
outputWriter.AddElement(&alterMirrorWrite{
DestinationTopicName: result.DestinationTopicName,
ErrorMessage: msg,
ErrorCode: code,

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.

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

Comment thread internal/pkg/errors/strings.go Outdated
UpdatedLinkMsg = "Updated cluster link \"%s\".\n"

// kafka mirror commands
RestProxyNotAvailableMsg = "Operation not supported: rest proxy is not available in the destination cluster."

@ahuang98 Alyssa Huang (ahuang98) Mar 12, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@ctan888
Cheng (ctan888) merged commit 6a9cb63 into master May 3, 2021
@ctan888
Cheng (ctan888) deleted the linkNmirror branch May 3, 2021 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants