Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Cleaned up selection of librato metics #19

Open
wants to merge 4 commits into from

4 participants

Justin Love Eric Lindvall Benjamin Fritsch Ryan Lower
Justin Love

I took Ryanlower's selection code, (eric/metriks#9) made the necessary checks for empty filters, and added a few tests to cover the new cases. Did a very simple extract-method to support the tests.

Eric Lindvall
Owner

This looks pretty sweet. Thanks!

Benjamin Fritsch

hey,

what happened to the pull request? just read through the related issues and couldn't find a hint why this isn't merged yet.

how can i help to get this merged?

Eric Lindvall
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
23 lib/metriks/reporter/librato_metrics.rb
View
@@ -15,6 +15,12 @@ def initialize(email, token, options = {})
@registry = options[:registry] || Metriks::Registry.default
@time_tracker = Metriks::TimeTracker.new(options[:interval] || 60)
@on_error = options[:on_error] || proc { |ex| }
+
+ if options[:only] and options[:except]
+ raise 'Can only specify one of :only or :except'
+ end
+ @only = options[:only] || []
+ @except = options[:except] || []
end
def start
@@ -43,7 +49,7 @@ def restart
start
end
- def write
+ def prepare_metrics
gauges = []
@registry.each do |name, metric|
gauges << case metric
@@ -84,9 +90,13 @@ def write
end
gauges.flatten!
+ gauges
+ end
+ def write
+ gauges = prepare_metrics
unless gauges.empty?
- submit(form_data(gauges.flatten))
+ submit(form_data(gauges))
end
end
@@ -146,6 +156,15 @@ def prepare_metric(base_name, metric, keys, snapshot_keys = [])
base_name = "#{@prefix}.#{base_name}"
end
+ if @only.any?
+ keys = keys & @only
+ snapshot_keys = snapshot_keys & @only
+ end
+ if @except.any?
+ keys = keys - @except
+ snapshot_keys = snapshot_keys - @except
+ end
+
keys.flatten.each do |key|
name = key.to_s.gsub(/^get_/, '')
value = metric.send(key)
21 test/librato_metrics_reporter_test.rb
View
@@ -31,4 +31,23 @@ def test_write
@reporter.write
end
-end
+
+ def assert_generated(count, options)
+ @registry.timer('timer.testing').update(1.5)
+
+ metrics = build_reporter(options).prepare_metrics
+ assert_equal(count, metrics.length)
+ end
+
+ def test_no_filters
+ assert_generated(11, {})
+ end
+
+ def test_only
+ assert_generated(2, {:only => [:count, :median]})
+ end
+
+ def test_except
+ assert_generated(9, {:except => [:count, :median]})
+ end
+end
Something went wrong with that request. Please try again.