Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET-3865] [Supportability] Additional Information in the output of 'consul operator raft list-peers' #17582

Merged
merged 30 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2f94024
init
absolutelightning Jun 6, 2023
7626d09
fix tests
absolutelightning Jun 6, 2023
79aabc9
added -detailed in docs
absolutelightning Jun 6, 2023
44eee41
added change log
absolutelightning Jun 6, 2023
1390353
Merge branch 'main' into asheshvidyut/NET-3865
absolutelightning Jun 6, 2023
d118518
fix doc
absolutelightning Jun 6, 2023
d46a074
checking for entry in map
absolutelightning Jun 7, 2023
539dbc7
fix tests
absolutelightning Jun 7, 2023
604b616
removed detailed flag
absolutelightning Jun 7, 2023
3a63b3d
removed detailed flag
absolutelightning Jun 7, 2023
008946c
revert unwanted changes
absolutelightning Jun 7, 2023
509062e
removed unwanted changes
absolutelightning Jun 7, 2023
cf22ea5
updated change log
absolutelightning Jun 7, 2023
eb69358
Merge branch 'main' into asheshvidyut/NET-3865
absolutelightning Jun 7, 2023
5c2a587
pr review comment changes
absolutelightning Jun 8, 2023
8e1f728
pr comment changes single API instead of two
absolutelightning Jun 8, 2023
360ab9e
Merge branch 'asheshvidyut/NET-3865' of github.com:hashicorp/consul i…
absolutelightning Jun 8, 2023
dc25344
fix change log
absolutelightning Jun 8, 2023
c461f59
Merge branch 'main' into asheshvidyut/NET-3865
absolutelightning Jun 8, 2023
3631708
fix tests
absolutelightning Jun 8, 2023
5d479e8
Merge branch 'asheshvidyut/NET-3865' of github.com:hashicorp/consul i…
absolutelightning Jun 8, 2023
40dc1e1
fix tests
absolutelightning Jun 8, 2023
e7afa34
fix test operator raft endpoint test
absolutelightning Jun 9, 2023
8c1bab4
Update .changelog/17582.txt
absolutelightning Jun 9, 2023
6b76d59
nits
absolutelightning Jun 9, 2023
c001e59
Merge branch 'asheshvidyut/NET-3865' of github.com:hashicorp/consul i…
absolutelightning Jun 9, 2023
64e3b0a
Merge branch 'main' into asheshvidyut/NET-3865
absolutelightning Jun 14, 2023
7f8d9d8
updated docs
absolutelightning Jun 14, 2023
fdad3bb
Merge branch 'asheshvidyut/NET-3865' of github.com:hashicorp/consul i…
absolutelightning Jun 14, 2023
1adcb15
Merge branch 'main' into asheshvidyut/NET-3865
absolutelightning Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pr comment changes single API instead of two
  • Loading branch information
absolutelightning committed Jun 8, 2023
commit 8e1f7285d00d968130d98f2d857e7839c5cf2013
7 changes: 7 additions & 0 deletions agent/consul/operator_raft_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func (op *Operator) RaftGetConfiguration(args *structs.DCSpecificRequest, reply
serverMap[raft.ServerAddress(addr)] = member
}

serverIDLastIndexMap := make(map[raft.ServerID]uint64)

for _, serverState := range op.srv.autopilot.GetState().Servers {
serverIDLastIndexMap[serverState.Server.ID] = serverState.Stats.LastIndex
}

// Fill out the reply.
leader := op.srv.raft.Leader()
reply.Index = future.Index()
Expand All @@ -66,6 +72,7 @@ func (op *Operator) RaftGetConfiguration(args *structs.DCSpecificRequest, reply
Leader: server.Address == leader,
Voter: server.Suffrage == raft.Voter,
ProtocolVersion: raftProtocolVersion,
LastIndex: serverIDLastIndexMap[server.ID],
}
reply.Servers = append(reply.Servers, entry)
}
Expand Down
3 changes: 3 additions & 0 deletions agent/structs/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type RaftServer struct {
// it's a non-voting server, which will be added in a future release of
// Consul.
Voter bool

// LastIndex is the last log index this server has a record of in its Raft log.
LastIndex uint64
}

// RaftConfigurationResponse is returned when querying for the current Raft
Expand Down
3 changes: 3 additions & 0 deletions api/operator_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type RaftServer struct {
// it's a non-voting server, which will be added in a future release of
// Consul.
Voter bool

// LastIndex is the last log index this server has a record of in its Raft log.
LastIndex uint64
}

// RaftConfiguration is returned when querying for the current Raft configuration.
Expand Down
21 changes: 8 additions & 13 deletions command/operator/raft/listpeers/operator_raft_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,18 @@ func raftListPeers(client *api.Client, stale bool) (string, error) {
return "", fmt.Errorf("Failed to retrieve raft configuration: %v", err)
}

autoPilotReply, err := client.Operator().AutopilotServerHealth(q)
if err != nil {
return "", fmt.Errorf("Failed to retrieve autopilot health: %v", err)
}

serverHealthDataMap := make(map[string]api.ServerHealth)
leaderLastCommitIndex := uint64(0)
serverIdLastIndexMap := make(map[string]uint64)

for _, serverHealthData := range autoPilotReply.Servers {
serverHealthDataMap[serverHealthData.ID] = serverHealthData
for _, raftServer := range reply.Servers {
serverIdLastIndexMap[raftServer.ID] = raftServer.LastIndex
}

for _, s := range reply.Servers {
if s.Leader {
serverHealthDataLeader, ok := serverHealthDataMap[s.ID]
lastIndex, ok := serverIdLastIndexMap[s.ID]
if ok {
leaderLastCommitIndex = serverHealthDataLeader.LastIndex
leaderLastCommitIndex = lastIndex
}
}
}
Expand All @@ -104,17 +99,17 @@ func raftListPeers(client *api.Client, stale bool) (string, error) {
state = "leader"
}

serverHealthData, ok := serverHealthDataMap[s.ID]
serverLastIndex, ok := serverIdLastIndexMap[s.ID]
if ok {
trailsLeaderBy := leaderLastCommitIndex - serverHealthData.LastIndex
trailsLeaderBy := leaderLastCommitIndex - serverLastIndex
trailsLeaderByText := fmt.Sprintf("%d commits", trailsLeaderBy)
if s.Leader {
trailsLeaderByText = "-"
} else if trailsLeaderBy <= 1 {
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))
s.Node, s.ID, s.Address, state, s.Voter, raftProtocol, serverLastIndex, 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, "-"))
Expand Down