mirror of
https://github.com/hashicorp/vault.git
synced 2025-12-16 15:01:13 +01:00
Add performance standby status to status output (#5192)
* Add performance standby status to status output * Update ha.go
This commit is contained in:
parent
5406f1952a
commit
d3017e259f
@ -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"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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{}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user