From 5b6e5ca81d73d5cc291db3c59d290f39d4d85a65 Mon Sep 17 00:00:00 2001 From: Marcus Cobden Date: Tue, 9 May 2017 15:09:48 +0000 Subject: [PATCH 1/2] Update billing-client --- vendor/github.com/weaveworks/billing-client/event.go | 1 + vendor/manifest | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/vendor/github.com/weaveworks/billing-client/event.go b/vendor/github.com/weaveworks/billing-client/event.go index a955d72007..d468eeeef6 100644 --- a/vendor/github.com/weaveworks/billing-client/event.go +++ b/vendor/github.com/weaveworks/billing-client/event.go @@ -37,6 +37,7 @@ const ( // ContainerSeconds is one of the billable metrics ContainerSeconds AmountType = "container-seconds" NodeSeconds AmountType = "node-seconds" + WeaveNetSeconds AmountType = "weavenet-seconds" Samples AmountType = "samples" ) diff --git a/vendor/manifest b/vendor/manifest index a4c01190df..b939fd027c 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -1414,7 +1414,7 @@ "importpath": "github.com/weaveworks/billing-client", "repository": "https://github.com/weaveworks/billing-client", "vcs": "git", - "revision": "f5ac1ebd2b577d93dca4d948ca429c499451dbc8", + "revision": "694ea14d915e520638b234d9b3ca780c25963435", "branch": "master", "notests": true }, @@ -1756,4 +1756,4 @@ "branch": "master" } ] -} +} \ No newline at end of file From 9fded9d34e36556ed5861d9798eea0facb4a2009 Mon Sep 17 00:00:00 2001 From: Marcus Cobden Date: Mon, 8 May 2017 11:25:28 +0000 Subject: [PATCH 2/2] Add weavenet metrics to billing --- app/multitenant/billing_emitter.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/multitenant/billing_emitter.go b/app/multitenant/billing_emitter.go index 886cc0cac3..7081fae32c 100644 --- a/app/multitenant/billing_emitter.go +++ b/app/multitenant/billing_emitter.go @@ -57,9 +57,15 @@ func (e *BillingEmitter) Add(ctx context.Context, rep report.Report, buf []byte) hasher := sha256.New() hasher.Write(buf) hash := "sha256:" + base64.URLEncoding.EncodeToString(hasher.Sum(nil)) + weaveNetCount := 0 + if hasWeaveNet(rep) { + weaveNetCount = 1 + } + 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.WeaveNetSeconds: int64(interval/time.Second) * int64(weaveNetCount), } metadata := map[string]string{ "row_key": rowKey, @@ -112,6 +118,18 @@ func (e *BillingEmitter) reportInterval(r report.Report) time.Duration { return d } +// Tries to determine if this report came from a host running Weave Net +func hasWeaveNet(r report.Report) bool { + for _, n := range r.Overlay.Nodes { + overlayType, _ := report.ParseOverlayNodeID(n.ID) + if overlayType == report.WeaveOverlayPeerPrefix { + return true + } + } + + return false +} + // Close shuts down the billing emitter and billing client flushing events. func (e *BillingEmitter) Close() error { return e.billing.Close()