fix(multitenant): move use of rounding map inside lock

This commit is contained in:
Bryan Boreham
2020-04-13 16:16:20 +00:00
parent 5553e6ec80
commit 8c46367808

View File

@@ -77,21 +77,21 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte)
interval = e.DefaultInterval
}
}
// Billing takes an integer number of seconds, so keep track of the amount lost to rounding
nodeSeconds := interval.Seconds()*float64(len(rep.Host.Nodes)) + e.rounding[userID]
rounding := nodeSeconds - math.Floor(nodeSeconds)
e.rounding[userID] = rounding
e.Unlock()
hasher := sha256.New()
hasher.Write(buf)
hash := "sha256:" + base64.URLEncoding.EncodeToString(hasher.Sum(nil))
weaveNetCount := 0
if hasWeaveNet(rep) {
weaveNetCount = 1
}
// Billing takes an integer number of seconds, so keep track of the amount lost to rounding
nodeSeconds := interval.Seconds()*float64(len(rep.Host.Nodes)) + e.rounding[userID]
rounding := nodeSeconds - math.Floor(nodeSeconds)
e.rounding[userID] = rounding
amounts := billing.Amounts{
billing.ContainerSeconds: int64(interval/time.Second) * int64(len(rep.Container.Nodes)),
billing.NodeSeconds: int64(nodeSeconds),