From ab4f5f5da5229bbc33f3c86815eaf1e057c697b1 Mon Sep 17 00:00:00 2001 From: Effy Elden Date: Tue, 17 Jan 2017 22:00:03 +1100 Subject: Add Heroku deployment support --- config/environments/production.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'config/environments/production.rb') diff --git a/config/environments/production.rb b/config/environments/production.rb index 9254d494c..8b8d974b3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -45,10 +45,20 @@ Rails.application.configure do # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + # Parse and split the REDIS_URL if passed (used with hosting platforms such as Heroku). + # Set ENV variables because they are used elsewhere. + if ENV['REDIS_URL'] + redis_url = URI.parse(ENV['REDIS_URL']) + ENV['REDIS_HOST'] = redis_url.host + ENV['REDIS_PORT'] = redis_url.port.to_s + ENV['REDIS_PASSWORD'] = redis_url.password + end + # Use a different cache store in production. config.cache_store = :redis_store, { host: ENV.fetch('REDIS_HOST') { 'localhost' }, port: ENV.fetch('REDIS_PORT') { 6379 }, + password: ENV.fetch('REDIS_PASSWORD') { false }, db: 0, namespace: 'cache', expires_in: 20.minutes @@ -85,7 +95,7 @@ Rails.application.configure do :address => ENV['SMTP_SERVER'], :user_name => ENV['SMTP_LOGIN'], :password => ENV['SMTP_PASSWORD'], - :domain => config.x.local_domain, + :domain => ENV['SMTP_DOMAIN'] || config.x.local_domain, :authentication => :plain, } -- cgit From 306eb6e9c90295dcdff2a0094066542a46a8e634 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 18 Jan 2017 23:44:29 +0100 Subject: Add optional StatsD performance tracking --- Gemfile | 1 + Gemfile.lock | 2 ++ app/lib/statsd_monitor.rb | 11 +++++++++++ config/application.rb | 2 ++ config/environments/production.rb | 4 ++++ config/initializers/inflections.rb | 7 +++---- config/initializers/statsd.rb | 20 ++++++++++++++++++++ 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 app/lib/statsd_monitor.rb create mode 100644 config/initializers/statsd.rb (limited to 'config/environments/production.rb') diff --git a/Gemfile b/Gemfile index 6b8519369..1341e45de 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,7 @@ gem 'sidekiq' gem 'rails-settings-cached' gem 'pg_search' gem 'simple-navigation' +gem 'statsd-instrument' gem 'react-rails' gem 'browserify-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 2c009955e..7214d21eb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -370,6 +370,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + statsd-instrument (2.1.2) temple (0.7.7) term-ansicolor (1.4.0) tins (~> 1.0) @@ -463,6 +464,7 @@ DEPENDENCIES simple-navigation simple_form simplecov + statsd-instrument uglifier (>= 1.3.0) webmock will_paginate diff --git a/app/lib/statsd_monitor.rb b/app/lib/statsd_monitor.rb new file mode 100644 index 000000000..e48ce6541 --- /dev/null +++ b/app/lib/statsd_monitor.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class StatsDMonitor + def initialize(app) + @app = app + end + + def call(env) + @app.call(env) + end +end diff --git a/config/application.rb b/config/application.rb index e561d0473..e97fb165b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -30,6 +30,8 @@ module Mastodon config.active_job.queue_adapter = :sidekiq + config.middleware.insert(0, 'StatsDMonitor') + config.middleware.insert_before 0, Rack::Cors do allow do origins '*' diff --git a/config/environments/production.rb b/config/environments/production.rb index 8b8d974b3..30170e810 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -104,4 +104,8 @@ Rails.application.configure do config.react.variant = :production config.active_record.logger = nil + + config.to_prepare do + StatsD.backend = StatsD::Instrument::Backends::NullBackend if ENV['STATSD_ADDR'].blank? + end end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9d..8fd1ae72c 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -10,7 +10,6 @@ # inflect.uncountable %w( fish sheep ) # end -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end +ActiveSupport::Inflector.inflections(:en) do |inflect| + inflect.acronym 'StatsD' +end diff --git a/config/initializers/statsd.rb b/config/initializers/statsd.rb new file mode 100644 index 000000000..c9c754e7f --- /dev/null +++ b/config/initializers/statsd.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +StatsD.prefix = 'mastodon' +StatsD.default_sample_rate = 1 + +StatsDMonitor.extend(StatsD::Instrument) +StatsDMonitor.statsd_measure(:call, 'request.duration') + +STATSD_REQUEST_METRICS = { + 'request.status.success' => 200, + 'request.status.not_found' => 404, + 'request.status.too_many_requests' => 429, + 'request.status.internal_server_error' => 500, +}.freeze + +STATSD_REQUEST_METRICS.each do |name, code| + StatsDMonitor.statsd_count_if(:call, name) do |status, _env, _body| + status.to_i == code + end +end -- cgit From f051c2e8131616018486cfb9f4a80a120ca71f6e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 19 Jan 2017 09:37:07 +0100 Subject: Fix statsd null backend not being initialized properly --- Gemfile | 2 +- Gemfile.lock | 7 +++---- app/models/account.rb | 3 ++- config/environments/production.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'config/environments/production.rb') diff --git a/Gemfile b/Gemfile index 1341e45de..aa149c61e 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'dotenv-rails' gem 'font-awesome-rails' gem 'best_in_place', '~> 3.0.1' -gem 'paperclip', '~> 5.0' +gem 'paperclip', '~> 5.1' gem 'paperclip-av-transcoder' gem 'aws-sdk', '>= 2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7214d21eb..9b33580fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,8 +76,7 @@ GEM bullet (5.3.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.10.0) - climate_control (0.0.3) - activesupport (>= 3.0) + climate_control (0.1.0) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) coderay (1.1.1) @@ -89,7 +88,7 @@ GEM execjs coffee-script-source (1.10.0) colorize (0.8.1) - concurrent-ruby (1.0.3) + concurrent-ruby (1.0.4) connection_pool (2.2.1) crack (0.4.3) safe_yaml (~> 1.0.0) @@ -437,7 +436,7 @@ DEPENDENCIES nokogiri oj ostatus2 - paperclip (~> 5.0) + paperclip (~> 5.1) paperclip-av-transcoder pg pg_search diff --git a/app/models/account.rb b/app/models/account.rb index 621a66e24..c2a41c4c6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -126,7 +126,8 @@ class Account < ApplicationRecord def save_with_optional_avatar! save! rescue ActiveRecord::RecordInvalid - self.avatar = nil + self.avatar = nil + self[:avatar_remote_url] = '' save! end diff --git a/config/environments/production.rb b/config/environments/production.rb index 30170e810..1572eaf6c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -106,6 +106,6 @@ Rails.application.configure do config.active_record.logger = nil config.to_prepare do - StatsD.backend = StatsD::Instrument::Backends::NullBackend if ENV['STATSD_ADDR'].blank? + StatsD.backend = StatsD::Instrument::Backends::NullBackend.new if ENV['STATSD_ADDR'].blank? end end -- cgit From 67befe546342c58f1a16bdb08b6a2ef438e83d57 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 22 Jan 2017 20:35:49 +0100 Subject: Allow to specify trusted proxies through env --- config/environments/production.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'config/environments/production.rb') diff --git a/config/environments/production.rb b/config/environments/production.rb index 1572eaf6c..d2dfa4274 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -32,6 +32,9 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Allow to specify public IP of reverse proxy if it's needed + config.action_dispatch.trusted_proxies = [IPAddr.new(ENV['TRUSTED_PROXY_IP'])] unless ENV['TRUSTED_PROXY_IP'].blank? + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = false -- cgit