Skip to content

Commit

Permalink
rpk: decommission-status supports human-friendly outputs
Browse files Browse the repository at this point in the history
decommission-status now supports the -H option that prints
partition size in a human-readable format

(cherry picked from commit b4bc399)
  • Loading branch information
daisukebe authored and vbotbuildovich committed Aug 31, 2023
1 parent c8ed0e4 commit f2b138b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/go/rpk/pkg/cli/redpanda/admin/brokers/decommission-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"strconv"

"github.com/docker/go-units"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/adminapi"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out"
Expand All @@ -18,14 +19,16 @@ func newDecommissionBrokerStatus(fs afero.Fs, p *config.Params) *cobra.Command {
var (
completion int
detailed bool
human bool
)
cmd := &cobra.Command{
Use: "decommission-status [BROKER ID]",
Short: "Show the progress of a node decommissioning",
Long: `Show the progrss of a node decommissioning.
When a node is being decommissioned, this command reports the decommissioning
progress as follows, where PARTITION-SIZE is in bytes.
progress as follows, where PARTITION-SIZE is in bytes. Using -H, it prints the
partition size in a human-readable format.
$ rpk redpanda admin brokers decommission-status 4
DECOMMISSION PROGRESS
Expand Down Expand Up @@ -108,6 +111,14 @@ using 'rpk cluster config get partition_autobalancing_mode'.
if detailed {
headers = append(headers, "Bytes-moved", "Bytes-remaining")
}

sizeFn := func(size int) string {
if human {
return units.HumanSize(float64(size))
}
return strconv.Itoa(size)
}

f := func(p *adminapi.DecommissionPartitions) interface{} {
nt := p.Ns + "/" + p.Topic
if p.PartitionSize > 0 {
Expand All @@ -119,31 +130,31 @@ using 'rpk cluster config get partition_autobalancing_mode'.
Partition int
MovingTo int
Completion int
PartitionSize int
BytesMoved int
BytesRemaining int
PartitionSize string
BytesMoved string
BytesRemaining string
}{
nt,
p.Partition,
p.MovingTo.NodeID,
completion,
p.PartitionSize,
p.BytesMoved,
p.BytesLeftToMove,
sizeFn(p.PartitionSize),
sizeFn(p.BytesMoved),
sizeFn(p.BytesLeftToMove),
}
} else {
return struct {
NT string
Partition int
MovingTo int
Completion int
PartitionSize int
PartitionSize string
}{
nt,
p.Partition,
p.MovingTo.NodeID,
completion,
p.PartitionSize,
sizeFn(p.PartitionSize),
}
}
}
Expand All @@ -158,6 +169,7 @@ using 'rpk cluster config get partition_autobalancing_mode'.
},
}
cmd.Flags().BoolVarP(&detailed, "detailed", "d", false, "Print how much data moved and remaining in bytes")
cmd.Flags().BoolVarP(&human, "human-readable", "H", false, "Print the partition size in a human-readable form")

return cmd
}

0 comments on commit f2b138b

Please sign in to comment.