From 74b6a292d55a897bcb7366c1af7eda9fcce6b350 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 13 Sep 2019 07:31:07 +0000 Subject: [PATCH] Use time.Duration instead of nanoseconds for constants --- app/multitenant/aws_collector.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/multitenant/aws_collector.go b/app/multitenant/aws_collector.go index 5550ac830..bdc0f0e6d 100644 --- a/app/multitenant/aws_collector.go +++ b/app/multitenant/aws_collector.go @@ -31,10 +31,10 @@ const ( reportField = "report" natsTimeout = 10 * time.Second - reportQuantisationInterval = 3000000000 // 3 seconds in nanoseconds + reportQuantisationInterval = 3 * time.Second // Grace period allows for some gap between the timestamp on reports // (assigned when they arrive at collector) and them appearing in DynamoDB query - gracePeriod = 500000000 // 1/2 second in nanoseconds + gracePeriod = 500 * time.Millisecond ) var ( @@ -381,8 +381,8 @@ func (c *awsCollector) Report(ctx context.Context, timestamp time.Time) (report. var reports []report.Report // Fetch a merged report for each time quantum covering the window startTS, endTS := start.UnixNano(), end.UnixNano() - ts := startTS - (startTS % reportQuantisationInterval) - for ; ts+reportQuantisationInterval+gracePeriod < endTS; ts += reportQuantisationInterval { + ts := startTS - (startTS % reportQuantisationInterval.Nanoseconds()) + for ; ts+(reportQuantisationInterval+gracePeriod).Nanoseconds() < endTS; ts += reportQuantisationInterval.Nanoseconds() { quantumReport, err := c.reportForQuantum(ctx, userid, reportKeys, ts) if err != nil { return report.MakeReport(), err @@ -406,7 +406,7 @@ func (c *awsCollector) reportForQuantum(ctx context.Context, userid string, repo if len(cached) == 1 { return cached[key], nil } - reports, err := c.reportsForKeysInRange(ctx, reportKeys, start, start+reportQuantisationInterval) + reports, err := c.reportsForKeysInRange(ctx, reportKeys, start, start+reportQuantisationInterval.Nanoseconds()) if err != nil { return report.MakeReport(), err }