diff --git a/changelog/18302.txt b/changelog/18302.txt new file mode 100644 index 000000000..1f4b69dc8 --- /dev/null +++ b/changelog/18302.txt @@ -0,0 +1,3 @@ +```release-note:improvement +hcp/status: Expand node-level status information +``` diff --git a/go.sum b/go.sum index c112eea1f..fcc758021 100644 --- a/go.sum +++ b/go.sum @@ -1171,16 +1171,6 @@ github.com/hashicorp/vault-plugin-secrets-terraform v0.6.0/go.mod h1:GzYAJYytgbN github.com/hashicorp/vault-testing-stepwise v0.1.1/go.mod h1:3vUYn6D0ZadvstNO3YQQlIcp7u1a19MdoOC0NQ0yaOE= github.com/hashicorp/vault-testing-stepwise v0.1.2 h1:3obC/ziAPGnsz2IQxr5e4Ayb7tu7WL6pm6mmZ5gwhhs= github.com/hashicorp/vault-testing-stepwise v0.1.2/go.mod h1:TeU6B+5NqxUjto+Zey+QQEH1iywuHn0ciHZNYh4q3uI= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20221209165735-a2eed407e08d h1:U692VbDl6ww5GQsNFClJVFJDaPeuqtDt1Mwqf21KYek= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20221209165735-a2eed407e08d/go.mod h1:a2crHoMWwY6aiL8GWT8hYj7vKD64uX0EdRPbnsHF5wU= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20221213220056-b0613b59f419 h1:yl6f//YTaTTGKJwyOpRe7v1DDPrzP+NErwgnef6qx7A= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20221213220056-b0613b59f419/go.mod h1:a2crHoMWwY6aiL8GWT8hYj7vKD64uX0EdRPbnsHF5wU= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230103211812-c28545e74f94 h1:Rx4Q2/mOPqJuanzwZYttDkWjdibPv3UpvsvKmOkl6h4= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230103211812-c28545e74f94/go.mod h1:a2crHoMWwY6aiL8GWT8hYj7vKD64uX0EdRPbnsHF5wU= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230105183308-048241517ffb h1:PgXcBszV61BvxD0wZzm4QCz9btgTWX74NO4be6S2afU= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230105183308-048241517ffb/go.mod h1:a2crHoMWwY6aiL8GWT8hYj7vKD64uX0EdRPbnsHF5wU= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230106184443-96cfe11e7051 h1:cMQoRbIUMhbM0NsmP6hH3S3ZmAPVgic3g3L8Z55rXCI= -github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230106184443-96cfe11e7051/go.mod h1:a2crHoMWwY6aiL8GWT8hYj7vKD64uX0EdRPbnsHF5wU= github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230106203127-9eaf26716342 h1:9cMwZnaAV/lKs8EZsvBF00wPt350wD3sg/xqWGeN4gM= github.com/hashicorp/vault/vault/hcp_link/proto v0.0.0-20230106203127-9eaf26716342/go.mod h1:a2crHoMWwY6aiL8GWT8hYj7vKD64uX0EdRPbnsHF5wU= github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 h1:O/pT5C1Q3mVXMyuqg7yuAWUg/jMZR1/0QTzTRdNR6Uw= diff --git a/vault/core.go b/vault/core.go index bcfec5baa..8252e1bee 100644 --- a/vault/core.go +++ b/vault/core.go @@ -3082,6 +3082,11 @@ func (c *Core) LogFormat() string { return conf.(*server.Config).LogFormat } +// LogLevel returns the log level provided by level provided by config, CLI flag, or env +func (c *Core) LogLevel() string { + return c.logLevel +} + // MetricsHelper returns the global metrics helper which allows external // packages to access Vault's internal metrics. func (c *Core) MetricsHelper() *metricsutil.MetricsHelper { @@ -3707,6 +3712,39 @@ func (c *Core) GetHCPLinkStatus() (string, string) { return status, resourceID } +// ListenerAddresses provides a slice of configured listener addresses +func (c *Core) ListenerAddresses() ([]string, error) { + addresses := make([]string, 0) + + conf := c.rawConfig.Load() + if conf == nil { + return nil, fmt.Errorf("failed to load core raw config") + } + + listeners := conf.(*server.Config).Listeners + if listeners == nil { + return nil, fmt.Errorf("no listener configured") + } + + for _, listener := range listeners { + addresses = append(addresses, listener.Address) + } + + return addresses, nil +} + +// IsRaftVoter specifies whether the node is a raft voter which is +// always false if raft storage is not in use. +func (c *Core) IsRaftVoter() bool { + raftInfo := c.raftInfo.Load().(*raftInformation) + + if raftInfo == nil { + return false + } + + return !raftInfo.nonVoter +} + func (c *Core) HAEnabled() bool { return c.ha != nil && c.ha.HAEnabled() } diff --git a/vault/hcp_link/capabilities/node_status/node_status.go b/vault/hcp_link/capabilities/node_status/node_status.go index 31ea3725c..8fb408cac 100644 --- a/vault/hcp_link/capabilities/node_status/node_status.go +++ b/vault/hcp_link/capabilities/node_status/node_status.go @@ -4,8 +4,11 @@ import ( "context" "github.com/hashicorp/hcp-link/pkg/nodestatus" + "github.com/hashicorp/vault/helper/logging" "github.com/hashicorp/vault/vault/hcp_link/internal" "github.com/hashicorp/vault/vault/hcp_link/proto/node_status" + "github.com/shirou/gopsutil/v3/host" + "google.golang.org/protobuf/types/known/timestamppb" ) var ( @@ -26,29 +29,53 @@ func (c *NodeStatusReporter) GetNodeStatus(ctx context.Context) (nodestatus.Node } replState := c.NodeStatusGetter.ReplicationState() + hostInfo, err := host.InfoWithContext(ctx) + if err != nil { + return status, err + } + + listenerAddresses, err := c.NodeStatusGetter.ListenerAddresses() + if err != nil { + return status, err + } + + logLevel, err := logging.ParseLogLevel(c.NodeStatusGetter.LogLevel()) + if err != nil { + return status, err + } + + raftStatus := &node_status.RaftStatus{} + if sealStatus.StorageType == "raft" { + raftStatus.IsVoter = c.NodeStatusGetter.IsRaftVoter() + } protoRes := &node_status.LinkedClusterNodeStatusResponse{ - Type: sealStatus.Type, - Initialized: sealStatus.Initialized, - Sealed: sealStatus.Sealed, - T: int64(sealStatus.T), - N: int64(sealStatus.N), - Progress: int64(sealStatus.Progress), - Nonce: sealStatus.Nonce, - Version: sealStatus.Version, - BuildDate: sealStatus.BuildDate, - Migration: sealStatus.Migration, - ClusterID: sealStatus.ClusterID, - ClusterName: sealStatus.ClusterName, - RecoverySeal: sealStatus.RecoverySeal, - StorageType: sealStatus.StorageType, - ReplicationState: replState.StateStrings(), + Type: sealStatus.Type, + Initialized: sealStatus.Initialized, + Sealed: sealStatus.Sealed, + T: int64(sealStatus.T), + N: int64(sealStatus.N), + Progress: int64(sealStatus.Progress), + Nonce: sealStatus.Nonce, + Version: sealStatus.Version, + BuildDate: sealStatus.BuildDate, + Migration: sealStatus.Migration, + ClusterID: sealStatus.ClusterID, + ClusterName: sealStatus.ClusterName, + RecoverySeal: sealStatus.RecoverySeal, + StorageType: sealStatus.StorageType, + ReplicationState: replState.StateStrings(), + Hostname: hostInfo.Hostname, + ListenerAddresses: listenerAddresses, + OperatingSystem: hostInfo.OS, + OperatingSystemVersion: hostInfo.PlatformVersion, + LogLevel: node_status.LogLevel(logLevel), + ActiveTime: timestamppb.New(c.NodeStatusGetter.ActiveTime()), + RaftStatus: raftStatus, } - ns := nodestatus.NodeStatus{ - StatusVersion: uint32(Version), - Status: protoRes, - } + status.StatusVersion = uint32(Version) + status.Status = protoRes - return ns, nil + return status, nil } diff --git a/vault/hcp_link/internal/wrapped_hcpLink.go b/vault/hcp_link/internal/wrapped_hcpLink.go index 98b0bf4e0..6f5de4ab0 100644 --- a/vault/hcp_link/internal/wrapped_hcpLink.go +++ b/vault/hcp_link/internal/wrapped_hcpLink.go @@ -2,6 +2,7 @@ package internal import ( "context" + "time" "github.com/hashicorp/vault/helper/namespace" "github.com/hashicorp/vault/physical/raft" @@ -11,7 +12,11 @@ import ( ) type WrappedCoreNodeStatus interface { + ActiveTime() time.Time GetSealStatus(ctx context.Context) (*vault.SealStatusResponse, error) + IsRaftVoter() bool + ListenerAddresses() ([]string, error) + LogLevel() string ReplicationState() consts.ReplicationState }