Prepare CE changes for [census.Agent] SetMetadata (#27577)

This commit is contained in:
Mike Palmiotto
2024-06-25 10:41:56 -04:00
committed by GitHub
parent c51bdac2c1
commit 93682b0547
6 changed files with 14 additions and 20 deletions

View File

@@ -1711,7 +1711,7 @@ func (c *ServerCommand) Run(args []string) int {
sr.NotifyConfigurationReload(srConfig)
}
if err := core.ReloadCensus(); err != nil {
if err := core.ReloadCensusManager(); err != nil {
c.UI.Error(err.Error())
}

View File

@@ -1016,7 +1016,8 @@ func (a *ActivityLog) SetConfigInit(config activityConfig) {
a.defaultReportMonths = config.DefaultReportMonths
a.retentionMonths = config.RetentionMonths
if a.retentionMonths < a.configOverrides.MinimumRetentionMonths {
// Let tests override the minimum if they want to.
if a.configOverrides.MinimumRetentionMonths > 0 {
a.retentionMonths = a.configOverrides.MinimumRetentionMonths
}

View File

@@ -14,7 +14,6 @@ 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 }
func (c *Core) ReloadCensus() error { return nil }
func (c *Core) teardownCensusManager() error { return nil }
func (c *Core) StartManualCensusSnapshots() {}
func (c *Core) ManualLicenseReportingEnabled() bool { return false }

View File

@@ -10,4 +10,5 @@ import "context"
//go:generate go run github.com/hashicorp/vault/tools/stubmaker
func (c *Core) StartCensusReports(ctx context.Context) {}
func (c *Core) ReloadCensusActivityLog() error { return nil }
func (c *Core) SetRetentionMonths(months int) error { return nil }
func (c *Core) ReloadCensusManager() error { return nil }

View File

@@ -2445,16 +2445,13 @@ func (s standardUnsealStrategy) unseal(ctx context.Context, logger log.Logger, c
return err
}
if !c.perfStandby {
if err := c.setupCensusManager(); err != nil {
logger.Error("failed to instantiate the license reporting agent", "error", err)
}
c.StartCensusReports(ctx)
c.StartManualCensusSnapshots()
if err := c.setupCensusManager(); err != nil {
logger.Error("failed to instantiate the license reporting agent", "error", err)
}
c.StartCensusReports(ctx)
c.StartManualCensusSnapshots()
} else {
broker, err := audit.NewBroker(logger)
if err != nil {
@@ -2847,7 +2844,6 @@ func (c *Core) preSeal() error {
if err := c.teardownCensusManager(); err != nil {
result = multierror.Append(result, fmt.Errorf("error tearing down reporting agent: %w", err))
}
if err := c.teardownCredentials(context.Background()); err != nil {
result = multierror.Append(result, fmt.Errorf("error tearing down credentials: %w", err))
}

View File

@@ -422,9 +422,6 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log
}
}
a.core.activityLogLock.RLock()
minimumRetentionMonths := a.configOverrides.MinimumRetentionMonths
a.core.activityLogLock.RUnlock()
enabled := config.Enabled == "enable"
if !enabled && config.Enabled == "default" {
enabled = activityLogEnabledDefault
@@ -435,8 +432,8 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log
}
// if manual license reporting is enabled, retention months must at least be 48 months
if a.core.ManualLicenseReportingEnabled() && config.RetentionMonths < minimumRetentionMonths {
return logical.ErrorResponse("retention_months must be at least %d while Reporting is enabled", minimumRetentionMonths), logical.ErrInvalidRequest
if a.core.ManualLicenseReportingEnabled() && config.RetentionMonths < ActivityLogMinimumRetentionMonths {
return logical.ErrorResponse("retention_months must be at least %d while Reporting is enabled", ActivityLogMinimumRetentionMonths), logical.ErrInvalidRequest
}
// Store the config
@@ -451,9 +448,9 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log
// Set the new config on the activity log
a.SetConfig(ctx, config)
// reload census agent if retention months change during update when reporting is enabled
// Update Census agent's metadata if retention months change
if prevRetentionMonths != config.RetentionMonths {
if err := a.core.ReloadCensusActivityLog(); err != nil {
if err := b.Core.SetRetentionMonths(config.RetentionMonths); err != nil {
return nil, err
}
}