Refactor reporter for unseal setup (#20296)
This commit is contained in:
parent
d7f67b8856
commit
8001d76e28
|
@ -1107,7 +1107,7 @@ func (c *Core) setupActivityLog(ctx context.Context, wg *sync.WaitGroup) error {
|
|||
}(manager.retentionMonths)
|
||||
|
||||
manager.CensusReportDone = make(chan bool)
|
||||
go c.activityLog.CensusReport(ctx, c.censusAgent)
|
||||
go c.activityLog.CensusReport(ctx, c.censusAgent, c.billingStart)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -839,7 +839,7 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
|
|||
"enabled": activityLogEnabledDefaultValue,
|
||||
"queries_available": false,
|
||||
"reporting_enabled": core.censusLicensingEnabled,
|
||||
"billing_start_timestamp": core.GetBillingStart(),
|
||||
"billing_start_timestamp": core.billingStart,
|
||||
"minimum_retention_months": core.activityLog.configOverrides.MinimumRetentionMonths,
|
||||
}
|
||||
|
||||
|
@ -923,7 +923,7 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
|
|||
"enabled": "enable",
|
||||
"queries_available": false,
|
||||
"reporting_enabled": core.censusLicensingEnabled,
|
||||
"billing_start_timestamp": core.GetBillingStart(),
|
||||
"billing_start_timestamp": core.billingStart,
|
||||
"minimum_retention_months": core.activityLog.configOverrides.MinimumRetentionMonths,
|
||||
}
|
||||
|
||||
|
@ -962,7 +962,7 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
|
|||
"enabled": activityLogEnabledDefaultValue,
|
||||
"queries_available": false,
|
||||
"reporting_enabled": core.censusLicensingEnabled,
|
||||
"billing_start_timestamp": core.GetBillingStart(),
|
||||
"billing_start_timestamp": core.billingStart,
|
||||
"minimum_retention_months": core.activityLog.configOverrides.MinimumRetentionMonths,
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
|
||||
package vault
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// sendCurrentFragment is a no-op on OSS
|
||||
func (a *ActivityLog) sendCurrentFragment(ctx context.Context) error {
|
||||
|
@ -13,4 +16,4 @@ func (a *ActivityLog) sendCurrentFragment(ctx context.Context) error {
|
|||
}
|
||||
|
||||
// CensusReport is a no-op on OSS
|
||||
func (a *ActivityLog) CensusReport(_ctx context.Context, _ca *CensusAgent) {}
|
||||
func (a *ActivityLog) CensusReport(context.Context, CensusReporter, time.Time) {}
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
package vault
|
||||
|
||||
import "time"
|
||||
|
||||
// CensusAgent is a stub for OSS
|
||||
type CensusAgent struct {
|
||||
billingStart time.Time
|
||||
}
|
||||
type CensusReporter struct{}
|
||||
|
||||
// setupCensusAgent is a stub for OSS.
|
||||
func (c *Core) setupCensusAgent() error { return nil }
|
||||
|
|
|
@ -636,11 +636,14 @@ type Core struct {
|
|||
activityLogConfig ActivityLogCoreConfig
|
||||
|
||||
// censusAgent is the mechanism used for reporting Vault's billing data.
|
||||
censusAgent *CensusAgent
|
||||
censusAgent CensusReporter
|
||||
|
||||
// censusLicensingEnabled records whether Vault is exporting census metrics
|
||||
censusLicensingEnabled bool
|
||||
|
||||
// billingStart keeps track of the billing start time for exporting census metrics
|
||||
billingStart time.Time
|
||||
|
||||
// activeTime is set on active nodes indicating the time at which this node
|
||||
// became active.
|
||||
activeTime time.Time
|
||||
|
@ -812,7 +815,7 @@ type CoreConfig struct {
|
|||
LicensingConfig *LicensingConfig
|
||||
|
||||
// Configured Census Agent
|
||||
censusAgent *CensusAgent
|
||||
CensusAgent CensusReporter
|
||||
|
||||
DisablePerformanceStandby bool
|
||||
DisableIndexing bool
|
||||
|
@ -2362,6 +2365,11 @@ func (s standardUnsealStrategy) unseal(ctx context.Context, logger log.Logger, c
|
|||
if err := c.setupAuditedHeadersConfig(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.setupCensusAgent(); err != nil {
|
||||
c.logger.Error("skipping reporting for nil agent", "error", err)
|
||||
}
|
||||
|
||||
// not waiting on wg to avoid changing existing behavior
|
||||
var wg sync.WaitGroup
|
||||
if err := c.setupActivityLog(ctx, &wg); err != nil {
|
||||
|
@ -4007,14 +4015,3 @@ func (c *Core) GetRaftAutopilotState(ctx context.Context) (*raft.AutopilotState,
|
|||
func (c *Core) Events() *eventbus.EventBus {
|
||||
return c.events
|
||||
}
|
||||
|
||||
// GetBillingStart gets the billing start timestamp from the configured Census
|
||||
// Agent, handling a nil agent.
|
||||
func (c *Core) GetBillingStart() time.Time {
|
||||
var billingStart time.Time
|
||||
if c.censusAgent != nil {
|
||||
billingStart = c.censusAgent.billingStart
|
||||
}
|
||||
|
||||
return billingStart
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ func (b *SystemBackend) handleActivityConfigRead(ctx context.Context, req *logic
|
|||
"enabled": config.Enabled,
|
||||
"queries_available": qa,
|
||||
"reporting_enabled": b.Core.censusLicensingEnabled,
|
||||
"billing_start_timestamp": b.Core.GetBillingStart(),
|
||||
"billing_start_timestamp": b.Core.billingStart,
|
||||
"minimum_retention_months": a.configOverrides.MinimumRetentionMonths,
|
||||
},
|
||||
}, nil
|
||||
|
|
|
@ -217,7 +217,7 @@ func TestCoreWithSealAndUINoCleanup(t testing.T, opts *CoreConfig) *Core {
|
|||
conf.PluginDirectory = opts.PluginDirectory
|
||||
conf.DetectDeadlocks = opts.DetectDeadlocks
|
||||
conf.Experiments = []string{experiments.VaultExperimentEventsAlpha1}
|
||||
conf.censusAgent = opts.censusAgent
|
||||
conf.CensusAgent = opts.CensusAgent
|
||||
|
||||
if opts.Logger != nil {
|
||||
conf.Logger = opts.Logger
|
||||
|
|
Loading…
Reference in New Issue