mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
Manual census snapshot cleanup changes CE (#25061)
* snapshot cleanup oss * CE changes for the API PR * godoc for test --------- Co-authored-by: hamid ghaf <hamid@hashicorp.com>
This commit is contained in:
@@ -17,6 +17,20 @@ func StartOfPreviousMonth(t time.Time) time.Time {
|
||||
return time.Date(year, month, 1, 0, 0, 0, 0, t.Location()).AddDate(0, -1, 0)
|
||||
}
|
||||
|
||||
func StartOfDay(t time.Time) time.Time {
|
||||
year, month, day := t.Date()
|
||||
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
|
||||
}
|
||||
|
||||
// IsCurrentDay checks if :t: is in the current day, as defined by :compare:
|
||||
// generally, pass in time.Now().UTC() as :compare:
|
||||
func IsCurrentDay(t, compare time.Time) bool {
|
||||
thisDayStart := StartOfDay(compare)
|
||||
queryDayStart := StartOfDay(t)
|
||||
|
||||
return queryDayStart.Equal(thisDayStart)
|
||||
}
|
||||
|
||||
func StartOfMonth(t time.Time) time.Time {
|
||||
year, month, _ := t.Date()
|
||||
return time.Date(year, month, 1, 0, 0, 0, 0, t.Location())
|
||||
|
||||
@@ -223,6 +223,47 @@ func TestTimeutil_IsCurrentMonth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestTimeutil_IsCurrentDay checks if the test times equals the current day or not.
|
||||
func TestTimeutil_IsCurrentDay(t *testing.T) {
|
||||
now := time.Now()
|
||||
testCases := []struct {
|
||||
input time.Time
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
input: now,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
input: StartOfDay(now).AddDate(0, 0, -1),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
input: StartOfDay(now).AddDate(-1, 0, 0),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
input: StartOfDay(now).Add(1 * time.Second),
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
input: StartOfDay(now).Add(-1 * time.Second),
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
input: StartOfDay(now).Add(86400), // a day is 86400 seconds
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
result := IsCurrentDay(tc.input, now)
|
||||
if result != tc.expected {
|
||||
t.Errorf("invalid result. expected %t for %v", tc.expected, tc.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeUtil_ContiguousMonths(t *testing.T) {
|
||||
testCases := []struct {
|
||||
input []time.Time
|
||||
|
||||
@@ -10,12 +10,13 @@ import "time"
|
||||
// CensusAgent is a stub for OSS
|
||||
type CensusReporter interface{}
|
||||
|
||||
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 }
|
||||
func (c *Core) ManualCensusSnapshotInterval() time.Duration { return time.Duration(0) }
|
||||
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 }
|
||||
func (c *Core) ManualCensusSnapshotInterval() time.Duration { return time.Duration(0) }
|
||||
func (c *Core) ManualCensusSnapshotRetentionTime() time.Duration { return time.Duration(0) }
|
||||
|
||||
@@ -2419,7 +2419,7 @@ func (s standardUnsealStrategy) unseal(ctx context.Context, logger log.Logger, c
|
||||
if !c.IsDRSecondary() {
|
||||
if !c.perfStandby {
|
||||
if err := c.setupCensusManager(); err != nil {
|
||||
logger.Error("skipping license reporting for nil agent", "error", err)
|
||||
logger.Error("failed to instantiate the license reporting agent", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user