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 :prefix option on metrics creation #148

Merged
merged 9 commits into from
Nov 28, 2018

Conversation

timothysmith0609
Copy link
Contributor

Closes #69

Allows clients to pass in :prefix as an option to a metric. This allows classes that extend StatsD to avoid polluting the global namespace. The motivation for this is KubernetesDeploy #384, though it seems it's not the first app to feel the need for this.

The change is backwards compatible and purely opt-in

@timothysmith0609 timothysmith0609 self-assigned this Nov 27, 2018
@@ -2,7 +2,7 @@ require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new('test') do |t|
t.ruby_opts << '-rubygems'
t.ruby_opts << '-r rubygems'

Choose a reason for hiding this comment

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

unrelated change>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CI was complaining about this (and was in fact preventing me from testing locally)

@@ -47,7 +49,11 @@ def initialize(options = {})
@type = options[:type] or raise ArgumentError, "Metric :type is required."
@name = options[:name] or raise ArgumentError, "Metric :name is required."
@name = normalize_name(@name)
@name = StatsD.prefix ? "#{StatsD.prefix}.#{@name}" : @name unless options[:no_prefix]
@name = if options[:prefix]
Copy link

Choose a reason for hiding this comment

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

what happens if prefix & no_prefix are set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

prefix will override (which I should document).
I could be persuaded to have :no_prefix have greater precedence but it's 6 of 1, half-dozen of the other.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. no_prefix having precedence sounds less surprising to me.

lib/statsd/instrument.rb Outdated Show resolved Hide resolved
@@ -47,7 +49,11 @@ def initialize(options = {})
@type = options[:type] or raise ArgumentError, "Metric :type is required."
@name = options[:name] or raise ArgumentError, "Metric :name is required."
@name = normalize_name(@name)
@name = StatsD.prefix ? "#{StatsD.prefix}.#{@name}" : @name unless options[:no_prefix]
@name = if options[:prefix]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. no_prefix having precedence sounds less surprising to me.

@timothysmith0609 timothysmith0609 merged commit bb5e072 into master Nov 28, 2018
@timothysmith0609 timothysmith0609 deleted the allow_prefix_override branch November 28, 2018 14:12
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.

None yet

4 participants