From af5a5eab2b11fe90dcc25c05f62ae6ab67c79081 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 6 Jun 2023 09:51:24 +0000 Subject: [PATCH 01/12] backport of commit 2f94024b356f774d0032ad069babb1a3fce6cfbd --- api/operator_raft.go | 17 +++++ api/operator_raft_test.go | 19 +++++ .../raft/listpeers/operator_raft_list.go | 71 +++++++++++++++++-- .../raft/listpeers/operator_raft_list_test.go | 27 +++++++ 4 files changed, 129 insertions(+), 5 deletions(-) diff --git a/api/operator_raft.go b/api/operator_raft.go index 1da20e899ff5..b59721ee98b6 100644 --- a/api/operator_raft.go +++ b/api/operator_raft.go @@ -119,3 +119,20 @@ 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 +} diff --git a/api/operator_raft_test.go b/api/operator_raft_test.go index ecefaa971920..dc2012c0ff16 100644 --- a/api/operator_raft_test.go +++ b/api/operator_raft_test.go @@ -54,3 +54,22 @@ 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) + } +} diff --git a/command/operator/raft/listpeers/operator_raft_list.go b/command/operator/raft/listpeers/operator_raft_list.go index 98934d8d0eb2..17f92b30033f 100644 --- a/command/operator/raft/listpeers/operator_raft_list.go +++ b/command/operator/raft/listpeers/operator_raft_list.go @@ -21,10 +21,16 @@ type cmd struct { flags *flag.FlagSet http *flags.HTTPFlags help string + + // flags + detailed bool } func (c *cmd) init() { c.flags = flag.NewFlagSet("", flag.ContinueOnError) + c.flags.BoolVar(&c.detailed, "detailed", false, + "Outputs additional information 'commit_index' which is "+ + "the index of the server's last committed Raft log entry.") c.http = &flags.HTTPFlags{} flags.Merge(c.flags, c.http.ClientFlags()) flags.Merge(c.flags, c.http.ServerFlags()) @@ -48,13 +54,22 @@ func (c *cmd) Run(args []string) int { } // Fetch the current configuration. - result, err := raftListPeers(client, c.http.Stale()) - if err != nil { - c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) - return 1 + if c.detailed { + result, err := raftListPeersDetailed(client, c.http.Stale()) + if err != nil { + c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) + return 1 + } + c.UI.Output(result) + } else { + result, err := raftListPeers(client, c.http.Stale()) + if err != nil { + c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) + return 1 + } + c.UI.Output(result) } - c.UI.Output(result) return 0 } @@ -86,6 +101,52 @@ func raftListPeers(client *api.Client, stale bool) (string, error) { return columnize.Format(result, &columnize.Config{Delim: string([]byte{0x1f})}), nil } +func raftListPeersDetailed(client *api.Client, stale bool) (string, error) { + q := &api.QueryOptions{ + AllowStale: stale, + } + reply, err := client.Operator().RaftGetConfiguration(q) + if err != nil { + return "", fmt.Errorf("Failed to retrieve raft configuration: %v", err) + } + + autoPilotReply, err := client.Operator().GetAutoPilotHealth(q) + if err != nil { + return "", fmt.Errorf("Failed to retrieve autopilot health: %v", err) + } + + serverHealthDataMap := make(map[string]api.ServerHealth) + + for _, serverHealthData := range autoPilotReply.Servers { + serverHealthDataMap[serverHealthData.ID] = serverHealthData + } + + // Format it as a nice table. + result := []string{"Node\x1fID\x1fAddress\x1fState\x1fVoter\x1fRaftProtocol\x1fCommitIndex"} + for _, s := range reply.Servers { + raftProtocol := s.ProtocolVersion + + if raftProtocol == "" { + raftProtocol = "<=1" + } + state := "follower" + if s.Leader { + state = "leader" + } + + serverHealthData, ok := serverHealthDataMap[s.ID] + if ok { + 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, serverHealthData.LastIndex)) + } 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, "")) + } + } + + return columnize.Format(result, &columnize.Config{Delim: string([]byte{0x1f})}), nil +} + func (c *cmd) Synopsis() string { return synopsis } diff --git a/command/operator/raft/listpeers/operator_raft_list_test.go b/command/operator/raft/listpeers/operator_raft_list_test.go index 8d53e4945398..18ec43a1b109 100644 --- a/command/operator/raft/listpeers/operator_raft_list_test.go +++ b/command/operator/raft/listpeers/operator_raft_list_test.go @@ -43,6 +43,33 @@ func TestOperatorRaftListPeersCommand(t *testing.T) { } } +func TestOperatorRaftListPeersCommandDetailed(t *testing.T) { + if testing.Short() { + t.Skip("too slow for testing.Short") + } + + t.Parallel() + a := agent.NewTestAgent(t, ``) + defer a.Shutdown() + + expected := fmt.Sprintf("%s %s 127.0.0.1:%d leader true 3", + a.Config.NodeName, a.Config.NodeID, a.Config.ServerPort) + + // Test the list-peers subcommand directly + ui := cli.NewMockUi() + c := New(ui) + args := []string{"-http-addr=" + a.HTTPAddr(), "-detailed"} + + code := c.Run(args) + if code != 0 { + t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) + } + output := strings.TrimSpace(ui.OutputWriter.String()) + if !strings.Contains(output, expected) { + t.Fatalf("bad: %q, %q", output, expected) + } +} + func TestOperatorRaftListPeersCommand_verticalBar(t *testing.T) { if testing.Short() { t.Skip("too slow for testing.Short") From 85449d2546b8e9aa9ed1c76c6c73fe7d5ab0be8f Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 6 Jun 2023 09:56:50 +0000 Subject: [PATCH 02/12] backport of commit 7626d0992dd59f424d893dd462bbde3a9cb0646c --- command/operator/raft/listpeers/operator_raft_list_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/operator/raft/listpeers/operator_raft_list_test.go b/command/operator/raft/listpeers/operator_raft_list_test.go index 18ec43a1b109..a6f314143a3f 100644 --- a/command/operator/raft/listpeers/operator_raft_list_test.go +++ b/command/operator/raft/listpeers/operator_raft_list_test.go @@ -52,7 +52,7 @@ func TestOperatorRaftListPeersCommandDetailed(t *testing.T) { a := agent.NewTestAgent(t, ``) defer a.Shutdown() - expected := fmt.Sprintf("%s %s 127.0.0.1:%d leader true 3", + 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 From 53df02d60b406c0591621941d396a91449d56817 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 6 Jun 2023 11:01:54 +0000 Subject: [PATCH 03/12] backport of commit 79aabc958aed60b2bd97c836529d53a627262124 --- website/content/commands/operator/raft.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/content/commands/operator/raft.mdx b/website/content/commands/operator/raft.mdx index 857a9ee1ac12..7c948c1e14e3 100644 --- a/website/content/commands/operator/raft.mdx +++ b/website/content/commands/operator/raft.mdx @@ -73,6 +73,10 @@ configuration. we recommend setting this option to `true. Default is `false`. +- `-detailed` - Outputs additional information 'commit_index' which is +the index of the server's last committed Raft log entry. +Default is `false`. + ## remove-peer Corresponding HTTP API Endpoint: [\[DELETE\] /v1/operator/raft/peer](/consul/api-docs/operator/raft#delete-raft-peer) From f268323217b5e5e8795a1ae92884311f8f40a5db Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut Date: Tue, 6 Jun 2023 11:14:01 +0000 Subject: [PATCH 04/12] backport of commit 44eee4168b5a0d405636dbcb5b14ee7959334550 --- .changelog/17582.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17582.txt diff --git a/.changelog/17582.txt b/.changelog/17582.txt new file mode 100644 index 000000000000..3beae9d726a0 --- /dev/null +++ b/.changelog/17582.txt @@ -0,0 +1,3 @@ +```release-note:feature +improved consul operator raft list-peers command added -detailed flag which will print CommitIndex in the table in response +``` From 8c1aa8e894c56d459a6ff7245a9c9ca76b803fad Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:42:50 +0530 Subject: [PATCH 05/12] merge commit fa40654 --- .changelog/17582.txt | 2 +- agent/consul/operator_raft_endpoint.go | 7 ++++ agent/consul/operator_raft_endpoint_test.go | 13 +++++++ agent/structs/operator.go | 3 ++ api/operator_raft.go | 3 ++ .../raft/listpeers/operator_raft_list.go | 34 +++++++++++++++++-- .../raft/listpeers/operator_raft_list_test.go | 2 +- website/content/commands/operator/raft.mdx | 10 +++--- 8 files changed, 64 insertions(+), 10 deletions(-) diff --git a/.changelog/17582.txt b/.changelog/17582.txt index 3beae9d726a0..122b9df98116 100644 --- a/.changelog/17582.txt +++ b/.changelog/17582.txt @@ -1,3 +1,3 @@ ```release-note:feature -improved consul operator raft list-peers command added -detailed flag which will print CommitIndex in the table in response +cli: `consul operator raft list-peers` command shows the number of commits each follower is trailing the leader by to aid in troubleshooting. ``` diff --git a/agent/consul/operator_raft_endpoint.go b/agent/consul/operator_raft_endpoint.go index 328f8ff964e0..f5678fffdde5 100644 --- a/agent/consul/operator_raft_endpoint.go +++ b/agent/consul/operator_raft_endpoint.go @@ -45,6 +45,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() @@ -63,6 +69,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) } diff --git a/agent/consul/operator_raft_endpoint_test.go b/agent/consul/operator_raft_endpoint_test.go index be60ec66a317..e4f322130a75 100644 --- a/agent/consul/operator_raft_endpoint_test.go +++ b/agent/consul/operator_raft_endpoint_test.go @@ -47,6 +47,13 @@ func TestOperator_RaftGetConfiguration(t *testing.T) { if len(future.Configuration().Servers) != 1 { t.Fatalf("bad: %v", future.Configuration().Servers) } + + serverIDLastIndexMap := make(map[raft.ServerID]uint64) + + for _, serverState := range s1.autopilot.GetState().Servers { + serverIDLastIndexMap[serverState.Server.ID] = serverState.Stats.LastIndex + } + me := future.Configuration().Servers[0] expected := structs.RaftConfigurationResponse{ Servers: []*structs.RaftServer{ @@ -57,6 +64,7 @@ func TestOperator_RaftGetConfiguration(t *testing.T) { Leader: true, Voter: true, ProtocolVersion: "3", + LastIndex: serverIDLastIndexMap[me.ID], }, }, Index: future.Index(), @@ -110,6 +118,10 @@ func TestOperator_RaftGetConfiguration_ACLDeny(t *testing.T) { if len(future.Configuration().Servers) != 1 { t.Fatalf("bad: %v", future.Configuration().Servers) } + serverIDLastIndexMap := make(map[raft.ServerID]uint64) + for _, serverState := range s1.autopilot.GetState().Servers { + serverIDLastIndexMap[serverState.Server.ID] = serverState.Stats.LastIndex + } me := future.Configuration().Servers[0] expected := structs.RaftConfigurationResponse{ Servers: []*structs.RaftServer{ @@ -120,6 +132,7 @@ func TestOperator_RaftGetConfiguration_ACLDeny(t *testing.T) { Leader: true, Voter: true, ProtocolVersion: "3", + LastIndex: serverIDLastIndexMap[me.ID], }, }, Index: future.Index(), diff --git a/agent/structs/operator.go b/agent/structs/operator.go index be4507c325a8..5cb1a92ca935 100644 --- a/agent/structs/operator.go +++ b/agent/structs/operator.go @@ -31,6 +31,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 diff --git a/api/operator_raft.go b/api/operator_raft.go index b59721ee98b6..7147714b600a 100644 --- a/api/operator_raft.go +++ b/api/operator_raft.go @@ -25,6 +25,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. diff --git a/command/operator/raft/listpeers/operator_raft_list.go b/command/operator/raft/listpeers/operator_raft_list.go index 17f92b30033f..43b45d0efdf3 100644 --- a/command/operator/raft/listpeers/operator_raft_list.go +++ b/command/operator/raft/listpeers/operator_raft_list.go @@ -82,8 +82,24 @@ func raftListPeers(client *api.Client, stale bool) (string, error) { return "", fmt.Errorf("Failed to retrieve raft configuration: %v", err) } + leaderLastCommitIndex := uint64(0) + serverIdLastIndexMap := make(map[string]uint64) + + for _, raftServer := range reply.Servers { + serverIdLastIndexMap[raftServer.ID] = raftServer.LastIndex + } + + for _, s := range reply.Servers { + if s.Leader { + lastIndex, ok := serverIdLastIndexMap[s.ID] + if ok { + leaderLastCommitIndex = lastIndex + } + } + } + // Format it as a nice table. - result := []string{"Node\x1fID\x1fAddress\x1fState\x1fVoter\x1fRaftProtocol"} + result := []string{"Node\x1fID\x1fAddress\x1fState\x1fVoter\x1fRaftProtocol\x1fCommit Index\x1fTrails Leader By"} for _, s := range reply.Servers { raftProtocol := s.ProtocolVersion @@ -94,8 +110,20 @@ func raftListPeers(client *api.Client, stale bool) (string, error) { if s.Leader { state = "leader" } - result = append(result, fmt.Sprintf("%s\x1f%s\x1f%s\x1f%s\x1f%v\x1f%s", - s.Node, s.ID, s.Address, state, s.Voter, raftProtocol)) + + trailsLeaderByText := "-" + serverLastIndex, ok := serverIdLastIndexMap[s.ID] + if ok { + 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, serverLastIndex, trailsLeaderByText)) } return columnize.Format(result, &columnize.Config{Delim: string([]byte{0x1f})}), nil diff --git a/command/operator/raft/listpeers/operator_raft_list_test.go b/command/operator/raft/listpeers/operator_raft_list_test.go index a6f314143a3f..3cb9597b13d5 100644 --- a/command/operator/raft/listpeers/operator_raft_list_test.go +++ b/command/operator/raft/listpeers/operator_raft_list_test.go @@ -25,7 +25,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", + 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 diff --git a/website/content/commands/operator/raft.mdx b/website/content/commands/operator/raft.mdx index 7c948c1e14e3..7c888e0b46cf 100644 --- a/website/content/commands/operator/raft.mdx +++ b/website/content/commands/operator/raft.mdx @@ -46,10 +46,10 @@ Usage: `consul operator raft list-peers -stale=[true|false]` The output looks like this: ```text -Node ID Address State Voter RaftProtocol -alice 127.0.0.1:8300 127.0.0.1:8300 follower true 2 -bob 127.0.0.2:8300 127.0.0.2:8300 leader true 3 -carol 127.0.0.3:8300 127.0.0.3:8300 follower true 2 +Node ID Address State Voter RaftProtocol Commit Index Trails Leader By +alice 127.0.0.1:8300 127.0.0.1:8300 follower true 2 1167 0 commits +bob 127.0.0.2:8300 127.0.0.2:8300 leader true 3 1167 - +carol 127.0.0.3:8300 127.0.0.3:8300 follower true 2 1159 8 commits ``` `Node` is the node name of the server, as known to Consul, or "(unknown)" if @@ -70,7 +70,7 @@ configuration. - `-stale` - Enables non-leader servers to provide cluster state information. If the cluster is in an outage state without a leader, - we recommend setting this option to `true. + we recommend setting this option to `true`. Default is `false`. - `-detailed` - Outputs additional information 'commit_index' which is From b99e14862e323682b0b03fefb81118f0ca91f2a2 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:42:50 +0530 Subject: [PATCH 06/12] fix merge conf --- .../raft/listpeers/operator_raft_list.go | 48 +------------------ 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/command/operator/raft/listpeers/operator_raft_list.go b/command/operator/raft/listpeers/operator_raft_list.go index 43b45d0efdf3..b1fe5ae77d26 100644 --- a/command/operator/raft/listpeers/operator_raft_list.go +++ b/command/operator/raft/listpeers/operator_raft_list.go @@ -55,7 +55,7 @@ func (c *cmd) Run(args []string) int { // Fetch the current configuration. if c.detailed { - result, err := raftListPeersDetailed(client, c.http.Stale()) + result, err := raftListPeers(client, c.http.Stale()) if err != nil { c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) return 1 @@ -129,52 +129,6 @@ func raftListPeers(client *api.Client, stale bool) (string, error) { return columnize.Format(result, &columnize.Config{Delim: string([]byte{0x1f})}), nil } -func raftListPeersDetailed(client *api.Client, stale bool) (string, error) { - q := &api.QueryOptions{ - AllowStale: stale, - } - reply, err := client.Operator().RaftGetConfiguration(q) - if err != nil { - return "", fmt.Errorf("Failed to retrieve raft configuration: %v", err) - } - - autoPilotReply, err := client.Operator().GetAutoPilotHealth(q) - if err != nil { - return "", fmt.Errorf("Failed to retrieve autopilot health: %v", err) - } - - serverHealthDataMap := make(map[string]api.ServerHealth) - - for _, serverHealthData := range autoPilotReply.Servers { - serverHealthDataMap[serverHealthData.ID] = serverHealthData - } - - // Format it as a nice table. - result := []string{"Node\x1fID\x1fAddress\x1fState\x1fVoter\x1fRaftProtocol\x1fCommitIndex"} - for _, s := range reply.Servers { - raftProtocol := s.ProtocolVersion - - if raftProtocol == "" { - raftProtocol = "<=1" - } - state := "follower" - if s.Leader { - state = "leader" - } - - serverHealthData, ok := serverHealthDataMap[s.ID] - if ok { - 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, serverHealthData.LastIndex)) - } 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, "")) - } - } - - return columnize.Format(result, &columnize.Config{Delim: string([]byte{0x1f})}), nil -} - func (c *cmd) Synopsis() string { return synopsis } From 26573f9bbe4b669ff4434d1c4d3cc4eb577f8e62 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:42:50 +0530 Subject: [PATCH 07/12] [NET-3865] [Supportability] Additional Information in the output of 'consul operator raft list-peers' (#17582) * init * fix tests * added -detailed in docs * added change log * fix doc * checking for entry in map * fix tests * removed detailed flag * removed detailed flag * revert unwanted changes * removed unwanted changes * updated change log * pr review comment changes * pr comment changes single API instead of two * fix change log * fix tests * fix tests * fix test operator raft endpoint test * Update .changelog/17582.txt Co-authored-by: Semir Patel * nits * updated docs --------- Co-authored-by: Semir Patel From 7917d5b86afb681e79fe49ec034519960810564c Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:42:50 +0530 Subject: [PATCH 08/12] [NET-3865] [Supportability] Additional Information in the output of 'consul operator raft list-peers' (#17582) * init * fix tests * added -detailed in docs * added change log * fix doc * checking for entry in map * fix tests * removed detailed flag * removed detailed flag * revert unwanted changes * removed unwanted changes * updated change log * pr review comment changes * pr comment changes single API instead of two * fix change log * fix tests * fix tests * fix test operator raft endpoint test * Update .changelog/17582.txt Co-authored-by: Semir Patel * nits * updated docs --------- Co-authored-by: Semir Patel From 9077901939ecfca14f4aff8aa0cb7ba24a28c8d9 Mon Sep 17 00:00:00 2001 From: Ashesh Vidyut <134911583+absolutelightning@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:42:50 +0530 Subject: [PATCH 09/12] resolve diff --- api/operator_raft.go | 17 --------------- api/operator_raft_test.go | 19 ----------------- .../raft/listpeers/operator_raft_list.go | 21 ------------------- 3 files changed, 57 deletions(-) diff --git a/api/operator_raft.go b/api/operator_raft.go index 7147714b600a..f0ffa1522872 100644 --- a/api/operator_raft.go +++ b/api/operator_raft.go @@ -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 -} diff --git a/api/operator_raft_test.go b/api/operator_raft_test.go index dc2012c0ff16..ecefaa971920 100644 --- a/api/operator_raft_test.go +++ b/api/operator_raft_test.go @@ -54,22 +54,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) - } -} diff --git a/command/operator/raft/listpeers/operator_raft_list.go b/command/operator/raft/listpeers/operator_raft_list.go index b1fe5ae77d26..b1c16e102063 100644 --- a/command/operator/raft/listpeers/operator_raft_list.go +++ b/command/operator/raft/listpeers/operator_raft_list.go @@ -21,16 +21,10 @@ type cmd struct { flags *flag.FlagSet http *flags.HTTPFlags help string - - // flags - detailed bool } func (c *cmd) init() { c.flags = flag.NewFlagSet("", flag.ContinueOnError) - c.flags.BoolVar(&c.detailed, "detailed", false, - "Outputs additional information 'commit_index' which is "+ - "the index of the server's last committed Raft log entry.") c.http = &flags.HTTPFlags{} flags.Merge(c.flags, c.http.ClientFlags()) flags.Merge(c.flags, c.http.ServerFlags()) @@ -54,21 +48,6 @@ func (c *cmd) Run(args []string) int { } // Fetch the current configuration. - if c.detailed { - result, err := raftListPeers(client, c.http.Stale()) - if err != nil { - c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) - return 1 - } - c.UI.Output(result) - } else { - result, err := raftListPeers(client, c.http.Stale()) - if err != nil { - c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) - return 1 - } - c.UI.Output(result) - } return 0 } From 6d6dc5b3da6ff13eefb1863cf804ec8670e12aac Mon Sep 17 00:00:00 2001 From: absolutelightning Date: Sun, 18 Jun 2023 09:17:01 +0530 Subject: [PATCH 10/12] fix merge conf --- command/operator/raft/listpeers/operator_raft_list.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/command/operator/raft/listpeers/operator_raft_list.go b/command/operator/raft/listpeers/operator_raft_list.go index b1c16e102063..ef951bdc7973 100644 --- a/command/operator/raft/listpeers/operator_raft_list.go +++ b/command/operator/raft/listpeers/operator_raft_list.go @@ -48,6 +48,13 @@ func (c *cmd) Run(args []string) int { } // Fetch the current configuration. + result, err := raftListPeers(client, c.http.Stale()) + if err != nil { + c.UI.Error(fmt.Sprintf("Error getting peers: %v", err)) + return 1 + } + + c.UI.Output(result) return 0 } From 94335470b9cd394c1a61e1ca4f6c20ccf3d0e3dc Mon Sep 17 00:00:00 2001 From: absolutelightning Date: Sun, 18 Jun 2023 09:17:58 +0530 Subject: [PATCH 11/12] fix merge conf --- .../raft/listpeers/operator_raft_list.go | 1 - .../raft/listpeers/operator_raft_list_test.go | 27 ------------------- 2 files changed, 28 deletions(-) diff --git a/command/operator/raft/listpeers/operator_raft_list.go b/command/operator/raft/listpeers/operator_raft_list.go index ef951bdc7973..a54ccb9d3ea2 100644 --- a/command/operator/raft/listpeers/operator_raft_list.go +++ b/command/operator/raft/listpeers/operator_raft_list.go @@ -55,7 +55,6 @@ func (c *cmd) Run(args []string) int { } c.UI.Output(result) - return 0 } diff --git a/command/operator/raft/listpeers/operator_raft_list_test.go b/command/operator/raft/listpeers/operator_raft_list_test.go index 3cb9597b13d5..c40ae8c48d7b 100644 --- a/command/operator/raft/listpeers/operator_raft_list_test.go +++ b/command/operator/raft/listpeers/operator_raft_list_test.go @@ -43,33 +43,6 @@ func TestOperatorRaftListPeersCommand(t *testing.T) { } } -func TestOperatorRaftListPeersCommandDetailed(t *testing.T) { - if testing.Short() { - t.Skip("too slow for testing.Short") - } - - t.Parallel() - a := agent.NewTestAgent(t, ``) - defer a.Shutdown() - - 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 - ui := cli.NewMockUi() - c := New(ui) - args := []string{"-http-addr=" + a.HTTPAddr(), "-detailed"} - - code := c.Run(args) - if code != 0 { - t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) - } - output := strings.TrimSpace(ui.OutputWriter.String()) - if !strings.Contains(output, expected) { - t.Fatalf("bad: %q, %q", output, expected) - } -} - func TestOperatorRaftListPeersCommand_verticalBar(t *testing.T) { if testing.Short() { t.Skip("too slow for testing.Short") From 7ac76c0f69a14d025017797bb9b793b20535f7b2 Mon Sep 17 00:00:00 2001 From: absolutelightning Date: Sun, 18 Jun 2023 09:38:49 +0530 Subject: [PATCH 12/12] removed detailed flag --- website/content/commands/operator/raft.mdx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/website/content/commands/operator/raft.mdx b/website/content/commands/operator/raft.mdx index 7c888e0b46cf..25dea30ba62f 100644 --- a/website/content/commands/operator/raft.mdx +++ b/website/content/commands/operator/raft.mdx @@ -73,10 +73,6 @@ configuration. we recommend setting this option to `true`. Default is `false`. -- `-detailed` - Outputs additional information 'commit_index' which is -the index of the server's last committed Raft log entry. -Default is `false`. - ## remove-peer Corresponding HTTP API Endpoint: [\[DELETE\] /v1/operator/raft/peer](/consul/api-docs/operator/raft#delete-raft-peer)