refactor: extract fn to check whether collector or querier

This commit is contained in:
Bryan Boreham
2021-04-11 13:03:42 +00:00
parent bea8db3683
commit 055ca53241
2 changed files with 6 additions and 3 deletions

View File

@@ -200,7 +200,7 @@ func NewAWSCollector(config AWSCollectorConfig) (AWSCollector, error) {
}
// If given a StoreInterval we will be storing periodically; if not we only answer queries
if config.StoreInterval != 0 {
if c.isCollector() {
c.ticker = time.NewTicker(config.StoreInterval)
go c.flushLoop()
}

View File

@@ -42,11 +42,14 @@ func (c *awsCollector) addToLive(ctx context.Context, userid string, rep report.
entry.Unlock()
}
func (c *awsCollector) isCollector() bool {
return c.cfg.StoreInterval != 0
}
func (c *awsCollector) reportsFromLive(ctx context.Context, userid string) ([]report.Report, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "reportsFromLive")
defer span.Finish()
if c.cfg.StoreInterval != 0 {
// We are a collector
if c.isCollector() {
e, found := c.pending.Load(userid)
if !found {
return nil, nil