Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Maslanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Sep 5, 2023
1 parent 5d5f065 commit 5e75fbc
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/go/rpk/pkg/adminapi/api_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const (

type MaintenanceStatus struct {
Draining bool `json:"draining"`

Check failure on line 25 in src/go/rpk/pkg/adminapi/api_broker.go

View workflow job for this annotation

GitHub Actions / Lint go files

File is not `gofmt`-ed with `-s` (gofmt)
Finished bool `json:"finished"`
Errors bool `json:"errors"`
Partitions int `json:"partitions"`
Eligible int `json:"eligible"`
Transferring int `json:"transferring"`
Failed int `json:"failed"`
Finished *bool `json:"finished"`
Errors *bool `json:"errors"`
Partitions *int `json:"partitions"`
Eligible *int `json:"eligible"`
Transferring *int `json:"transferring"`
Failed *int `json:"failed"`
}

// MembershipStatus enumerates possible membership states for brokers.
Expand Down
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/cluster/maintenance/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ node exists that is already in maintenance mode then an error will be returned.
}
addBrokerMaintenanceReport(table, b)
table.Flush()
if b.Maintenance.Draining && b.Maintenance.Finished {
if b.Maintenance.Draining && b.Maintenance.Finished != nil && *b.Maintenance.Finished {
fmt.Printf("\nAll partitions on node %d have drained.\n", nodeID)
return
}
Expand Down
32 changes: 26 additions & 6 deletions src/go/rpk/pkg/cli/cluster/maintenance/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
package maintenance

import (
"fmt"

"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 @@ -25,16 +27,34 @@ func newMaintenanceReportTable() *out.TabWriter {
return out.NewTable(headers...)
}

func nullableBool2str(v *bool) string {

Check failure on line 30 in src/go/rpk/pkg/cli/cluster/maintenance/status.go

View workflow job for this annotation

GitHub Actions / Lint go files

unnecessary leading newline (whitespace)

Check failure on line 31 in src/go/rpk/pkg/cli/cluster/maintenance/status.go

View workflow job for this annotation

GitHub Actions / Lint go files

File is not `gofumpt`-ed (gofumpt)
if v == nil {
return "-"
} else {
return fmt.Sprint(*v)
}
}

func nullableInt2str(v *int) string {

Check failure on line 39 in src/go/rpk/pkg/cli/cluster/maintenance/status.go

View workflow job for this annotation

GitHub Actions / Lint go files

unnecessary leading newline (whitespace)

Check failure on line 40 in src/go/rpk/pkg/cli/cluster/maintenance/status.go

View workflow job for this annotation

GitHub Actions / Lint go files

File is not `gofumpt`-ed (gofumpt)
if v == nil {
return "-"
} else {
return fmt.Sprint(*v)
}
}

Check failure on line 46 in src/go/rpk/pkg/cli/cluster/maintenance/status.go

View workflow job for this annotation

GitHub Actions / Lint go files

File is not `gofumpt`-ed (gofumpt)
func addBrokerMaintenanceReport(table *out.TabWriter, b adminapi.Broker) {

Check failure on line 47 in src/go/rpk/pkg/cli/cluster/maintenance/status.go

View workflow job for this annotation

GitHub Actions / Lint go files

unnecessary leading newline (whitespace)

table.Print(
b.NodeID,
b.Maintenance.Draining,
b.Maintenance.Finished,
b.Maintenance.Errors,
b.Maintenance.Partitions,
b.Maintenance.Eligible,
b.Maintenance.Transferring,
b.Maintenance.Failed)
nullableBool2str(b.Maintenance.Finished),
nullableBool2str(b.Maintenance.Errors),
nullableInt2str(b.Maintenance.Partitions),
nullableInt2str(b.Maintenance.Eligible),
nullableInt2str(b.Maintenance.Transferring),
nullableInt2str(b.Maintenance.Failed))
}

func newStatusCommand(fs afero.Fs, p *config.Params) *cobra.Command {
Expand Down
7 changes: 0 additions & 7 deletions src/v/redpanda/admin_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -842,13 +842,6 @@ fill_maintenance_status(const cluster::broker_state& b_state) {

ret.draining = b_state.get_maintenance_state()
== model::maintenance_state::active;
// ensure that the output json has all fields
ret.finished = false;
ret.errors = false;
ret.partitions = 0;
ret.transferring = 0;
ret.eligible = 0;
ret.failed = 0;

return ret;
}
Expand Down
18 changes: 12 additions & 6 deletions tests/rptest/clients/rpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,14 +989,20 @@ def parse(line):
line = [x.strip() for x in line]
if line[0] == "NODE-ID":
return None
def bool_or_none(value: str):
return None if value == "-" else value == "true"
def int_or_none(value: str):
return None if value == "-" else int(value)


return RpkMaintenanceStatus(node_id=int(line[0]),
enabled=line[1] == "true",
finished=line[2] == "true",
errors=line[3] == "true",
partitions=int(line[4]),
eligible=int(line[5]),
transferring=int(line[6]),
failed=int(line[7]))
finished=bool_or_none(line[2]),
errors=bool_or_none(line[3]),
partitions=int_or_none(line[4]),
eligible=int_or_none(line[5]),
transferring=int_or_none(line[6]),
failed=int_or_none(line[7]))

cmd = [
self._rpk_binary(),
Expand Down
18 changes: 12 additions & 6 deletions tests/rptest/tests/maintenance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def _in_maintenance_mode(self, node):

def _in_maintenance_mode_fully(self, node):
status = self.admin.maintenance_status(node)
return status["finished"] and not status["errors"] and \
status["partitions"] > 0
if all([key in status for key in ['finished', 'errors', 'partitions']]):
return status["finished"] and not status["errors"] and \
status["partitions"] > 0
else:
return False

def _verify_broker_metadata(self, maintenance_enabled, node):
"""
Expand All @@ -80,17 +83,18 @@ def _verify_broker_metadata(self, maintenance_enabled, node):
return False
# check status wanted
if maintenance_enabled:
return status['draining'] and status['finished']
return status['draining'] and status[
'finished'] if 'finished' in status else True
else:
return not status['draining']

def _verify_maintenance_status(self, node, draining):
def _verify_maintenance_status(self, node, enabled):
"""
Check that cluster reports maintenance status as expected through
both rpk status tooling as well as raw admin interface.
"""
# get status for this node via rpk
node_id = self.redpanda.idx(node)
node_id = self.redpanda.node_id(node)
statuses = self.rpk.cluster_maintenance_status()
self.logger.debug(f"finding node_id {node_id} in rpk "
"maintenance status: {statuses}")
Expand All @@ -108,7 +112,7 @@ def _verify_maintenance_status(self, node, draining):
"{node.name}: {admin_status}")

# ensure that both agree on expected outcome
return admin_status["draining"] == rpk_status.enabled == draining
return admin_status["draining"] == rpk_status.enabled == enabled

def _enable_maintenance(self, node):
"""
Expand Down Expand Up @@ -325,6 +329,8 @@ def _check_maintenance_status_on_each_broker(status):
True
), "All the nodes should keep reporting the state of node in maintenance mode"

# self._verify_maintenance_status(target, True)

if self._use_rpk:
self.rpk.cluster_maintenance_disable(target)
else:
Expand Down

0 comments on commit 5e75fbc

Please sign in to comment.