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
attempt to correct invalid metric names #108
Conversation
Ping @jstorimer or @wvanbergen for review. |
I am a bit worried about adding a
|
Thanks for pointing that out! It definitely is much faster using I did only a simple benchmark with a single name and the difference was pretty clear. There's definitely a cost to doing this in terms of performance. with original PR change using gsub:
using tr:
simply returning name:
|
lib/statsd/instrument/metric.rb
Outdated
# @return [String] | ||
def self.normalize_name(name) | ||
name.tr(':|', '_') | ||
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.
Any thoughts on making this method a private instance method? I don't see how it could be useful to anyone to use it outside of the Metric class.
Maybe normalize_tags could be made a private instance method at some point, but that would break compatibility with previous versions.
Datadog's implementation seems to be stripping even more invalid characters https://github.com/DataDog/dogstatsd-ruby/blob/master/lib/datadog/statsd.rb#L396-L398. Not sure if that's specific to their implementation or to the spec though as I can't find a reliable one anywhere |
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.
I am happy with this now if you can address @maximebedard's questions.
Thanks for the feedback! I made the changes that I think you were recommending. Since this is no longer a static method and the need for benchmarking was temporary, I also removed the benchmark file (it didn't work after change). |
I'm also unclear on the spec since DataDog has implemented their own protocol. My change also added the |
I think two underscores are acceptable to not have to take the performance hit of |
Attempt to correct an invalid name for a metric. Today it tries to send along to upstream StatsD server as-is which will reject the metric.