Skip to content

Commit 5c2a587

Browse files
author
Ashesh Vidyut
committed
pr review comment changes
1 parent cf22ea5 commit 5c2a587

File tree

5 files changed

+7
-45
lines changed

5 files changed

+7
-45
lines changed

.changelog/17582.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
```release-note:feature
2-
improved consul operator raft list-peers command added CommitIndex as well as Trails Leader By in the output table
3-
Commit Index is the LastIndex from /v1/operator/autopilot/health and Trails Leader By is the difference from leader
4-
last index and followers last index
2+
raft list-peers shows the number of commits each follower is trailing the leader by to aid in troubleshooting.
53
```

api/operator_raft.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,3 @@ func (op *Operator) RaftRemovePeerByID(id string, q *WriteOptions) error {
122122
}
123123
return nil
124124
}
125-
126-
// GetAutoPilotHealth is used to query the autopilot health.
127-
func (op *Operator) GetAutoPilotHealth(q *QueryOptions) (*OperatorHealthReply, error) {
128-
r := op.c.newRequest("GET", "/v1/operator/autopilot/health")
129-
r.setQueryOptions(q)
130-
_, resp, err := op.c.doRequest(r)
131-
if err != nil {
132-
return nil, err
133-
}
134-
defer closeResponseBody(resp)
135-
136-
var out OperatorHealthReply
137-
if err := decodeBody(resp, &out); err != nil {
138-
return nil, err
139-
}
140-
return &out, nil
141-
}

api/operator_raft_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,3 @@ func TestAPI_OperatorRaftLeaderTransfer(t *testing.T) {
5757
t.Fatalf("err:%v", transfer)
5858
}
5959
}
60-
61-
func TestAPI_GetAutoPilotHealth(t *testing.T) {
62-
t.Parallel()
63-
c, s := makeClient(t)
64-
defer s.Stop()
65-
66-
operator := c.Operator()
67-
out, err := operator.GetAutoPilotHealth(nil)
68-
if err != nil {
69-
t.Fatalf("err: %v", err)
70-
}
71-
72-
if len(out.Servers) != 1 ||
73-
!out.Servers[0].Leader ||
74-
!out.Servers[0].Voter ||
75-
out.Servers[0].LastIndex <= 0 {
76-
t.Fatalf("bad: %v", out)
77-
}
78-
}

command/operator/raft/listpeers/operator_raft_list.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func raftListPeers(client *api.Client, stale bool) (string, error) {
7070
return "", fmt.Errorf("Failed to retrieve raft configuration: %v", err)
7171
}
7272

73-
autoPilotReply, err := client.Operator().GetAutoPilotHealth(q)
73+
autoPilotReply, err := client.Operator().AutopilotServerHealth(q)
7474
if err != nil {
7575
return "", fmt.Errorf("Failed to retrieve autopilot health: %v", err)
7676
}
@@ -107,17 +107,17 @@ func raftListPeers(client *api.Client, stale bool) (string, error) {
107107
serverHealthData, ok := serverHealthDataMap[s.ID]
108108
if ok {
109109
trailsLeaderBy := leaderLastCommitIndex - serverHealthData.LastIndex
110-
trailsLeaderByText := fmt.Sprintf("%d Commits", trailsLeaderBy)
110+
trailsLeaderByText := fmt.Sprintf("%d commits", trailsLeaderBy)
111111
if s.Leader {
112-
trailsLeaderByText = "_"
112+
trailsLeaderByText = "-"
113113
} else if trailsLeaderBy <= 1 {
114-
trailsLeaderByText = fmt.Sprintf("%d Commit", trailsLeaderBy)
114+
trailsLeaderByText = fmt.Sprintf("%d commit", trailsLeaderBy)
115115
}
116116
result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s\x1f%s\x1f%v\x1f%s\x1f%v\x1f%s",
117117
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, serverHealthData.LastIndex, trailsLeaderByText))
118118
} else {
119119
result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s\x1f%s\x1f%v\x1f%s\x1f%v",
120-
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, "_"))
120+
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, "-"))
121121
}
122122
}
123123

command/operator/raft/listpeers/operator_raft_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestOperatorRaftListPeersCommand(t *testing.T) {
2828
a := agent.NewTestAgent(t, ``)
2929
defer a.Shutdown()
3030

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

3434
// Test the list-peers subcommand directly

0 commit comments

Comments
 (0)