Replace self-rolled statsd instrumention with localshred/nsa (#5118)

This commit is contained in:
Eugen Rochko 2017-09-29 03:16:44 +02:00 committed by GitHub
parent f4ca116ea8
commit 35a8cafa35
4 changed files with 19 additions and 22 deletions

View file

@ -42,6 +42,7 @@ gem 'kaminari', '~> 1.0'
gem 'link_header', '~> 0.0' gem 'link_header', '~> 0.0'
gem 'mime-types', '~> 3.1' gem 'mime-types', '~> 3.1'
gem 'nokogiri', '~> 1.7' gem 'nokogiri', '~> 1.7'
gem 'nsa', '~> 0.2'
gem 'oj', '~> 3.0' gem 'oj', '~> 3.0'
gem 'ostatus2', '~> 2.0' gem 'ostatus2', '~> 2.0'
gem 'ox', '~> 2.5' gem 'ox', '~> 2.5'
@ -64,7 +65,6 @@ gem 'sidekiq-bulk', '~>0.1.1'
gem 'simple-navigation', '~> 4.0' gem 'simple-navigation', '~> 4.0'
gem 'simple_form', '~> 3.4' gem 'simple_form', '~> 3.4'
gem 'sprockets-rails', '~> 3.2', require: 'sprockets/railtie' gem 'sprockets-rails', '~> 3.2', require: 'sprockets/railtie'
gem 'statsd-instrument', '~> 2.1'
gem 'twitter-text', '~> 1.14' gem 'twitter-text', '~> 1.14'
gem 'tzinfo-data', '~> 1.2017' gem 'tzinfo-data', '~> 1.2017'
gem 'webpacker', '~> 3.0' gem 'webpacker', '~> 3.0'

View file

@ -289,6 +289,11 @@ GEM
mini_portile2 (~> 2.2.0) mini_portile2 (~> 2.2.0)
nokogumbo (1.4.13) nokogumbo (1.4.13)
nokogiri nokogiri
nsa (0.2.4)
activesupport (>= 4.2, < 6)
concurrent-ruby (~> 1.0.0)
sidekiq (>= 3.5.0)
statsd-ruby (~> 1.2.0)
oj (3.3.5) oj (3.3.5)
openssl (2.0.5) openssl (2.0.5)
orm_adapter (0.5.0) orm_adapter (0.5.0)
@ -483,7 +488,7 @@ GEM
sshkit (1.14.0) sshkit (1.14.0)
net-scp (>= 1.1.2) net-scp (>= 1.1.2)
net-ssh (>= 2.8.0) net-ssh (>= 2.8.0)
statsd-instrument (2.1.4) statsd-ruby (1.2.1)
strong_migrations (0.1.9) strong_migrations (0.1.9)
activerecord (>= 3.2.0) activerecord (>= 3.2.0)
temple (0.8.0) temple (0.8.0)
@ -578,6 +583,7 @@ DEPENDENCIES
microformats (~> 4.0) microformats (~> 4.0)
mime-types (~> 3.1) mime-types (~> 3.1)
nokogiri (~> 1.7) nokogiri (~> 1.7)
nsa (~> 0.2)
oj (~> 3.0) oj (~> 3.0)
ostatus2 (~> 2.0) ostatus2 (~> 2.0)
ox (~> 2.5) ox (~> 2.5)
@ -617,7 +623,6 @@ DEPENDENCIES
simple_form (~> 3.4) simple_form (~> 3.4)
simplecov (~> 0.14) simplecov (~> 0.14)
sprockets-rails (~> 3.2) sprockets-rails (~> 3.2)
statsd-instrument (~> 2.1)
strong_migrations strong_migrations
twitter-text (~> 1.14) twitter-text (~> 1.14)
tzinfo-data (~> 1.2017) tzinfo-data (~> 1.2017)

View file

@ -90,11 +90,6 @@ Rails.application.configure do
config.action_mailer.delivery_method = ENV.fetch('SMTP_DELIVERY_METHOD', 'smtp').to_sym config.action_mailer.delivery_method = ENV.fetch('SMTP_DELIVERY_METHOD', 'smtp').to_sym
config.to_prepare do
StatsD.backend = StatsD::Instrument::Backends::NullBackend.new if ENV['STATSD_ADDR'].blank?
Sidekiq::Logging.logger.level = Logger::WARN
end
config.action_dispatch.default_headers = { config.action_dispatch.default_headers = {
'Server' => 'Mastodon', 'Server' => 'Mastodon',
'X-Frame-Options' => 'DENY', 'X-Frame-Options' => 'DENY',

View file

@ -1,18 +1,15 @@
# frozen_string_literal: true # frozen_string_literal: true
RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
StatsD.prefix = 'mastodon' if ENV['STATSD_ADDR'].present?
StatsD.default_sample_rate = 1 host, port = ENV['STATSD_ADDR'].split(':')
def clean_name(str) statsd = ::Statsd.new(host, port)
str.gsub('::', '.').gsub(RESERVED_CHARACTERS_REGEX, '_') statsd.namespace = ['Mastodon', Rails.env].join('.')
end
::NSA.inform_statsd(statsd) do |informant|
ActiveSupport::Notifications.subscribe(/performance/) do |name, _start, _finish, _id, payload| informant.collect(:action_controller, :web)
action = payload[:action] || :increment informant.collect(:active_record, :db)
measurement = payload[:measurement] informant.collect(:cache, :cache)
value = payload[:value] informant.collect(:sidekiq, :sidekiq)
key_name = clean_name("#{name}.#{measurement}") end
StatsD.send(action.to_s, key_name, (value || 1))
end end