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

stats: Add tally reporter to emit tagged metrics #676

Merged
merged 2 commits into from
Jan 31, 2018
Merged

Conversation

prashantv
Copy link
Contributor

This is an open-sourcing of the tally StatsReporter which will emit
tagged metrics rather than statsd metrics.

This is an open-sourcing of the tally StatsReporter which will emit
tagged metrics rather than statsd metrics.
@codecov
Copy link

codecov bot commented Jan 30, 2018

Codecov Report

Merging #676 into dev will increase coverage by 0.27%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #676      +/-   ##
==========================================
+ Coverage   86.48%   86.76%   +0.27%     
==========================================
  Files          39       39              
  Lines        3958     3958              
==========================================
+ Hits         3423     3434      +11     
+ Misses        409      400       -9     
+ Partials      126      124       -2
Impacted Files Coverage Δ
mex.go 72.09% <0%> (-2.8%) ⬇️
outbound.go 79.88% <0%> (+1.14%) ⬆️
connection.go 85.13% <0%> (+3.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7c2fc5...55bf8a7. Read the comment docs.

@@ -1,14 +1,16 @@
hash: d6093eb1a6d4c1eaa9f2ad996ebf07748b0b3a0413f4ab9b9435df1d255567a5
updated: 2017-09-25T17:19:51.449837394-07:00
hash: b75ed7f632cfd185b6a8f8bc037b09d32e292f908af6c1e257e444e17a3a39ef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tip: I’ve found that it’s easier to rebase if I keep glide.lock updates in their own commit. Easy to remove the commit when I rebase, then recreate with glide up, instead of dealing with glide.lock merge conflicts. More relevant on a more active repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agreed. Since this repo isn't really updated, this hasn't been an issue.

@@ -0,0 +1,188 @@
package stats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth stuttering this package name, e.g., tchanneltally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding to the existing tchannel stats package:
https://godoc.org/github.com/uber/tchannel-go/stats

stats/tally.go Outdated
// NewTallyReporter takes a tally.Scope and wraps it so it ca be used as a
// StatsReporter. The list of metrics emitted is documented on:
// https://tchannel.readthedocs.io/en/latest/metrics/
// The tags emitted are similar to Muttley/YARPC, the tags emitted are:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public mention of Muttley.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

kt := convertTags(tags)

w.RLock()
ts, ok := w.byTags[kt]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In YARPC’s observability layer, we often digest the tags into a null-delimited string. You know the performance of struct key map lookup better than me. This is on the hot path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question -- this is definitely on the hot path (since we emit multiple stats per RPC).

A single string lookup is faster than using a struct with 4 strings. Just the lookup has a huge performance difference (the struct has 4 strings, and the string is the 4 strings concatenated with a null byte separator):

string-lookup: 24.6 ns/op
struct-lookup: 84.4 ns/op

However, this is not enough to look at, as using a single string requires building that string. Let's add the cost of building a string (without allocating) by reusing a shared buffer, and then do the lookup:

string-build-lookup: 63.8

This may be called from multiple goroutines, so we can't reuse a single buffer. Once we add buffer pooling, the cost difference is negligible, and the complexity of pooling (and risk of issues) is probably not worth the optimization.

@prashantv prashantv merged commit 11aa90d into dev Jan 31, 2018
@prashantv prashantv deleted the add_tagged_reporter branch January 31, 2018 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants