Add no-op CensusAgent (#19625)
* Add no-op CensusAgent * Changelog for Census Agent background worker
This commit is contained in:
parent
e627737fe8
commit
2381e6be66
|
@ -0,0 +1,4 @@
|
||||||
|
```release-note:feature
|
||||||
|
core (enterprise): Add background worker for automatic reporting of billing
|
||||||
|
information.
|
||||||
|
```
|
|
@ -174,6 +174,14 @@ type ActivityLog struct {
|
||||||
partialMonthClientTracker map[string]*activity.EntityRecord
|
partialMonthClientTracker map[string]*activity.EntityRecord
|
||||||
|
|
||||||
inprocessExport *atomic.Bool
|
inprocessExport *atomic.Bool
|
||||||
|
|
||||||
|
// CensusReportDone is a channel used to signal tests upon successful calls
|
||||||
|
// to (CensusReporter).Write() in CensusReport.
|
||||||
|
CensusReportDone chan bool
|
||||||
|
|
||||||
|
// CensusReportInterval is the testing configuration for time between
|
||||||
|
// Write() calls initiated in CensusReport.
|
||||||
|
CensusReportInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// These non-persistent configuration options allow us to disable
|
// These non-persistent configuration options allow us to disable
|
||||||
|
@ -185,6 +193,9 @@ type ActivityLogCoreConfig struct {
|
||||||
|
|
||||||
// Do not start timers to send or persist fragments.
|
// Do not start timers to send or persist fragments.
|
||||||
DisableTimers bool
|
DisableTimers bool
|
||||||
|
|
||||||
|
// CensusReportInterval is the testing configuration for time
|
||||||
|
CensusReportInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewActivityLog creates an activity log.
|
// NewActivityLog creates an activity log.
|
||||||
|
@ -206,6 +217,7 @@ func NewActivityLog(core *Core, logger log.Logger, view *BarrierView, metrics me
|
||||||
writeCh: make(chan struct{}, 1), // same for full segment
|
writeCh: make(chan struct{}, 1), // same for full segment
|
||||||
doneCh: make(chan struct{}, 1),
|
doneCh: make(chan struct{}, 1),
|
||||||
partialMonthClientTracker: make(map[string]*activity.EntityRecord),
|
partialMonthClientTracker: make(map[string]*activity.EntityRecord),
|
||||||
|
CensusReportInterval: time.Hour * 1,
|
||||||
|
|
||||||
currentSegment: segmentInfo{
|
currentSegment: segmentInfo{
|
||||||
startTimestamp: 0,
|
startTimestamp: 0,
|
||||||
|
@ -943,6 +955,10 @@ func (a *ActivityLog) SetConfigInit(config activityConfig) {
|
||||||
|
|
||||||
a.defaultReportMonths = config.DefaultReportMonths
|
a.defaultReportMonths = config.DefaultReportMonths
|
||||||
a.retentionMonths = config.RetentionMonths
|
a.retentionMonths = config.RetentionMonths
|
||||||
|
|
||||||
|
if a.configOverrides.CensusReportInterval > 0 {
|
||||||
|
a.CensusReportInterval = a.configOverrides.CensusReportInterval
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This version reacts to user changes
|
// This version reacts to user changes
|
||||||
|
@ -1079,6 +1095,9 @@ func (c *Core) setupActivityLog(ctx context.Context, wg *sync.WaitGroup) error {
|
||||||
manager.retentionWorker(ctx, time.Now(), months)
|
manager.retentionWorker(ctx, time.Now(), months)
|
||||||
close(manager.retentionDone)
|
close(manager.retentionDone)
|
||||||
}(manager.retentionMonths)
|
}(manager.retentionMonths)
|
||||||
|
|
||||||
|
manager.CensusReportDone = make(chan bool)
|
||||||
|
go c.activityLog.CensusReport(ctx, c.censusAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1579,7 +1598,9 @@ func (a *ActivityLog) handleQuery(ctx context.Context, startTime, endTime time.T
|
||||||
if computePartial {
|
if computePartial {
|
||||||
// Traverse through current month's activitylog data and group clients
|
// Traverse through current month's activitylog data and group clients
|
||||||
// into months and namespaces
|
// into months and namespaces
|
||||||
|
a.fragmentLock.RLock()
|
||||||
partialByMonth, partialByNamespace = a.populateNamespaceAndMonthlyBreakdowns()
|
partialByMonth, partialByNamespace = a.populateNamespaceAndMonthlyBreakdowns()
|
||||||
|
a.fragmentLock.RUnlock()
|
||||||
|
|
||||||
// Convert the byNamespace breakdowns into structs that are
|
// Convert the byNamespace breakdowns into structs that are
|
||||||
// consumable by the /activity endpoint, so as to reuse code between these two
|
// consumable by the /activity endpoint, so as to reuse code between these two
|
||||||
|
@ -1763,6 +1784,8 @@ type activityConfig struct {
|
||||||
|
|
||||||
// Enabled is one of enable, disable, default.
|
// Enabled is one of enable, disable, default.
|
||||||
Enabled string `json:"enabled"`
|
Enabled string `json:"enabled"`
|
||||||
|
|
||||||
|
CensusReportInterval time.Duration `json:"census_report_interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultActivityConfig() activityConfig {
|
func defaultActivityConfig() activityConfig {
|
||||||
|
|
|
@ -11,3 +11,6 @@ import "context"
|
||||||
func (a *ActivityLog) sendCurrentFragment(ctx context.Context) error {
|
func (a *ActivityLog) sendCurrentFragment(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CensusReport is a no-op on OSS
|
||||||
|
func (a *ActivityLog) CensusReport(_ctx context.Context, _ca *CensusAgent) {}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
//go:build !enterprise
|
||||||
|
|
||||||
|
package vault
|
||||||
|
|
||||||
|
// CensusAgent is a stub for OSS
|
||||||
|
type CensusAgent struct{}
|
|
@ -641,6 +641,9 @@ type Core struct {
|
||||||
|
|
||||||
activityLogConfig ActivityLogCoreConfig
|
activityLogConfig ActivityLogCoreConfig
|
||||||
|
|
||||||
|
// censusAgent is the mechanism used for reporting Vault's billing data.
|
||||||
|
censusAgent *CensusAgent
|
||||||
|
|
||||||
// activeTime is set on active nodes indicating the time at which this node
|
// activeTime is set on active nodes indicating the time at which this node
|
||||||
// became active.
|
// became active.
|
||||||
activeTime time.Time
|
activeTime time.Time
|
||||||
|
@ -808,6 +811,9 @@ type CoreConfig struct {
|
||||||
LicensePath string
|
LicensePath string
|
||||||
LicensingConfig *LicensingConfig
|
LicensingConfig *LicensingConfig
|
||||||
|
|
||||||
|
// Configured Census Agent
|
||||||
|
censusAgent *CensusAgent
|
||||||
|
|
||||||
DisablePerformanceStandby bool
|
DisablePerformanceStandby bool
|
||||||
DisableIndexing bool
|
DisableIndexing bool
|
||||||
DisableKeyEncodingChecks bool
|
DisableKeyEncodingChecks bool
|
||||||
|
|
|
@ -217,6 +217,7 @@ func TestCoreWithSealAndUINoCleanup(t testing.T, opts *CoreConfig) *Core {
|
||||||
conf.PluginDirectory = opts.PluginDirectory
|
conf.PluginDirectory = opts.PluginDirectory
|
||||||
conf.DetectDeadlocks = opts.DetectDeadlocks
|
conf.DetectDeadlocks = opts.DetectDeadlocks
|
||||||
conf.Experiments = []string{experiments.VaultExperimentEventsAlpha1}
|
conf.Experiments = []string{experiments.VaultExperimentEventsAlpha1}
|
||||||
|
conf.censusAgent = opts.censusAgent
|
||||||
|
|
||||||
if opts.Logger != nil {
|
if opts.Logger != nil {
|
||||||
conf.Logger = opts.Logger
|
conf.Logger = opts.Logger
|
||||||
|
|
Loading…
Reference in New Issue