Remove unneeded fields from state output (#11073)

This commit is contained in:
Vishal Nayak 2021-03-10 12:08:12 -05:00 committed by GitHub
parent 170a0800e6
commit 9839e76192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 87 deletions

View File

@ -68,21 +68,10 @@ 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"`

View File

@ -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)

View File

@ -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"`
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() {

View File

@ -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
}

View File

@ -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)

View File

@ -418,10 +418,8 @@ 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,

View File

@ -68,21 +68,10 @@ 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"`