mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 09:42:25 +00:00
CE no-op CensusManager (#27827)
This PR introduces a no-op CensusManager in CE in an effort to simplify overall maintenance. Resolves: VAULT-27562 Enterprise PR: hashicorp/vault-enterprise#6231
This commit is contained in:
@@ -5,12 +5,16 @@
|
||||
|
||||
package vault
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const utilizationBasePath = "utilization"
|
||||
|
||||
// CensusAgent is a stub for OSS
|
||||
type CensusReporter interface{}
|
||||
|
||||
func (c *Core) setupCensusManager() error { return nil }
|
||||
func (c *Core) BillingStart() time.Time { return time.Time{} }
|
||||
func (c *Core) AutomatedLicenseReportingEnabled() bool { return false }
|
||||
func (c *Core) CensusAgent() CensusReporter { return nil }
|
||||
@@ -19,3 +23,9 @@ func (c *Core) StartManualCensusSnapshots() {}
|
||||
func (c *Core) ManualLicenseReportingEnabled() bool { return false }
|
||||
func (c *Core) ManualCensusSnapshotInterval() time.Duration { return time.Duration(0) }
|
||||
func (c *Core) ManualCensusSnapshotRetentionTime() time.Duration { return time.Duration(0) }
|
||||
func (c *Core) StartCensusReports(ctx context.Context) {}
|
||||
func (c *Core) SetRetentionMonths(months int) error { return nil }
|
||||
func (c *Core) ReloadCensusManager(licenseChange bool) error { return nil }
|
||||
func (c *Core) parseCensusManagerConfig(conf *CoreConfig) (CensusManagerConfig, error) {
|
||||
return CensusManagerConfig{}, nil
|
||||
}
|
||||
|
||||
42
vault/census_manager.go
Normal file
42
vault/census_manager.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
//go:build !enterprise
|
||||
|
||||
package vault
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/vault/sdk/logical"
|
||||
)
|
||||
|
||||
// CensusManager provides stub behavior for CE, simplifying the logic between CE
|
||||
// and ENT. This will always be marked active: false.
|
||||
type CensusManager struct {
|
||||
active bool
|
||||
logger hclog.Logger
|
||||
}
|
||||
|
||||
// CensusManagerConfig is empty on CE.
|
||||
type CensusManagerConfig struct{}
|
||||
|
||||
// NewCensusManager sets up the stub CensusManager on CE with active: false.
|
||||
func NewCensusManager(logger hclog.Logger, conf CensusManagerConfig, storage logical.Storage) (*CensusManager, error) {
|
||||
return &CensusManager{
|
||||
active: false,
|
||||
logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// setupCensusManager is a stub on CE.
|
||||
func (c *Core) setupCensusManager(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BillingStart is a stub on CE.
|
||||
func (cm *CensusManager) BillingStart() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
//go:build !enterprise
|
||||
|
||||
package vault
|
||||
|
||||
import "context"
|
||||
|
||||
//go:generate go run github.com/hashicorp/vault/tools/stubmaker
|
||||
|
||||
func (c *Core) StartCensusReports(ctx context.Context) {}
|
||||
func (c *Core) SetRetentionMonths(months int) error { return nil }
|
||||
func (c *Core) ReloadCensusManager(licenseChange bool) error { return nil }
|
||||
@@ -727,6 +727,8 @@ type Core struct {
|
||||
periodicLeaderRefreshInterval time.Duration
|
||||
|
||||
clusterAddrBridge *raft.ClusterAddrBridge
|
||||
|
||||
censusManager *CensusManager
|
||||
}
|
||||
|
||||
func (c *Core) ActiveNodeClockSkewMillis() int64 {
|
||||
@@ -1316,6 +1318,19 @@ func NewCore(conf *CoreConfig) (*Core, error) {
|
||||
c.versionHistory = make(map[string]VaultVersion)
|
||||
}
|
||||
|
||||
// Setup the Census Manager
|
||||
cmConfig, err := c.parseCensusManagerConfig(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmLogger := conf.Logger.Named("reporting")
|
||||
c.allLoggers = append(c.allLoggers, cmLogger)
|
||||
c.censusManager, err = NewCensusManager(cmLogger, cmConfig, NewBarrierView(c.barrier, utilizationBasePath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Events
|
||||
eventsLogger := conf.Logger.Named("events")
|
||||
c.allLoggers = append(c.allLoggers, eventsLogger)
|
||||
@@ -2449,8 +2464,8 @@ func (s standardUnsealStrategy) unseal(ctx context.Context, logger log.Logger, c
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.setupCensusManager(); err != nil {
|
||||
logger.Error("failed to instantiate the license reporting agent", "error", err)
|
||||
if err := c.setupCensusManager(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.StartCensusReports(ctx)
|
||||
|
||||
Reference in New Issue
Block a user