Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
3 changes: 2 additions & 1 deletion vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion vault/census.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion vault/census_stubs_oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
14 changes: 5 additions & 9 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
11 changes: 4 additions & 7 deletions vault/logical_system_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
}
Expand Down
Loading