-
Notifications
You must be signed in to change notification settings - Fork 47
Experimenting with new ways to provide data to reporters #37
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
a3be900
f6c6de4
e729482
d824753
a4afd3d
0b6e337
9994eba
6e50126
8980d03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| module Metriks | ||
| module Reporter | ||
| class CounterDerivative | ||
| def initialize(reporter) | ||
| @reporter = reporter | ||
| @last = Hash.new | ||
| end | ||
|
|
||
| def each(&block) | ||
| @registry.each do |name, metric| | ||
| case metric | ||
| when Metriks::Meter | ||
| if @last["#{name}.count"] | ||
| count = metric.count | ||
| block.call("#{name}.count", count - @last["#{name}.count"]) | ||
| @last["#{name}.count"] = count | ||
| end | ||
| when Metriks::Counter | ||
| block.call("#{name}.count", metric.count) | ||
| when Metriks::Gauge | ||
| block.call("#{name}.value", metric.value) | ||
| when Metriks::UtilizationTimer | ||
| if @last["#{name}.count"] | ||
| count = metric.count | ||
| block.call("#{name}.count", count - @last["#{name}.count"]) | ||
| @last["#{name}.count"] = count | ||
| end | ||
|
|
||
| block.call("#{name}.min", metric.min) | ||
| block.call("#{name}.max", metric.max) | ||
| block.call("#{name}.median", metric.median) | ||
| block.call("#{name}.stddev", metric.stddev) | ||
|
|
||
| block.call("#{name}.one_minute_utilization", metric.one_minute_utilization) | ||
| block.call("#{name}.five_minute_utilization", metric.five_minute_utilization) | ||
| block.call("#{name}.fifteen_minute_utilization", metric.fifteen_minute_utilization) | ||
|
|
||
| snapshot = metric.snapshot | ||
|
|
||
| block.call("#{name}.median", snapshot.median) | ||
| block.call("#{name}.75th_percentile", snapshot.get_75th_percentile) | ||
| block.call("#{name}.95th_percentile", snapshot.get_95th_percentile) | ||
| block.call("#{name}.98th_percentile", snapshot.get_98th_percentile) | ||
| block.call("#{name}.99th_percentile", snapshot.get_99th_percentile) | ||
| block.call("#{name}.999th_percentile", snapshot.get_999th_percentile) | ||
| when Metriks::Timer | ||
| if @last["#{name}.count"] | ||
| count = metric.count | ||
| block.call("#{name}.count", count - @last["#{name}.count"]) | ||
| @last["#{name}.count"] = count | ||
| end | ||
|
|
||
| block.call("#{name}.min", metric.min) | ||
| block.call("#{name}.max", metric.max) | ||
| block.call("#{name}.median", metric.median) | ||
| block.call("#{name}.stddev", metric.stddev) | ||
|
|
||
| snapshot = metric.snapshot | ||
|
|
||
| block.call("#{name}.median", snapshot.median) | ||
| block.call("#{name}.75th_percentile", snapshot.get_75th_percentile) | ||
| block.call("#{name}.95th_percentile", snapshot.get_95th_percentile) | ||
| block.call("#{name}.98th_percentile", snapshot.get_98th_percentile) | ||
| block.call("#{name}.99th_percentile", snapshot.get_99th_percentile) | ||
| block.call("#{name}.999th_percentile", snapshot.get_999th_percentile) | ||
| when Metriks::Histogram | ||
| block.call("#{name}.count", metric.count) | ||
| block.call("#{name}.min", metric.min) | ||
| block.call("#{name}.max", metric.max) | ||
| block.call("#{name}.median", metric.median) | ||
| block.call("#{name}.stddev", metric.stddev) | ||
|
|
||
| snapshot = metric.snapshot | ||
|
|
||
| block.call("#{name}.median", snapshot.median) | ||
| block.call("#{name}.75th_percentile", snapshot.get_75th_percentile) | ||
| block.call("#{name}.95th_percentile", snapshot.get_95th_percentile) | ||
| block.call("#{name}.98th_percentile", snapshot.get_98th_percentile) | ||
| block.call("#{name}.99th_percentile", snapshot.get_99th_percentile) | ||
| block.call("#{name}.999th_percentile", snapshot.get_999th_percentile) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| module Metriks | ||
| module Reporter | ||
| class FlatteningRegistryEnumerator | ||
| def initialize(registry, options = {}) | ||
| @registry = registry | ||
| if options[:counter_derivative] | ||
| @last = Hash.new { |h,k| h[k] = 0 } | ||
| end | ||
| end | ||
|
|
||
| def each(&block) | ||
| @registry.each do |name, metric| | ||
| case metric | ||
| when Metriks::Meter | ||
| if @last | ||
| count = metric.count | ||
| block.call("#{name}.count", count - @last["#{name}.count"]) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to append |
||
| @last["#{name}.count"] = count | ||
| else | ||
| block.call("#{name}.count", metric.count) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if it ever makes sense to actually send |
||
| block.call("#{name}.one_minute_rate", metric.one_minute_rate) | ||
| block.call("#{name}.five_minute_rate", metric.five_minute_rate) | ||
| block.call("#{name}.fifteen_minute_rate", metric.fifteen_minute_rate) | ||
| block.call("#{name}.mean_rate", metric.mean_rate) | ||
| end | ||
|
|
||
| when Metriks::Counter | ||
| block.call("#{name}.count", metric.count) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to append
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know that a value is a count when it does not say
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That brings up a good philosophical point: Do we want the metric names to contain "schema" information that can be used to help format them properly? Is it useful to do that? I sort of lean toward the side of not caring about that schema information being included in the metric name, but I could see the value of it depending on what sort of backend you were using.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With schema information you mean "meter", "timer", ...? That seems pretty verbose to me. ("foo.bar.baz.meter.one_minute_rate") If a reporter wants to get rid of that it has to do some string wrangling. Another option is to pass the metric class to the block. block.call("#{name}.one_minute_rate", metric.one_minute_rate, metric.class)That way the reporter can just ignore the class name but can access it if it needs to take a decision based on the metric type. And then one could ask: why compute the name string in the first place? block.call(name, "one_minute_rate", metric.one_minute_rate, metric.class)Which makes the reporter to do more work again. I like the simplicity of the current enumeration approach.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and we can always create new registry presentation classes for the reporters later. ;) |
||
| when Metriks::Gauge | ||
| block.call("#{name}.value", metric.value) | ||
| when Metriks::UtilizationTimer | ||
| if @last | ||
| count = metric.count | ||
| block.call("#{name}.count", count - @last["#{name}.count"]) | ||
| @last["#{name}.count"] = count | ||
| else | ||
| block.call("#{name}.one_minute_rate", metric.one_minute_rate) | ||
| block.call("#{name}.five_minute_rate", metric.five_minute_rate) | ||
| block.call("#{name}.fifteen_minute_rate", metric.fifteen_minute_rate) | ||
| end | ||
|
|
||
| block.call("#{name}.min", metric.min) | ||
| block.call("#{name}.max", metric.max) | ||
| block.call("#{name}.median", metric.median) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Same for
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. |
||
| block.call("#{name}.stddev", metric.stddev) | ||
|
|
||
| block.call("#{name}.one_minute_utilization", metric.one_minute_utilization) | ||
| block.call("#{name}.five_minute_utilization", metric.five_minute_utilization) | ||
| block.call("#{name}.fifteen_minute_utilization", metric.fifteen_minute_utilization) | ||
|
|
||
| snapshot = metric.snapshot | ||
|
|
||
| block.call("#{name}.median", snapshot.median) | ||
| block.call("#{name}.75th_percentile", snapshot.get_75th_percentile) | ||
| block.call("#{name}.95th_percentile", snapshot.get_95th_percentile) | ||
| block.call("#{name}.98th_percentile", snapshot.get_98th_percentile) | ||
| block.call("#{name}.99th_percentile", snapshot.get_99th_percentile) | ||
| block.call("#{name}.999th_percentile", snapshot.get_999th_percentile) | ||
| when Metriks::Timer | ||
| if @last | ||
| count = metric.count | ||
| block.call("#{name}.count", count - @last["#{name}.count"]) | ||
| @last["#{name}.count"] = count | ||
| else | ||
| block.call("#{name}.count", metric.count) | ||
| block.call("#{name}.one_minute_rate", metric.one_minute_rate) | ||
| block.call("#{name}.five_minute_rate", metric.five_minute_rate) | ||
| block.call("#{name}.fifteen_minute_rate", metric.fifteen_minute_rate) | ||
| block.call("#{name}.mean_rate", metric.mean_rate) | ||
| end | ||
|
|
||
| block.call("#{name}.min", metric.min) | ||
| block.call("#{name}.max", metric.max) | ||
| block.call("#{name}.median", metric.median) | ||
| block.call("#{name}.stddev", metric.stddev) | ||
|
|
||
| snapshot = metric.snapshot | ||
|
|
||
| block.call("#{name}.median", snapshot.median) | ||
| block.call("#{name}.75th_percentile", snapshot.get_75th_percentile) | ||
| block.call("#{name}.95th_percentile", snapshot.get_95th_percentile) | ||
| block.call("#{name}.98th_percentile", snapshot.get_98th_percentile) | ||
| block.call("#{name}.99th_percentile", snapshot.get_99th_percentile) | ||
| block.call("#{name}.999th_percentile", snapshot.get_999th_percentile) | ||
| when Metriks::Histogram | ||
| block.call("#{name}.count", metric.count) | ||
| block.call("#{name}.min", metric.min) | ||
| block.call("#{name}.max", metric.max) | ||
| block.call("#{name}.median", metric.median) | ||
| block.call("#{name}.stddev", metric.stddev) | ||
|
|
||
| snapshot = metric.snapshot | ||
|
|
||
| block.call("#{name}.median", snapshot.median) | ||
| block.call("#{name}.75th_percentile", snapshot.get_75th_percentile) | ||
| block.call("#{name}.95th_percentile", snapshot.get_95th_percentile) | ||
| block.call("#{name}.98th_percentile", snapshot.get_98th_percentile) | ||
| block.call("#{name}.99th_percentile", snapshot.get_99th_percentile) | ||
| block.call("#{name}.999th_percentile", snapshot.get_999th_percentile) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only report like this, it means we won't actually report the marks that happened before the reporter was run for the first time.
Because we know these things are in-process, I think it would actually make more sense to initialize
@lastwith a default of0for the hash values:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.