diff --git a/app/collector.go b/app/collector.go index d71ff2087..8477be4da 100644 --- a/app/collector.go +++ b/app/collector.go @@ -29,6 +29,7 @@ const reportQuantisationInterval = 3 * time.Second // interface for parts of the app, and several experimental components. type Reporter interface { Report(context.Context, time.Time) (report.Report, error) + HasReports(context.Context, time.Time) (bool, error) HasHistoricReports() bool WaitOn(context.Context, chan struct{}) UnWait(context.Context, chan struct{}) @@ -161,6 +162,19 @@ func (c *collector) Report(_ context.Context, timestamp time.Time) (report.Repor return rpt, nil } +// HasReports indicates whether the collector contains reports between +// timestamp-app.window and timestamp. +func (c *collector) HasReports(ctx context.Context, timestamp time.Time) (bool, error) { + c.mtx.Lock() + defer c.mtx.Unlock() + + if len(c.timestamps) < 1 { + return false, nil + } + + return !c.timestamps[0].After(timestamp) && !c.timestamps[len(c.reports)-1].Before(timestamp.Add(-c.window)), nil +} + // HasHistoricReports indicates whether the collector contains reports // older than now-app.window. func (c *collector) HasHistoricReports() bool { @@ -223,6 +237,12 @@ func (c StaticCollector) Report(context.Context, time.Time) (report.Report, erro return report.Report(c), nil } +// HasReports indicates whether the collector contains reports between +// timestamp-app.window and timestamp. +func (c StaticCollector) HasReports(context.Context, time.Time) (bool, error) { + return true, nil +} + // HasHistoricReports indicates whether the collector contains reports // older than now-app.window. func (c StaticCollector) HasHistoricReports() bool { diff --git a/app/multitenant/aws_collector.go b/app/multitenant/aws_collector.go index 318925bc6..d0a75dbf3 100644 --- a/app/multitenant/aws_collector.go +++ b/app/multitenant/aws_collector.go @@ -349,6 +349,11 @@ func (c *awsCollector) Report(ctx context.Context, timestamp time.Time) (report. return c.merger.Merge(reports), nil } +func (c *awsCollector) HasReports(ctx context.Context, timestamp time.Time) (bool, error) { + reportKeys, err := c.getReportKeys(ctx, timestamp) + return len(reportKeys) > 0, err +} + func (c *awsCollector) HasHistoricReports() bool { return true }