about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-26 19:46:52 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-26 19:46:52 +0100
commitf6a5977f0b2986b15ca8254123053e1a59647cd1 (patch)
treefeb2f4993726c14e95a260ebd4def172ad817c66
parentd567f21d4f4c3feb09a08443cf75eb583904093b (diff)
Fix key names in statsd
-rw-r--r--config/initializers/statsd.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/config/initializers/statsd.rb b/config/initializers/statsd.rb
index 4e772a5ed..f00b1d401 100644
--- a/config/initializers/statsd.rb
+++ b/config/initializers/statsd.rb
@@ -1,13 +1,18 @@
 # frozen_string_literal: true
+RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
 
 StatsD.prefix              = 'mastodon'
 StatsD.default_sample_rate = 1
 
+def clean_name(str)
+  str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_')
+end
+
 ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
   action      = payload[:action] || :increment
   measurement = payload[:measurement]
   value       = payload[:value]
-  key_name    = "#{name}.#{measurement}"
+  key_name    = clean_name("#{name}.#{measurement}")
 
   StatsD.send(action.to_s, key_name, (value || 1))
 end