Refactor: pull time interval computation up out of getReportKeys()

This commit is contained in:
Bryan Boreham
2019-09-03 08:00:47 +00:00
parent 5b256ba473
commit 589c4c4d0b

View File

@@ -274,11 +274,9 @@ func (c *awsCollector) reportKeysInRange(ctx context.Context, userid string, row
return result, nil
}
// getReportKeys returns the S3 for reports in the reporting window ending at timestamp.
func (c *awsCollector) getReportKeys(ctx context.Context, timestamp time.Time) ([]string, error) {
// getReportKeys returns the S3 for reports in the interval [start, end].
func (c *awsCollector) getReportKeys(ctx context.Context, start, end time.Time) ([]string, error) {
var (
end = timestamp
start = end.Add(-c.cfg.Window)
rowStart = start.UnixNano() / time.Hour.Nanoseconds()
rowEnd = end.UnixNano() / time.Hour.Nanoseconds()
)
@@ -351,7 +349,9 @@ func (c *awsCollector) getReports(ctx context.Context, reportKeys []string) ([]r
func (c *awsCollector) Report(ctx context.Context, timestamp time.Time) (report.Report, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "awsCollector.Report")
defer span.Finish()
reportKeys, err := c.getReportKeys(ctx, timestamp)
end := timestamp
start := end.Add(-c.cfg.Window)
reportKeys, err := c.getReportKeys(ctx, start, end)
if err != nil {
return report.MakeReport(), err
}
@@ -366,7 +366,8 @@ func (c *awsCollector) Report(ctx context.Context, timestamp time.Time) (report.
}
func (c *awsCollector) HasReports(ctx context.Context, timestamp time.Time) (bool, error) {
reportKeys, err := c.getReportKeys(ctx, timestamp)
start := timestamp.Add(-c.cfg.Window)
reportKeys, err := c.getReportKeys(ctx, start, timestamp)
return len(reportKeys) > 0, err
}