<commit_before># frozen_string_literal: true

StatsD.prefix              = 'mastodon'
StatsD.default_sample_rate = 1

ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload|
  action      = payload[:action] || :increment
  measurement = payload[:measurement]
  value       = payload[:value]
  key_name    = "#{name}.#{measurement}"

  StatsD.send(action.to_s, key_name, (value || 1))
end<commit_msg>Fix key names in statsd<commit_after># 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    = clean_name("#{name}.#{measurement}")

  StatsD.send(action.to_s, key_name, (value || 1))
end
{'fraction_non_alphanumeric': 0.14691478942213515, 'fraction_numerical': 0.0039177277179236044, 'mean_word_length': 4.350785340314136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485835', 'n_tokens_mistral': 352, 'n_tokens_neox': 344, 'n_words': 65}