From 8c4636780869e5c5f16b9c78301d06aaa02c529d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 13 Apr 2020 16:16:20 +0000 Subject: [PATCH] fix(multitenant): move use of rounding map inside lock --- app/multitenant/billing_emitter.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/multitenant/billing_emitter.go b/app/multitenant/billing_emitter.go index 1cf41ce26..aca58b784 100644 --- a/app/multitenant/billing_emitter.go +++ b/app/multitenant/billing_emitter.go @@ -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),