From 1f7f536fcab9de6cff503542ce176f2be8aec97a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 14 Nov 2018 09:59:25 +0000 Subject: [PATCH] Check if host record has uptime in billing emitter --- app/multitenant/billing_emitter.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/multitenant/billing_emitter.go b/app/multitenant/billing_emitter.go index 3375b034d..ee82d1415 100644 --- a/app/multitenant/billing_emitter.go +++ b/app/multitenant/billing_emitter.go @@ -15,6 +15,10 @@ import ( "github.com/weaveworks/scope/report" ) +const ( + uptime = "uptime" +) + // BillingEmitterConfig has everything we need to make a billing emitter type BillingEmitterConfig struct { Enabled bool @@ -65,9 +69,18 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte) weaveNetCount = 1 } + // because the host structure is re-used to carry other information, + // count the number of real hosts in this report - ones with uptime + hostCount := 0 + for _, host := range rep.Host.Nodes { + if _, exists := host.Latest.Lookup(uptime); exists { + hostCount++ + } + } + amounts := billing.Amounts{ billing.ContainerSeconds: int64(interval/time.Second) * int64(len(rep.Container.Nodes)), - billing.NodeSeconds: int64(interval/time.Second) * int64(len(rep.Host.Nodes)), + billing.NodeSeconds: int64(interval/time.Second) * int64(hostCount), billing.WeaveNetSeconds: int64(interval/time.Second) * int64(weaveNetCount), } metadata := map[string]string{