Skip to content

Commit

Permalink
pr review comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 8, 2023
1 parent cf22ea5 commit 5c2a587
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 45 deletions.
4 changes: 1 addition & 3 deletions .changelog/17582.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
```release-note:feature
improved consul operator raft list-peers command added CommitIndex as well as Trails Leader By in the output table
Commit Index is the LastIndex from /v1/operator/autopilot/health and Trails Leader By is the difference from leader
last index and followers last index
raft list-peers shows the number of commits each follower is trailing the leader by to aid in troubleshooting.
```
17 changes: 0 additions & 17 deletions api/operator_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,3 @@ func (op *Operator) RaftRemovePeerByID(id string, q *WriteOptions) error {
}
return nil
}

// GetAutoPilotHealth is used to query the autopilot health.
func (op *Operator) GetAutoPilotHealth(q *QueryOptions) (*OperatorHealthReply, error) {
r := op.c.newRequest("GET", "/v1/operator/autopilot/health")
r.setQueryOptions(q)
_, resp, err := op.c.doRequest(r)
if err != nil {
return nil, err
}
defer closeResponseBody(resp)

var out OperatorHealthReply
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return &out, nil
}
19 changes: 0 additions & 19 deletions api/operator_raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,3 @@ func TestAPI_OperatorRaftLeaderTransfer(t *testing.T) {
t.Fatalf("err:%v", transfer)
}
}

func TestAPI_GetAutoPilotHealth(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()

operator := c.Operator()
out, err := operator.GetAutoPilotHealth(nil)
if err != nil {
t.Fatalf("err: %v", err)
}

if len(out.Servers) != 1 ||
!out.Servers[0].Leader ||
!out.Servers[0].Voter ||
out.Servers[0].LastIndex <= 0 {
t.Fatalf("bad: %v", out)
}
}
10 changes: 5 additions & 5 deletions command/operator/raft/listpeers/operator_raft_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func raftListPeers(client *api.Client, stale bool) (string, error) {
return "", fmt.Errorf("Failed to retrieve raft configuration: %v", err)
}

autoPilotReply, err := client.Operator().GetAutoPilotHealth(q)
autoPilotReply, err := client.Operator().AutopilotServerHealth(q)
if err != nil {
return "", fmt.Errorf("Failed to retrieve autopilot health: %v", err)
}
Expand Down Expand Up @@ -107,17 +107,17 @@ func raftListPeers(client *api.Client, stale bool) (string, error) {
serverHealthData, ok := serverHealthDataMap[s.ID]
if ok {
trailsLeaderBy := leaderLastCommitIndex - serverHealthData.LastIndex
trailsLeaderByText := fmt.Sprintf("%d Commits", trailsLeaderBy)
trailsLeaderByText := fmt.Sprintf("%d commits", trailsLeaderBy)
if s.Leader {
trailsLeaderByText = "_"
trailsLeaderByText = "-"
} else if trailsLeaderBy <= 1 {
trailsLeaderByText = fmt.Sprintf("%d Commit", trailsLeaderBy)
trailsLeaderByText = fmt.Sprintf("%d commit", trailsLeaderBy)
}
result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s\x1f%s\x1f%v\x1f%s\x1f%v\x1f%s",
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, serverHealthData.LastIndex, trailsLeaderByText))
} else {
result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s\x1f%s\x1f%v\x1f%s\x1f%v",
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, "_"))
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, "-"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion command/operator/raft/listpeers/operator_raft_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestOperatorRaftListPeersCommand(t *testing.T) {
a := agent.NewTestAgent(t, ``)
defer a.Shutdown()

expected := fmt.Sprintf("%s %s 127.0.0.1:%d leader true 3 1 _",
expected := fmt.Sprintf("%s %s 127.0.0.1:%d leader true 3 1 -",
a.Config.NodeName, a.Config.NodeID, a.Config.ServerPort)

// Test the list-peers subcommand directly
Expand Down

0 comments on commit 5c2a587

Please sign in to comment.