Skip to content

Commit

Permalink
Reapply KGLOBAL-5675 (#2939)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgagniere authored Nov 19, 2024
1 parent b29132d commit 4a031db
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
54 changes: 37 additions & 17 deletions internal/kafka/command_link_describe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package kafka

import (
"fmt"
"strings"

"github.com/spf13/cobra"

kafkarestv3 "github.com/confluentinc/ccloud-sdk-go-v2/kafkarest/v3"
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}

Expand All @@ -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")
}
Original file line number Diff line number Diff line change
@@ -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 |
+-------------------------------+-------------------------+
4 changes: 4 additions & 0 deletions test/test-server/kafka_rest_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 4a031db

Please sign in to comment.