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

Allow selection of which metrics to submit from Librato metrics reporter #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/metriks/reporter/librato_metrics.rb
Expand Up @@ -12,6 +12,12 @@ def initialize(email, token, options = {})
@registry = options[:registry] || Metriks::Registry.default
@interval = 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] || []
Copy link
Owner

Choose a reason for hiding this comment

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

Defaulting these to an empty array is going to cause the if's later on to always evaluate to true.

I think this may be worth a test case to not break things.

end

def start
Expand Down Expand Up @@ -121,6 +127,15 @@ def prepare_metric(base_name, metric, keys, snapshot_keys = [])
base_name = "#{@prefix}.#{base_name}"
end

if @only
Copy link
Owner

Choose a reason for hiding this comment

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

With the defaulting above, this is going to need to be if @only && !@only.empty? — same with the @except one.

keys = keys & @only
snapshot_keys = snapshot_keys & @only
end
if @except
keys = keys - @except
snapshot_keys = snapshot_keys - @except
end

keys.flatten.each do |key|
name = key.to_s.gsub(/^get_/, '')
value = metric.send(key)
Expand Down