-
Notifications
You must be signed in to change notification settings - Fork 26
AKCORE-915 : Add on-prem support for kafka share-group commands (list, describe,consumer list) #3297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
AKCORE-915 : Add on-prem support for kafka share-group commands (list, describe,consumer list) #3297
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package kafka | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/examples" | ||
| "github.com/confluentinc/cli/v4/pkg/kafkarest" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *shareGroupCommand) newConsumerListCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List Kafka share group consumers.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.consumerListOnPrem, | ||
| Example: examples.BuildExampleString( | ||
| examples.Example{ | ||
| Text: `List all consumers in share group "my-share-group".`, | ||
| Code: "confluent kafka share-group consumer list --group my-share-group", | ||
| }, | ||
| ), | ||
| } | ||
|
|
||
| cmd.Flags().String("group", "", "Share group ID.") | ||
| cmd.Flags().AddFlagSet(pcmd.OnPremKafkaRestSet()) | ||
| pcmd.AddContextFlag(cmd, c.CLICommand) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| cobra.CheckErr(cmd.MarkFlagRequired("group")) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *shareGroupCommand) consumerListOnPrem(cmd *cobra.Command, _ []string) error { | ||
| restClient, restContext, clusterId, err := initKafkaRest(c.AuthenticatedCLICommand, cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| group, err := cmd.Flags().GetString("group") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| consumers, resp, err := restClient.ShareGroupV3Api.ListKafkaShareGroupConsumers(restContext, clusterId, group) | ||
| if err != nil { | ||
| return kafkarest.NewError(restClient.GetConfig().BasePath, err, resp) | ||
| } | ||
|
|
||
| list := output.NewList(cmd) | ||
| for _, consumer := range consumers.Data { | ||
| list.Add(&shareGroupConsumerOut{ | ||
| Cluster: consumer.ClusterId, | ||
| ShareGroup: group, | ||
| Consumer: consumer.ConsumerId, | ||
| Client: consumer.ClientId, | ||
| }) | ||
| } | ||
| return list.Print() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package kafka | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func (c *shareGroupCommand) newConsumerCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "consumer", | ||
| Short: "Manage Kafka share group consumers.", | ||
| } | ||
|
|
||
| cmd.AddCommand(c.newConsumerListCommandOnPrem()) | ||
|
|
||
| return cmd | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package kafka | ||
|
|
||
| import ( | ||
| "sort" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/confluentinc/kafka-rest-sdk-go/kafkarestv3" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/kafkarest" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *shareGroupCommand) newDescribeCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "describe <group>", | ||
| Short: "Describe a Kafka share group.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: c.describeOnPrem, | ||
| } | ||
|
|
||
| cmd.Flags().AddFlagSet(pcmd.OnPremKafkaRestSet()) | ||
| pcmd.AddContextFlag(cmd, c.CLICommand) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *shareGroupCommand) describeOnPrem(cmd *cobra.Command, args []string) error { | ||
| restClient, restContext, clusterId, err := initKafkaRest(c.AuthenticatedCLICommand, cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| shareGroup, resp, err := restClient.ShareGroupV3Api.GetKafkaShareGroup(restContext, clusterId, args[0]) | ||
| if err != nil { | ||
| return kafkarest.NewError(restClient.GetConfig().BasePath, err, resp) | ||
| } | ||
|
|
||
| table := output.NewTable(cmd) | ||
| table.Add(&shareGroupOut{ | ||
| Cluster: shareGroup.ClusterId, | ||
| ShareGroup: shareGroup.ShareGroupId, | ||
| Coordinator: getStringBroker(shareGroup.Coordinator.Related), | ||
| State: shareGroup.State, | ||
| ConsumerCount: shareGroup.ConsumerCount, | ||
| PartitionCount: shareGroup.PartitionCount, | ||
| TopicSubscriptions: getShareGroupTopicNamesOnPrem(shareGroup), | ||
| }) | ||
| return table.Print() | ||
| } | ||
|
|
||
| func getShareGroupTopicNamesOnPrem(shareGroup kafkarestv3.ShareGroupData) []string { | ||
| if len(shareGroup.AssignedTopicPartitions) == 0 { | ||
| return []string{} | ||
| } | ||
|
|
||
| topicSet := make(map[string]bool) | ||
| for _, tp := range shareGroup.AssignedTopicPartitions { | ||
| topicSet[tp.TopicName] = true | ||
|
cqin-confluent marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if len(topicSet) == 0 { | ||
| return []string{} | ||
| } | ||
|
|
||
| topics := make([]string, 0, len(topicSet)) | ||
| for topic := range topicSet { | ||
| topics = append(topics, topic) | ||
| } | ||
|
|
||
| sort.Strings(topics) | ||
| return topics | ||
|
Comment on lines
+59
to
+74
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package kafka | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/kafkarest" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *shareGroupCommand) newListCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List Kafka share groups.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.listOnPrem, | ||
| } | ||
|
|
||
| cmd.Flags().AddFlagSet(pcmd.OnPremKafkaRestSet()) | ||
| pcmd.AddContextFlag(cmd, c.CLICommand) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *shareGroupCommand) listOnPrem(cmd *cobra.Command, _ []string) error { | ||
| restClient, restContext, clusterId, err := initKafkaRest(c.AuthenticatedCLICommand, cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| groups, resp, err := restClient.ShareGroupV3Api.ListKafkaShareGroups(restContext, clusterId) | ||
| if err != nil { | ||
| return kafkarest.NewError(restClient.GetConfig().BasePath, err, resp) | ||
| } | ||
|
|
||
| list := output.NewList(cmd) | ||
| for _, group := range groups.Data { | ||
| list.Add(&shareGroupOut{ | ||
| Cluster: group.ClusterId, | ||
| ShareGroup: group.ShareGroupId, | ||
| Coordinator: getStringBroker(group.Coordinator.Related), | ||
| State: group.State, | ||
| ConsumerCount: group.ConsumerCount, | ||
| }) | ||
| } | ||
| list.Filter([]string{"Cluster", "ShareGroup", "Coordinator", "State", "ConsumerCount"}) | ||
| return list.Print() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Manage Kafka share group consumers. | ||
|
|
||
| Usage: | ||
| confluent kafka share-group consumer [command] | ||
|
|
||
| Available Commands: | ||
| list List Kafka share group consumers. | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). | ||
|
|
||
| Use "confluent kafka share-group consumer [command] --help" for more information about a command. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Error: REST request failed: This server does not host this share group. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| List Kafka share group consumers. | ||
|
|
||
| Usage: | ||
| confluent kafka share-group consumer list [flags] | ||
|
|
||
| Examples: | ||
| List all consumers in share group "my-share-group". | ||
|
|
||
| $ confluent kafka share-group consumer list --group my-share-group | ||
|
|
||
| Flags: | ||
| --group string REQUIRED: Share group ID. | ||
| --url string Base URL of REST Proxy Endpoint of Kafka Cluster (include "/kafka" for embedded Rest Proxy). Must set flag or CONFLUENT_REST_URL. | ||
| --certificate-authority-path string Path to a PEM-encoded Certificate Authority to verify the Confluent REST Proxy. | ||
| --client-cert-path string Path to client cert to be verified by Confluent REST Proxy. Include for mTLS authentication. | ||
| --client-key-path string Path to client private key, include for mTLS authentication. | ||
| --no-authentication Include if requests should be made without authentication headers and user will not be prompted for credentials. | ||
| --prompt Bypass use of available login credentials and prompt for Kafka Rest credentials. | ||
| --context string CLI context name. | ||
| -o, --output string Specify the output format as "human", "json", or "yaml". (default "human") | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Cluster | Share Group | Consumer | Client | ||
| ------------+---------------+------------+----------- | ||
| cluster-1 | share-group-1 | consumer-1 | client-1 | ||
| cluster-1 | share-group-1 | consumer-2 | client-2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Error: REST request failed: This server does not host this share group. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Describe a Kafka share group. | ||
|
|
||
| Usage: | ||
| confluent kafka share-group describe <group> [flags] | ||
|
|
||
| Flags: | ||
| --url string Base URL of REST Proxy Endpoint of Kafka Cluster (include "/kafka" for embedded Rest Proxy). Must set flag or CONFLUENT_REST_URL. | ||
| --certificate-authority-path string Path to a PEM-encoded Certificate Authority to verify the Confluent REST Proxy. | ||
| --client-cert-path string Path to client cert to be verified by Confluent REST Proxy. Include for mTLS authentication. | ||
| --client-key-path string Path to client private key, include for mTLS authentication. | ||
| --no-authentication Include if requests should be made without authentication headers and user will not be prompted for credentials. | ||
| --prompt Bypass use of available login credentials and prompt for Kafka Rest credentials. | ||
| --context string CLI context name. | ||
| -o, --output string Specify the output format as "human", "json", or "yaml". (default "human") | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Manage Kafka share groups. | ||
|
|
||
| Usage: | ||
| confluent kafka share-group [command] | ||
|
|
||
| Available Commands: | ||
| consumer Manage Kafka share group consumers. | ||
| describe Describe a Kafka share group. | ||
| list List Kafka share groups. | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). | ||
|
|
||
| Use "confluent kafka share-group [command] --help" for more information about a command. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| List Kafka share groups. | ||
|
|
||
| Usage: | ||
| confluent kafka share-group list [flags] | ||
|
|
||
| Flags: | ||
| --url string Base URL of REST Proxy Endpoint of Kafka Cluster (include "/kafka" for embedded Rest Proxy). Must set flag or CONFLUENT_REST_URL. | ||
| --certificate-authority-path string Path to a PEM-encoded Certificate Authority to verify the Confluent REST Proxy. | ||
| --client-cert-path string Path to client cert to be verified by Confluent REST Proxy. Include for mTLS authentication. | ||
| --client-key-path string Path to client private key, include for mTLS authentication. | ||
| --no-authentication Include if requests should be made without authentication headers and user will not be prompted for credentials. | ||
| --prompt Bypass use of available login credentials and prompt for Kafka Rest credentials. | ||
| --context string CLI context name. | ||
| -o, --output string Specify the output format as "human", "json", or "yaml". (default "human") | ||
|
|
||
| Global Flags: | ||
| -h, --help Show help for this command. | ||
| --unsafe-trace Equivalent to -vvvv, but also log HTTP requests and responses which might contain plaintext secrets. | ||
| -v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Cluster | Share Group | Coordinator | State | Consumer Count | ||
| ------------+---------------+-------------+--------+----------------- | ||
| cluster-1 | share-group-1 | broker-1 | STABLE | 2 | ||
| cluster-1 | share-group-2 | broker-2 | EMPTY | 0 |
Uh oh!
There was an error while loading. Please reload this page.