Add performance standby status to status output (#5192)

* Add performance standby status to status output

* Update ha.go
This commit is contained in:
Brian Kassouf 2018-08-27 10:01:07 -07:00 committed by GitHub
parent 5406f1952a
commit d3017e259f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 15 deletions

View File

@ -19,8 +19,10 @@ func (c *Sys) Leader() (*LeaderResponse, error) {
} }
type LeaderResponse struct { type LeaderResponse struct {
HAEnabled bool `json:"ha_enabled"` HAEnabled bool `json:"ha_enabled"`
IsSelf bool `json:"is_self"` IsSelf bool `json:"is_self"`
LeaderAddress string `json:"leader_address"` LeaderAddress string `json:"leader_address"`
LeaderClusterAddress string `json:"leader_cluster_address"` LeaderClusterAddress string `json:"leader_cluster_address"`
PerfStandby bool `json:"performance_standby"`
PerfStandbyLastRemoteWAL uint64 `json:"performance_standby_last_remote_wal"`
} }

View File

@ -367,6 +367,11 @@ func OutputSealStatus(ui cli.Ui, client *api.Client, status *api.SealStatusRespo
if showLeaderAddr { if showLeaderAddr {
out = append(out, fmt.Sprintf("Active Node Address | %s", leaderStatus.LeaderAddress)) out = append(out, fmt.Sprintf("Active Node Address | %s", leaderStatus.LeaderAddress))
} }
if leaderStatus.PerfStandby {
out = append(out, fmt.Sprintf("Performance Standby Node | %t", leaderStatus.PerfStandby))
out = append(out, fmt.Sprintf("Performance Standby Last Remote WAL | %d", leaderStatus.PerfStandbyLastRemoteWAL))
}
} }
} }

View File

@ -29,18 +29,25 @@ func handleSysLeaderGet(core *vault.Core, w http.ResponseWriter, r *http.Request
respondError(w, http.StatusInternalServerError, err) respondError(w, http.StatusInternalServerError, err)
return return
} }
resp := &LeaderResponse{
respondOk(w, &LeaderResponse{
HAEnabled: haEnabled, HAEnabled: haEnabled,
IsSelf: isLeader, IsSelf: isLeader,
LeaderAddress: address, LeaderAddress: address,
LeaderClusterAddress: clusterAddr, LeaderClusterAddress: clusterAddr,
}) PerfStandby: core.PerfStandby(),
}
if resp.PerfStandby {
resp.PerfStandbyLastRemoteWAL = vault.LastRemoteWAL(core)
}
respondOk(w, resp)
} }
type LeaderResponse struct { type LeaderResponse struct {
HAEnabled bool `json:"ha_enabled"` HAEnabled bool `json:"ha_enabled"`
IsSelf bool `json:"is_self"` IsSelf bool `json:"is_self"`
LeaderAddress string `json:"leader_address"` LeaderAddress string `json:"leader_address"`
LeaderClusterAddress string `json:"leader_cluster_address"` LeaderClusterAddress string `json:"leader_cluster_address"`
PerfStandby bool `json:"performance_standby"`
PerfStandbyLastRemoteWAL uint64 `json:"performance_standby_last_remote_wal"`
} }

View File

@ -1,6 +1,7 @@
package http package http
import ( import (
"encoding/json"
"net/http" "net/http"
"reflect" "reflect"
"testing" "testing"
@ -20,10 +21,12 @@ func TestSysLeader_get(t *testing.T) {
var actual map[string]interface{} var actual map[string]interface{}
expected := map[string]interface{}{ expected := map[string]interface{}{
"ha_enabled": false, "ha_enabled": false,
"is_self": false, "is_self": false,
"leader_address": "", "leader_address": "",
"leader_cluster_address": "", "leader_cluster_address": "",
"performance_standby": false,
"performance_standby_last_remote_wal": json.Number("0"),
} }
testResponseStatus(t, resp, 200) testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual) testResponseBody(t, resp, &actual)

View File

@ -169,6 +169,7 @@ type Core struct {
sealed *uint32 sealed *uint32
standby bool standby bool
perfStandby bool
standbyDoneCh chan struct{} standbyDoneCh chan struct{}
standbyStopCh chan struct{} standbyStopCh chan struct{}
manualStepDownCh chan struct{} manualStepDownCh chan struct{}

View File

@ -61,6 +61,14 @@ func (c *Core) Standby() (bool, error) {
return standby, nil return standby, nil
} }
// PerfStandby checks if the vault is a performance standby
func (c *Core) PerfStandby() bool {
c.stateLock.RLock()
perfStandby := c.perfStandby
c.stateLock.RUnlock()
return perfStandby
}
// Leader is used to get the current active leader // Leader is used to get the current active leader
func (c *Core) Leader() (isLeader bool, leaderAddr, clusterAddr string, err error) { func (c *Core) Leader() (isLeader bool, leaderAddr, clusterAddr string, err error) {
// Check if HA enabled. We don't need the lock for this check as it's set // Check if HA enabled. We don't need the lock for this check as it's set