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

Backport of Fix read only error to storage error while updating retention months for upgrades CE changes into release/1.15.x #27167

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
29 changes: 16 additions & 13 deletions vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"io"
"net/http"
"os"
"path"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -271,11 +270,20 @@ func NewActivityLog(core *Core, logger log.Logger, view *BarrierView, metrics me
precomputedQueryWritten: make(chan struct{}),
}

config, err := a.loadConfigOrDefault(core.activeContext, core.ManualLicenseReportingEnabled())
config, err := a.loadConfigOrDefault(core.activeContext)
if err != nil {
return nil, err
}

// check if the retention time is lesser than the default in storage when reporting is enabled to support upgrades
if (config.RetentionMonths < ActivityLogMinimumRetentionMonths) && core.ManualLicenseReportingEnabled() {
updatedConfig, err := a.setDefaultRetentionMonthsInConfig(core.activeContext, config)
if err != nil {
return nil, err
}
config = updatedConfig
}

a.SetConfigInit(config)

a.queryStore = activity.NewPrecomputedQueryStore(
Expand Down Expand Up @@ -1908,7 +1916,7 @@ func defaultActivityConfig() activityConfig {
}
}

func (a *ActivityLog) loadConfigOrDefault(ctx context.Context, isReportingEnabled bool) (activityConfig, error) {
func (a *ActivityLog) loadConfigOrDefault(ctx context.Context) (activityConfig, error) {
// Load from storage
var config activityConfig
configRaw, err := a.view.Get(ctx, activityConfigKey)
Expand All @@ -1922,25 +1930,20 @@ func (a *ActivityLog) loadConfigOrDefault(ctx context.Context, isReportingEnable
if err := configRaw.DecodeJSON(&config); err != nil {
return config, err
}

// check if the retention time is lesser than the default when reporting is enabled
if (config.RetentionMonths < ActivityLogMinimumRetentionMonths) && isReportingEnabled {
updatedConfig, err := a.setDefaultRetentionMonthsInConfig(ctx, config)
if err != nil {
return config, err
}
return updatedConfig, nil
}
return config, nil
}

// setDefaultRetentionMonthsInConfig sets the retention months in activity config with default value.
// This supports upgrades from versions prior to set the new default ActivityLogMinimumRetentionMonths.
func (a *ActivityLog) setDefaultRetentionMonthsInConfig(ctx context.Context, inputConfig activityConfig) (activityConfig, error) {
if a.core.perfStandby {
return inputConfig, nil
}

inputConfig.RetentionMonths = ActivityLogMinimumRetentionMonths

// Store the config
entry, err := logical.StorageEntryJSON(path.Join(activitySubPath, activityConfigKey), inputConfig)
entry, err := logical.StorageEntryJSON(activityConfigKey, inputConfig)
if err != nil {
return inputConfig, err
}
Expand Down
4 changes: 2 additions & 2 deletions vault/logical_system_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (b *SystemBackend) handleActivityConfigRead(ctx context.Context, req *logic
return logical.ErrorResponse("no activity log present"), nil
}

config, err := a.loadConfigOrDefault(ctx, b.Core.ManualLicenseReportingEnabled())
config, err := a.loadConfigOrDefault(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log

warnings := make([]string, 0)

config, err := a.loadConfigOrDefault(ctx, b.Core.ManualLicenseReportingEnabled())
config, err := a.loadConfigOrDefault(ctx)
if err != nil {
return nil, err
}
Expand Down
Loading