fix (multitenant collector): Use consistent report timestamp

Previously the code called `time.Now()` in two different places so the
timestamps didn't match. Now we use the timestamp of the report itself.

Add the collector's local time to the report if it didn't have one.
This commit is contained in:
Bryan Boreham
2020-03-26 19:01:12 +00:00
parent b3f212755b
commit 6b72246fe6
4 changed files with 7 additions and 2 deletions

View File

@@ -348,6 +348,7 @@ func replay(a Adder, timestamps []time.Time, reports []report.Report) {
due := time.Now()
for {
for i, r := range reports {
r.TS = due
a.Add(nil, r, nil)
due = due.Add(delays[i])
delay := due.Sub(time.Now())

View File

@@ -538,7 +538,7 @@ func (c *awsCollector) Add(ctx context.Context, rep report.Report, buf []byte) e
}
// first, put the report on s3
rowKey, colKey := calculateDynamoKeys(userid, time.Now())
rowKey, colKey := calculateDynamoKeys(userid, rep.TS)
reportKey, err := calculateReportKey(rowKey, colKey)
if err != nil {
return err

View File

@@ -59,7 +59,7 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
// proceeding.
return err
}
rowKey, colKey := calculateDynamoKeys(userID, now)
rowKey, colKey := calculateDynamoKeys(userID, rep.TS)
interval := e.reportInterval(rep)
// Cache the last-known value of interval for this user, and use

View File

@@ -148,6 +148,10 @@ func RegisterReportPostHandler(a Adder, router *mux.Router) {
buf, _ = rpt.WriteBinary()
}
// If it didn't come in with a timestamp, give it one now
if rpt.TS.IsZero() {
rpt.TS = time.Now().UTC()
}
if err := a.Add(ctx, *rpt, buf.Bytes()); err != nil {
log.Errorf("Error Adding report: %v", err)
respondWith(w, http.StatusInternalServerError, err)