-
Notifications
You must be signed in to change notification settings - Fork 60
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
[DP-1762] - topicctl get actions for under replicated and offline partitions #149
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 | ||
---|---|---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |||
"github.com/segmentio/topicctl/pkg/cli" | ||||
log "github.com/sirupsen/logrus" | ||||
"github.com/spf13/cobra" | ||||
prefixed "github.com/x-cray/logrus-prefixed-formatter" | ||||
) | ||||
|
||||
var getCmd = &cobra.Command{ | ||||
|
@@ -31,7 +32,24 @@ type getCmdConfig struct { | |||
|
||||
var getConfig getCmdConfig | ||||
|
||||
type urpCmdConfig struct { | ||||
topics []string | ||||
} | ||||
|
||||
var urpConfig urpCmdConfig | ||||
|
||||
type opCmdConfig struct { | ||||
topics []string | ||||
} | ||||
|
||||
var opConfig urpCmdConfig | ||||
|
||||
func init() { | ||||
log.SetFormatter(&prefixed.TextFormatter{ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This log format and the debug flag should already be getting set by the root command that these subcommands are added to topicctl/cmd/topicctl/subcmd/root.go Line 31 in 7ac2269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, we are overriding them, nevermind There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove some duplicate code by adding this to the get subcommands prerun rootCmd.PersistentPreRun(cmd, args) |
||||
TimestampFormat: "2006-01-02 15:04:05", | ||||
FullTimestamp: true, | ||||
}) | ||||
|
||||
getCmd.PersistentFlags().BoolVar( | ||||
&getConfig.full, | ||||
"full", | ||||
|
@@ -44,6 +62,12 @@ func init() { | |||
false, | ||||
"Sort by value instead of name; only applies for lags at the moment", | ||||
) | ||||
getCmd.PersistentFlags().BoolVar( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --debug is noted as being a "global flag". Isn't this already set somewhere higher up the stack? |
||||
&debug, | ||||
"debug", | ||||
false, | ||||
"enable debug logging", | ||||
) | ||||
addSharedFlags(getCmd, &getConfig.shared) | ||||
getCmd.AddCommand( | ||||
balanceCmd(), | ||||
|
@@ -55,11 +79,16 @@ func init() { | |||
partitionsCmd(), | ||||
offsetsCmd(), | ||||
topicsCmd(), | ||||
underReplicatedPartitionsCmd(), | ||||
offlinePartitionsCmd(), | ||||
) | ||||
RootCmd.AddCommand(getCmd) | ||||
} | ||||
|
||||
func getPreRun(cmd *cobra.Command, args []string) error { | ||||
if debug { | ||||
log.SetLevel(log.DebugLevel) | ||||
} | ||||
return getConfig.shared.validate() | ||||
} | ||||
|
||||
|
@@ -234,3 +263,53 @@ func topicsCmd() *cobra.Command { | |||
}, | ||||
} | ||||
} | ||||
|
||||
func underReplicatedPartitionsCmd() *cobra.Command { | ||||
urpCommand := &cobra.Command{ | ||||
Use: "under-replicated-partitions", | ||||
Short: "Fetch all under replicated partitions in the kafka cluster.", | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The term "under-replicated partitions", when output, is inconsistently written. I would suggest "under-replicated partitions" (with the hyphen between under and replicated, and not capitalized) because that is most grammatically correct IMO. |
||||
Args: cobra.MinimumNArgs(0), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want |
||||
RunE: func(cmd *cobra.Command, args []string) error { | ||||
ctx, cliRunner, err := getCliRunnerAndCtx() | ||||
if err != nil { | ||||
return err | ||||
} | ||||
return cliRunner.GetUnderReplicatedPartitions(ctx, urpConfig.topics) | ||||
}, | ||||
} | ||||
|
||||
urpCommand.Flags().StringSliceVarP( | ||||
&urpConfig.topics, | ||||
"topics", | ||||
"t", | ||||
[]string{}, | ||||
"under replicated partitions for the topics", | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. under-replicated partitions |
||||
) | ||||
|
||||
return urpCommand | ||||
} | ||||
|
||||
func offlinePartitionsCmd() *cobra.Command { | ||||
opCommand := &cobra.Command{ | ||||
Use: "offline-partitions", | ||||
Short: "Fetch all offline partitions in the kafka cluster.", | ||||
Args: cobra.MinimumNArgs(0), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want |
||||
RunE: func(cmd *cobra.Command, args []string) error { | ||||
ctx, cliRunner, err := getCliRunnerAndCtx() | ||||
if err != nil { | ||||
return err | ||||
} | ||||
return cliRunner.GetOfflinePartitions(ctx, opConfig.topics) | ||||
}, | ||||
} | ||||
|
||||
opCommand.Flags().StringSliceVarP( | ||||
&opConfig.topics, | ||||
"topics", | ||||
"t", | ||||
[]string{}, | ||||
"offline partitions for the topics", | ||||
) | ||||
|
||||
return opCommand | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"strconv" | ||
"time" | ||
|
||
"github.com/segmentio/kafka-go" | ||
"github.com/segmentio/topicctl/pkg/util" | ||
) | ||
|
||
|
@@ -136,6 +137,16 @@ type zkChangeNotification struct { | |
EntityPath string `json:"entity_path"` | ||
} | ||
|
||
type TopicURPsInfo struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The more I think about it, do we even need these new types? Couldn't we just reuse |
||
Name string `json:"name"` | ||
Partitions []PartitionInfo `json:"partitions"` | ||
} | ||
|
||
type TopicOPsInfo struct { | ||
Name string `json:"name"` | ||
Partitions []kafka.Partition `json:"partitions"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be converting |
||
} | ||
|
||
// Addr returns the address of the current BrokerInfo. | ||
func (b BrokerInfo) Addr() string { | ||
return fmt.Sprintf("%s:%d", b.Host, b.Port) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using abbreviations for under-replicated-partitions and offline-partitions breaks the pattern used everywhere else. Even within these two new commands, it's not consistent: you have urpCmdConfg, underReplicatedPartitionsCmd, GetUnderReplicatedPartitions, urpCommand, FormatURPs, etc.
I realize they are long but I think it's better not to use abbreviations and be more consistent.