Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add weavenet metrics to billing #2504

Merged
merged 2 commits into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/multitenant/billing_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -1756,4 +1756,4 @@
"branch": "master"
}
]
}
}