Skip to content

Commit

Permalink
VAULT-11830: Expand NodeStatusReporter with new fields (#18302)
Browse files Browse the repository at this point in the history
* expand NodeStatusReporter with new fields

* only call IsRaftVoter if using raft storage

* add changelog entry

* fix listeners

* return LogLevel as enum

* update github.com/hashicorp/vault/vault/hcp_link/proto

* add changelog entry

* bump github.com/hashicorp/vault/vault/hcp_link/proto

* go mod tidy
  • Loading branch information
ccapurso authored and AnPucel committed Jan 14, 2023
1 parent b6bf22f commit 0ca1088
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 30 deletions.
3 changes: 3 additions & 0 deletions changelog/18302.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
hcp/status: Expand node-level status information
```
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
38 changes: 38 additions & 0 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down
67 changes: 47 additions & 20 deletions vault/hcp_link/capabilities/node_status/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
}

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(),
listenerAddresses, err := c.NodeStatusGetter.ListenerAddresses()
if err != nil {
return status, err
}

logLevel, err := logging.ParseLogLevel(c.NodeStatusGetter.LogLevel())
if err != nil {
return status, err
}

ns := nodestatus.NodeStatus{
StatusVersion: uint32(Version),
Status: protoRes,
raftStatus := &node_status.RaftStatus{}
if sealStatus.StorageType == "raft" {
raftStatus.IsVoter = c.NodeStatusGetter.IsRaftVoter()
}

return ns, nil
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(),
Hostname: hostInfo.Hostname,
ListenerAddresses: listenerAddresses,
OperatingSystem: hostInfo.OS,
OperatingSystemVersion: hostInfo.PlatformVersion,
LogLevel: node_status.LogLevel(logLevel),
ActiveTime: timestamppb.New(c.NodeStatusGetter.ActiveTime()),
RaftStatus: raftStatus,
}

status.StatusVersion = uint32(Version)
status.Status = protoRes

return status, nil
}
5 changes: 5 additions & 0 deletions vault/hcp_link/internal/wrapped_hcpLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"context"
"time"

"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/physical/raft"
Expand All @@ -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
}

Expand Down

0 comments on commit 0ca1088

Please sign in to comment.