-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpk: introduce cluster partitions balancer-status
This command will query the cluster via admin api to retrieve information about the partition auto balancer.
- Loading branch information
Showing
5 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package partitions | ||
|
||
import ( | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/cmd/common" | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewPartitionsCommand(fs afero.Fs) *cobra.Command { | ||
var ( | ||
adminURL string | ||
adminEnableTLS bool | ||
adminCertFile string | ||
adminKeyFile string | ||
adminCAFile string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "partitions", | ||
Args: cobra.ExactArgs(0), | ||
Short: "Manage cluster partitions", | ||
} | ||
|
||
common.AddAdminAPITLSFlags(cmd, | ||
&adminEnableTLS, | ||
&adminCertFile, | ||
&adminKeyFile, | ||
&adminCAFile, | ||
) | ||
|
||
cmd.AddCommand( | ||
NewBalancerStatusCommand(fs), | ||
) | ||
|
||
cmd.PersistentFlags().StringVar( | ||
&adminURL, | ||
config.FlagAdminHosts2, | ||
"", | ||
"Comma-separated list of admin API addresses (<IP>:<port>)") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package partitions | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/api/admin" | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewBalancerStatusCommand(fs afero.Fs) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "balancer-status", | ||
Short: "Queries cluster for partition balancer status", | ||
Long: `Queries cluster for partition balancer status: | ||
FIELDS DESCRIPTION: | ||
Status: Either off, ready, starting, in_progress or stalled. | ||
Seconds Since Last Tick: The last time the partition balancer ran. | ||
Current Reassignments Count: Current number of partition reassignments in progress. | ||
Unavailable Nodes: The nodes that have been unavailable after a time set by 'partition_autobalancing_node_availability_timeout_sec' property. | ||
Over Disk Limit Nodes: The nodes that surpassed the threshold of used disk percentage set by 'partition_autobalancing_max_disk_usage_percent' property. | ||
BALANCER STATUS: | ||
off: The balancer is disabled. | ||
ready: The balancer is active but there is nothing to do. | ||
starting: The balancer is starting but has not run yet. | ||
in_progress: The balancer is active and is in the process of scheduling partition movements. | ||
stalled: There are some violations, but for some reason, the balancer cannot make progress in mitigating them. | ||
`, | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
p := config.ParamsFromCommand(cmd) | ||
cfg, err := p.Load(fs) | ||
out.MaybeDie(err, "unable to load config: %v", err) | ||
|
||
cl, err := admin.NewClient(fs, cfg) | ||
out.MaybeDie(err, "unable to initialize admin client: %v", err) | ||
|
||
status, err := cl.GetPartitionStatus(cmd.Context()) | ||
out.MaybeDie(err, "unable to request balancer status: %v", err) | ||
|
||
printBalancerStatus(status) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func printBalancerStatus(pbs admin.PartitionBalancerStatus) { | ||
format := `Status: %v | ||
Seconds Since Last Tick: %v | ||
Current Reassignment Count: %v | ||
` | ||
fmt.Printf(format, pbs.Status, pbs.SecondsSinceLastTick, pbs.CurrentReassignmentsCount) | ||
|
||
v := pbs.Violations | ||
if len(v.OverDiskLimitNodes) > 0 || len(v.UnavailableNodes) > 0 { | ||
vFormat := `Unavailable Nodes: %v | ||
Over Disk Limit Nodes: %v | ||
` | ||
fmt.Printf(vFormat, v.UnavailableNodes, v.OverDiskLimitNodes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters