From e8071a489005b207797dee2186f53d7886d690bb Mon Sep 17 00:00:00 2001 From: akshya96 <87045294+akshya96@users.noreply.github.com> Date: Tue, 15 Apr 2025 15:31:45 -0700 Subject: [PATCH] Vault 34678-Removing estimates from counters api: Handle billing start date updates CE (#30266) * adding handle billing start date changes ce * fix ce version for reload census manager --- command/server.go | 2 +- vault/activity_log.go | 19 ++++++++++++++----- vault/activity_log_util_common.go | 14 +++++++------- vault/census.go | 22 +++++++++++----------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/command/server.go b/command/server.go index 581306afb3..a1c41de1d0 100644 --- a/command/server.go +++ b/command/server.go @@ -1692,7 +1692,7 @@ func (c *ServerCommand) Run(args []string) int { sr.NotifyConfigurationReload(srConfig) } - if err := core.ReloadCensusManager(false); err != nil { + if err := core.ReloadCensusManager(ctx, false); err != nil { c.UI.Error(err.Error()) } diff --git a/vault/activity_log.go b/vault/activity_log.go index 2a65dba67b..b3cd783b52 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -214,12 +214,19 @@ type ActivityLog struct { // is written. It's used for unit testing precomputedQueryWritten chan struct{} + clientIDsUsage ClientUsageInfo +} + +type ClientUsageInfo struct { + // clientIDsUsageInfoLock controls access to the ClientUsageInfo + clientIDsUsageInfoLock sync.RWMutex + + // setupClientIDsUsageInfoCancelCtx is used to cancel and restart setupClientIDsUsageInfo goroutine during reloads + setupClientIDsUsageInfoCancelCtx context.CancelFunc + // The clientIDsUsageInfo map has clientIDs that have been used in the current billing period clientIDsUsageInfo map[string]struct{} - // clientIDsUsageInfoLock controls access to the clientIDsUsageInfo - clientIDsUsageInfoLock sync.RWMutex - // clientIDsUsageInfoLoaded is set to true when the clientIDsUsageInfo has up-to date information upon startup. // This ensures that the counters api returns exact values for new clients in the current month upon startup. clientIDsUsageInfoLoaded *atomic.Bool @@ -342,8 +349,10 @@ func NewActivityLog(core *Core, logger log.Logger, view *BarrierView, metrics me standbyFragmentsReceived: make([]*activity.LogFragment, 0), inprocessExport: atomic.NewBool(false), precomputedQueryWritten: make(chan struct{}), - clientIDsUsageInfo: make(map[string]struct{}), - clientIDsUsageInfoLoaded: new(atomic.Bool), + clientIDsUsage: ClientUsageInfo{ + clientIDsUsageInfo: make(map[string]struct{}), + clientIDsUsageInfoLoaded: new(atomic.Bool), + }, } config, err := a.loadConfigOrDefault(core.activeContext) diff --git a/vault/activity_log_util_common.go b/vault/activity_log_util_common.go index 45f393ac4b..8351b272e5 100644 --- a/vault/activity_log_util_common.go +++ b/vault/activity_log_util_common.go @@ -559,19 +559,19 @@ func (a *ActivityLog) namespaceRecordToCountsResponse(record *activity.Namespace } func (a *ActivityLog) GetClientIDsUsageInfo() map[string]struct{} { - a.clientIDsUsageInfoLock.Lock() - defer a.clientIDsUsageInfoLock.Unlock() - return a.clientIDsUsageInfo + a.clientIDsUsage.clientIDsUsageInfoLock.Lock() + defer a.clientIDsUsage.clientIDsUsageInfoLock.Unlock() + return a.clientIDsUsage.clientIDsUsageInfo } func (a *ActivityLog) SetClientIDsUsageInfo(inMemClientIDsMap map[string]struct{}) { - a.clientIDsUsageInfoLock.Lock() - defer a.clientIDsUsageInfoLock.Unlock() + a.clientIDsUsage.clientIDsUsageInfoLock.Lock() + defer a.clientIDsUsage.clientIDsUsageInfoLock.Unlock() - a.clientIDsUsageInfo = inMemClientIDsMap + a.clientIDsUsage.clientIDsUsageInfo = inMemClientIDsMap } // GetclientIDsUsageInfoLoaded gets a.clientIDsUsageInfoLoaded for external tests func (a *ActivityLog) GetClientIDsUsageInfoLoaded() bool { - return a.clientIDsUsageInfoLoaded.Load() + return a.clientIDsUsage.clientIDsUsageInfoLoaded.Load() } diff --git a/vault/census.go b/vault/census.go index 3481adacd2..821bac5837 100644 --- a/vault/census.go +++ b/vault/census.go @@ -15,17 +15,17 @@ const utilizationBasePath = "utilization" // CensusAgent is a stub for OSS type CensusReporter interface{} -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) teardownCensusManager() error { return nil } -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) BillingStart() time.Time { return time.Time{} } +func (c *Core) AutomatedLicenseReportingEnabled() bool { return false } +func (c *Core) CensusAgent() CensusReporter { return nil } +func (c *Core) teardownCensusManager() error { return nil } +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(ctx context.Context, licenseChange bool) error { return nil } func (c *Core) parseCensusManagerConfig(conf *CoreConfig) (CensusManagerConfig, error) { return CensusManagerConfig{}, nil }