From 4a031dbdf925603b64c6b1ac9f0f880cba45bd70 Mon Sep 17 00:00:00 2001 From: Steven Gagniere <108363707+sgagniere@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:47:50 -0800 Subject: [PATCH] Reapply KGLOBAL-5675 (#2939) --- go.mod | 2 +- go.sum | 4 +- internal/kafka/command_link_describe.go | 54 +++++++++++++------ .../link/describe-bidirectional-link.golden | 15 +++--- test/test-server/kafka_rest_router.go | 4 ++ 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 175a006986..511049c8db 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/confluentinc/ccloud-sdk-go-v2/iam-ip-filtering v0.3.0 github.com/confluentinc/ccloud-sdk-go-v2/identity-provider v0.2.0 github.com/confluentinc/ccloud-sdk-go-v2/kafka-quotas v0.4.0 - github.com/confluentinc/ccloud-sdk-go-v2/kafkarest v0.21.0 + github.com/confluentinc/ccloud-sdk-go-v2/kafkarest v0.22.0 github.com/confluentinc/ccloud-sdk-go-v2/ksql v0.2.0 github.com/confluentinc/ccloud-sdk-go-v2/mds v0.4.0 github.com/confluentinc/ccloud-sdk-go-v2/metrics v0.2.0 diff --git a/go.sum b/go.sum index 73c315a323..eade639084 100644 --- a/go.sum +++ b/go.sum @@ -231,8 +231,8 @@ github.com/confluentinc/ccloud-sdk-go-v2/identity-provider v0.2.0 h1:9TT8UCFRc5z github.com/confluentinc/ccloud-sdk-go-v2/identity-provider v0.2.0/go.mod h1:JLmrXfnT2PzcuXHD8a6c2cW1c9LKK7aMsdZjjqxYPEk= github.com/confluentinc/ccloud-sdk-go-v2/kafka-quotas v0.4.0 h1:T9e7lNj/VjxE89+tcpX2RS2NE4rWNWbJjxcO2yehEqM= github.com/confluentinc/ccloud-sdk-go-v2/kafka-quotas v0.4.0/go.mod h1:7gqwWFIyj2MAGpL/kf6SGXm/pi2Z6qpMJIjKlgEEhhg= -github.com/confluentinc/ccloud-sdk-go-v2/kafkarest v0.21.0 h1:QXdyHcmx5xuX2D0THt2nJdhQ3YHOuPqoR8JfqalODCs= -github.com/confluentinc/ccloud-sdk-go-v2/kafkarest v0.21.0/go.mod h1:1hTwJlTy/3WPjA6I4tFf3X8RjXRHe0RQhRYfR+gHaqc= +github.com/confluentinc/ccloud-sdk-go-v2/kafkarest v0.22.0 h1:nnp7SQnGxhAIcSGSjZd0bjRWWN5qV4TPgsxBRSKKD6M= +github.com/confluentinc/ccloud-sdk-go-v2/kafkarest v0.22.0/go.mod h1:FOaBPIbG2+RApcd9uriBno/yBRzjDOrGYIeJW2ZmIcY= github.com/confluentinc/ccloud-sdk-go-v2/ksql v0.2.0 h1:g6OHa1iW3HO3N/YiTAL9Q6Y7rdjMBAjOPYK37akTt0M= github.com/confluentinc/ccloud-sdk-go-v2/ksql v0.2.0/go.mod h1:0LAvd4VqlaRwKU4yvDEkVCtV43yNezt56+hBe9Lmg7Q= github.com/confluentinc/ccloud-sdk-go-v2/mds v0.4.0 h1:jIXXhGi+Xn+XYFCErnMvd035QijbYXla1Bo8W7V7lFM= diff --git a/internal/kafka/command_link_describe.go b/internal/kafka/command_link_describe.go index 6b8d0eeac0..bb32a87449 100644 --- a/internal/kafka/command_link_describe.go +++ b/internal/kafka/command_link_describe.go @@ -1,6 +1,9 @@ package kafka import ( + "fmt" + "strings" + "github.com/spf13/cobra" kafkarestv3 "github.com/confluentinc/ccloud-sdk-go-v2/kafkarest/v3" @@ -10,14 +13,15 @@ import ( ) type linkOut struct { - Name string `human:"Name" serialized:"link_name"` - TopicName string `human:"Topic Name" serialized:"topic_name"` - SourceCluster string `human:"Source Cluster" serialized:"source_cluster,omitempty"` - DestinationCluster string `human:"Destination Cluster" serialized:"destination_cluster,omitempty"` - RemoteCluster string `human:"Remote Cluster" serialized:"remote_cluster,omitempty"` - State string `human:"State" serialized:"state"` - Error string `human:"Error,omitempty" serialized:"error,omitempty"` - ErrorMessage string `human:"Error Message,omitempty" serialized:"error_message,omitempty"` + Name string `human:"Name" serialized:"link_name"` + TopicName string `human:"Topic Name" serialized:"topic_name"` + SourceCluster string `human:"Source Cluster" serialized:"source_cluster,omitempty"` + DestinationCluster string `human:"Destination Cluster" serialized:"destination_cluster,omitempty"` + RemoteCluster string `human:"Remote Cluster" serialized:"remote_cluster,omitempty"` + State string `human:"State" serialized:"state"` + Error string `human:"Error,omitempty" serialized:"error,omitempty"` + ErrorMessage string `human:"Error Message,omitempty" serialized:"error_message,omitempty"` + MirrorPartitionStatesCount string `human:"Mirror Partition States Count,omitempty" serialized:"mirror_partition_states_count,omitempty"` } func (c *linkCommand) newDescribeCommand() *cobra.Command { @@ -52,7 +56,7 @@ func (c *linkCommand) describe(cmd *cobra.Command, args []string) error { table := output.NewTable(cmd) table.Add(newDescribeLink(link, "")) - table.Filter(getListFields(false)) + table.Filter(getDescribeFields(false)) return table.Print() } @@ -61,14 +65,30 @@ func newDescribeLink(link kafkarestv3.ListLinksResponseData, topic string) *link if link.GetLinkError() != "NO_ERROR" { linkError = link.GetLinkError() } + linkCategories := link.GetCategoryCounts() + categories := make([]string, len(linkCategories)) + for i, category := range linkCategories { + categories[i] = fmt.Sprintf(`%s: %d`, category.StateCategory, category.Count) + } return &linkOut{ - Name: link.GetLinkName(), - TopicName: topic, - SourceCluster: link.GetSourceClusterId(), - DestinationCluster: link.GetDestinationClusterId(), - RemoteCluster: link.GetRemoteClusterId(), - State: link.GetLinkState(), - Error: linkError, - ErrorMessage: link.GetLinkErrorMessage(), + Name: link.GetLinkName(), + TopicName: topic, + SourceCluster: link.GetSourceClusterId(), + DestinationCluster: link.GetDestinationClusterId(), + RemoteCluster: link.GetRemoteClusterId(), + State: link.GetLinkState(), + Error: linkError, + ErrorMessage: link.GetLinkErrorMessage(), + MirrorPartitionStatesCount: strings.Join(categories, ", "), } } + +func getDescribeFields(includeTopics bool) []string { + x := []string{"Name"} + + if includeTopics { + x = append(x, "TopicName") + } + + return append(x, "SourceCluster", "DestinationCluster", "RemoteCluster", "State", "Error", "ErrorMessage", "MirrorPartitionStatesCount") +} diff --git a/test/fixtures/output/kafka/link/describe-bidirectional-link.golden b/test/fixtures/output/kafka/link/describe-bidirectional-link.golden index 97c8cd48dc..a26f6c4a93 100644 --- a/test/fixtures/output/kafka/link/describe-bidirectional-link.golden +++ b/test/fixtures/output/kafka/link/describe-bidirectional-link.golden @@ -1,7 +1,8 @@ -+---------------------+-----------+ -| Name | link-4 | -| Source Cluster | | -| Destination Cluster | | -| Remote Cluster | cluster-2 | -| State | AVAILABLE | -+---------------------+-----------+ ++-------------------------------+-------------------------+ +| Name | link-4 | +| Source Cluster | | +| Destination Cluster | | +| Remote Cluster | cluster-2 | +| State | AVAILABLE | +| Mirror Partition States Count | ACTIVE: 10, IN_ERROR: 2 | ++-------------------------------+-------------------------+ diff --git a/test/test-server/kafka_rest_router.go b/test/test-server/kafka_rest_router.go index 9a9a188297..db7532d064 100644 --- a/test/test-server/kafka_rest_router.go +++ b/test/test-server/kafka_rest_router.go @@ -718,6 +718,10 @@ func handleKafkaRestLink(t *testing.T) http.HandlerFunc { ClusterLinkId: "LINKID4", TopicNames: []string{"link-1-topic-1", "link-1-topic-2"}, LinkState: cckafkarestv3.PtrString("AVAILABLE"), + CategoryCounts: []cckafkarestv3.LinkCategory{ + {StateCategory: "ACTIVE", Count: 10}, + {StateCategory: "IN_ERROR", Count: 2}, + }, }) require.NoError(t, err) } else if link == "link-5" {