Skip to content
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

feat: add list-configs of topics #27

Merged
merged 7 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,31 @@ $ kafta topic list
| topic2 | 6 | 3 |
+-------------------------+------------+--------------------+
```
List configs topic

```
$ kafka topic list-configs my-topic

+-----------------------------------------+---------------------+--------------+
| Config Name | Config Value | Source |
+-----------------------------------------+---------------------+--------------+
| compression.type | producer | Default |
| leader.replication.throttled.replicas | N/A | Default |
| min.insync.replicas | 1 | StaticBroker |
| segment.jitter.ms | 0 | Default |
| cleanup.policy | delete | Default |
| flush.ms | 9223372036854775807 | Default |
| follower.replication.throttled.replicas | N/A | Default |
| segment.bytes | 1073741824 | Default |
| retention.ms | 172800000 | Topic |
| flush.messages | 9223372036854775807 | Default |
| delete.retention.ms | 86400000 | Default |
| segment.ms | 604800000 | Default |
| message.timestamp.difference.max.ms | 9223372036854775807 | Default |
| segment.index.bytes | 10485760 | Default |
+-----------------------------------------+---------------------+--------------+

```
## Consumer Group

List all consumers, run:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYt
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo/v2 v2.8.3 h1:RpbK1G8nWPNaCVFBWsOGnEQQGgASi6b8fxcWBvDYjxQ=
github.com/onsi/gomega v1.27.1 h1:rfztXRbg6nv/5f+Raen9RcGoSecHIFgBBLQK3Wdj754=
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
Expand Down
69 changes: 69 additions & 0 deletions pkg/cmd/cli/topic/config_topic.go
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
package topic

import (
"fmt"
"os"
"strings"

"github.com/Shopify/sarama"
"github.com/electric-saw/kafta/internal/pkg/configuration"
"github.com/electric-saw/kafta/internal/pkg/kafka"
cmdutil "github.com/electric-saw/kafta/pkg/cmd/util"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)

type listConfigsOptions struct {
config *configuration.Configuration
topic string
}

func NewCmdListConfigs(config *configuration.Configuration) *cobra.Command {
options := &listConfigsOptions{config: config}
cmd := &cobra.Command{
Use: "list-configs TOPIC",
Short: "List all configurations for a topic",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
options.topic = args[0]
cmdutil.CheckErr(options.run())
},
}

return cmd
}

func (o *listConfigsOptions) run() error {
conn := kafka.MakeConnection(o.config)
defer conn.Close()

resource := sarama.ConfigResource{
Name: o.topic,
Type: sarama.TopicResource,
}
configs, err := conn.Admin.DescribeConfig(resource)
if err != nil {
return fmt.Errorf("failed to describe config for topic %s: %w", o.topic, err)
}

table := tablewriter.NewWriter(os.Stdout)
snakeice marked this conversation as resolved.
Show resolved Hide resolved
table.SetHeader([]string{"Config Name", "Config Value", "Source"})
table.SetHeaderColor(tablewriter.Colors{tablewriter.Bold}, tablewriter.Colors{tablewriter.Bold}, tablewriter.Colors{tablewriter.Bold})
table.SetColumnColor(tablewriter.Colors{}, tablewriter.Colors{}, tablewriter.Colors{})

for _, config := range configs {
value := strings.TrimSpace(config.Value)
if value == "" {
value = "N/A"
}

table.Append([]string{config.Name, value, config.Source.String()})
}

table.SetAutoFormatHeaders(false)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetColWidth(30)

table.Render()

return nil
}
1 change: 1 addition & 0 deletions pkg/cmd/cli/topic/topic_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func NewCmdTopic(config *configuration.Configuration) *cobra.Command {
cmd.AddCommand(NewCmdDescribeTopic(config))
cmd.AddCommand(NewCmdConfigUpdateTopic(config))
cmd.AddCommand(NewCmdConfigResetTopic(config))
cmd.AddCommand(NewCmdListConfigs(config))

return cmd
}
Expand Down
Loading