From 0beaa439d67ac2e52500ba849f209c4715e8fd00 Mon Sep 17 00:00:00 2001 From: Vishal Nayak Date: Wed, 10 Mar 2021 12:08:12 -0500 Subject: [PATCH] Remove unneeded fields from state output (#11073) --- api/sys_raft.go | 23 +++-------- command/format.go | 1 - physical/raft/raft_autopilot.go | 40 ++----------------- physical/raft/raft_util.go | 6 --- .../raft/raft_autopilot_test.go | 1 - vault/logical_system_raft.go | 14 +++---- .../hashicorp/vault/api/sys_raft.go | 23 +++-------- 7 files changed, 21 insertions(+), 87 deletions(-) diff --git a/api/sys_raft.go b/api/sys_raft.go index 0e3a241c8f..f0acc38c63 100644 --- a/api/sys_raft.go +++ b/api/sys_raft.go @@ -68,25 +68,14 @@ func (ac *AutopilotConfig) UnmarshalJSON(b []byte) error { return nil } -// AutopilotExecutionStatus represents the current status of the autopilot background go routines -type AutopilotExecutionStatus string - -const ( - AutopilotNotRunning AutopilotExecutionStatus = "not-running" - AutopilotRunning AutopilotExecutionStatus = "running" - AutopilotShuttingDown AutopilotExecutionStatus = "shutting-down" -) - // AutopilotState represents the response of the raft autopilot state API type AutopilotState struct { - ExecutionStatus AutopilotExecutionStatus `mapstructure:"execution_status"` - Healthy bool `mapstructure:"healthy"` - FailureTolerance int `mapstructure:"failure_tolerance"` - OptimisticFailureTolerance int `mapstructure:"optimistic_failure_tolerance"` - Servers map[string]*AutopilotServer `mapstructure:"servers"` - Leader string `mapstructure:"leader"` - Voters []string `mapstructure:"voters"` - NonVoters []string `mapstructure:"non_voters"` + Healthy bool `mapstructure:"healthy"` + FailureTolerance int `mapstructure:"failure_tolerance"` + Servers map[string]*AutopilotServer `mapstructure:"servers"` + Leader string `mapstructure:"leader"` + Voters []string `mapstructure:"voters"` + NonVoters []string `mapstructure:"non_voters"` } // AutopilotServer represents the server blocks in the response of the raft diff --git a/command/format.go b/command/format.go index 4665f21ccb..159f3c036f 100644 --- a/command/format.go +++ b/command/format.go @@ -182,7 +182,6 @@ func (p PrettyFormatter) OutputAutopilotState(ui cli.Ui, data interface{}) { var buffer bytes.Buffer buffer.WriteString(fmt.Sprintf("Healthy: %t\n", state.Healthy)) buffer.WriteString(fmt.Sprintf("Failure Tolerance: %d\n", state.FailureTolerance)) - buffer.WriteString(fmt.Sprintf("Optimistic Failure Tolerance: %d\n", state.OptimisticFailureTolerance)) buffer.WriteString(fmt.Sprintf("Leader: %s\n", state.Leader)) buffer.WriteString("Voters:\n") outputStringSlice(&buffer, " ", state.Voters) diff --git a/physical/raft/raft_autopilot.go b/physical/raft/raft_autopilot.go index 05bbff3262..ff9c84ae89 100644 --- a/physical/raft/raft_autopilot.go +++ b/physical/raft/raft_autopilot.go @@ -464,26 +464,6 @@ func (b *RaftBackend) AutopilotDisabled() bool { return disabled } -// AutopilotExecutionStatus represents the current status of the autopilot background go routines -type AutopilotExecutionStatus string - -const ( - AutopilotNotRunning AutopilotExecutionStatus = "not-running" - AutopilotRunning AutopilotExecutionStatus = "running" - AutopilotShuttingDown AutopilotExecutionStatus = "shutting-down" -) - -func autopilotStatusToStatus(status autopilot.ExecutionStatus) AutopilotExecutionStatus { - switch status { - case autopilot.Running: - return AutopilotRunning - case autopilot.ShuttingDown: - return AutopilotShuttingDown - default: - return AutopilotNotRunning - } -} - func (b *RaftBackend) startFollowerHeartbeatTracker() { b.l.RLock() tickerCh := b.followerHeartbeatTicker.C @@ -523,10 +503,8 @@ func (b *RaftBackend) StopAutopilot() { // AutopilotState represents the health information retrieved from autopilot. type AutopilotState struct { - ExecutionStatus AutopilotExecutionStatus `json:"execution_status"` - Healthy bool `json:"healthy"` - FailureTolerance int `json:"failure_tolerance"` - OptimisticFailureTolerance int `json:"optimistic_failure_tolerance"` + Healthy bool `json:"healthy"` + FailureTolerance int `json:"failure_tolerance"` Servers map[string]*AutopilotServer `json:"servers"` Leader string `json:"leader"` @@ -620,10 +598,6 @@ func autopilotToAPIState(state *autopilot.State) (*AutopilotState, error) { out.Servers[string(id)] = autopilotToAPIServer(srv) } - if err := autopilotToAPIStateEnterprise(state, out); err != nil { - return out, err - } - return out, nil } @@ -666,15 +640,7 @@ func (b *RaftBackend) GetAutopilotServerState(ctx context.Context) (*AutopilotSt return nil, nil } - state, err := autopilotToAPIState(apState) - if err != nil { - return nil, err - } - - apStatus, _ := b.autopilot.IsRunning() - state.ExecutionStatus = autopilotStatusToStatus(apStatus) - - return state, nil + return autopilotToAPIState(apState) } func (b *RaftBackend) DisableAutopilot() { diff --git a/physical/raft/raft_util.go b/physical/raft/raft_util.go index 04e5787773..890c701f7e 100644 --- a/physical/raft/raft_util.go +++ b/physical/raft/raft_util.go @@ -24,12 +24,6 @@ func autopilotToAPIServerEnterprise(_ *autopilot.ServerState, _ *AutopilotServer // noop in oss } -func autopilotToAPIStateEnterprise(state *autopilot.State, apiState *AutopilotState) error { - // Both are same in OSS - apiState.OptimisticFailureTolerance = state.FailureTolerance - return nil -} - func (d *Delegate) autopilotConfigExt() interface{} { return nil } diff --git a/vault/external_tests/raft/raft_autopilot_test.go b/vault/external_tests/raft/raft_autopilot_test.go index 65fb2a4d7a..97c4072eb2 100644 --- a/vault/external_tests/raft/raft_autopilot_test.go +++ b/vault/external_tests/raft/raft_autopilot_test.go @@ -46,7 +46,6 @@ func TestRaft_Autopilot_Stabilization_And_State(t *testing.T) { client := cluster.Cores[0].Client state, err := client.Sys().RaftAutopilotState() require.NoError(t, err) - require.Equal(t, api.AutopilotRunning, state.ExecutionStatus) require.Equal(t, true, state.Healthy) require.Len(t, state.Servers, 1) require.Equal(t, "core-0", state.Servers["core-0"].ID) diff --git a/vault/logical_system_raft.go b/vault/logical_system_raft.go index 852cd60849..08cd536e43 100644 --- a/vault/logical_system_raft.go +++ b/vault/logical_system_raft.go @@ -418,14 +418,12 @@ func (b *SystemBackend) handleStorageRaftAutopilotState() framework.OperationFun return &logical.Response{ Data: map[string]interface{}{ - "execution_status": state.ExecutionStatus, - "healthy": state.Healthy, - "failure_tolerance": state.FailureTolerance, - "optimistic_failure_tolerance": state.OptimisticFailureTolerance, - "servers": state.Servers, - "leader": state.Leader, - "voters": state.Voters, - "non_voters": state.NonVoters, + "healthy": state.Healthy, + "failure_tolerance": state.FailureTolerance, + "servers": state.Servers, + "leader": state.Leader, + "voters": state.Voters, + "non_voters": state.NonVoters, }, }, nil } diff --git a/vendor/github.com/hashicorp/vault/api/sys_raft.go b/vendor/github.com/hashicorp/vault/api/sys_raft.go index 0e3a241c8f..f0acc38c63 100644 --- a/vendor/github.com/hashicorp/vault/api/sys_raft.go +++ b/vendor/github.com/hashicorp/vault/api/sys_raft.go @@ -68,25 +68,14 @@ func (ac *AutopilotConfig) UnmarshalJSON(b []byte) error { return nil } -// AutopilotExecutionStatus represents the current status of the autopilot background go routines -type AutopilotExecutionStatus string - -const ( - AutopilotNotRunning AutopilotExecutionStatus = "not-running" - AutopilotRunning AutopilotExecutionStatus = "running" - AutopilotShuttingDown AutopilotExecutionStatus = "shutting-down" -) - // AutopilotState represents the response of the raft autopilot state API type AutopilotState struct { - ExecutionStatus AutopilotExecutionStatus `mapstructure:"execution_status"` - Healthy bool `mapstructure:"healthy"` - FailureTolerance int `mapstructure:"failure_tolerance"` - OptimisticFailureTolerance int `mapstructure:"optimistic_failure_tolerance"` - Servers map[string]*AutopilotServer `mapstructure:"servers"` - Leader string `mapstructure:"leader"` - Voters []string `mapstructure:"voters"` - NonVoters []string `mapstructure:"non_voters"` + Healthy bool `mapstructure:"healthy"` + FailureTolerance int `mapstructure:"failure_tolerance"` + Servers map[string]*AutopilotServer `mapstructure:"servers"` + Leader string `mapstructure:"leader"` + Voters []string `mapstructure:"voters"` + NonVoters []string `mapstructure:"non_voters"` } // AutopilotServer represents the server blocks in the response of the raft