From 57aa72eceef72c4e8dd527beee540885626842d5 Mon Sep 17 00:00:00 2001 From: Jesus Federico Date: Mon, 8 Apr 2019 16:06:14 -0400 Subject: [PATCH] GRN-73: Added settings for externalizing logs (#441) * Added settoings for externalizing logs * Fix for passing rubocop * Attempt to fix jenkins fail * Final Jenkins fix --- Gemfile | 4 ++-- Gemfile.lock | 4 ++++ config/environments/production.rb | 7 ++++++- sample.env | 8 ++++++++ spec/controllers/rooms_controller_spec.rb | 6 +++--- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 7da2a440..80b99f7a 100644 --- a/Gemfile +++ b/Gemfile @@ -91,7 +91,6 @@ group :test do gem 'faker' gem "factory_bot_rails" gem 'webmock' - # Ruby linting. gem 'rubocop' end @@ -100,12 +99,13 @@ group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '~> 3.0.5' - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end +gem 'remote_syslog_logger' + # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index c2a223c6..1b404a93 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -221,6 +221,8 @@ GEM ffi (>= 0.5.0, < 2) redcarpet (3.4.0) redis (3.3.5) + remote_syslog_logger (1.0.4) + syslog_protocol rest-client (2.0.2) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) @@ -293,6 +295,7 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) + syslog_protocol (0.9.2) tabler-rubygem (0.1.2) autoprefixer-rails (>= 6.0.3) term-ansicolor (1.6.0) @@ -359,6 +362,7 @@ DEPENDENCIES random_password redcarpet redis (~> 3.0) + remote_syslog_logger rspec-rails (~> 3.7) rubocop sass-rails (~> 5.0) diff --git a/config/environments/production.rb b/config/environments/production.rb index f63fd8df..10743429 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -99,9 +99,14 @@ Rails.application.configure do # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"] == "true" - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) + elsif ENV["RAILS_LOG_REMOTE_NAME"] && ENV["RAILS_LOG_REMOTE_PORT"] + require 'remote_syslog_logger' + logger_program = ENV["RAILS_LOG_REMOTE_TAG"] || "greenlight-#{ENV['RAILS_ENV']}" + config.logger = RemoteSyslogLogger.new(ENV["RAILS_LOG_REMOTE_NAME"], + ENV["RAILS_LOG_REMOTE_PORT"], program: logger_program) end # Do not dump schema after migrations. diff --git a/sample.env b/sample.env index a433a281..97baf5db 100644 --- a/sample.env +++ b/sample.env @@ -159,4 +159,12 @@ PAGINATION_NUMBER=25 # https://docs.docker.com/config/containers/logging/syslog/#options # https://help.papertrailapp.com/kb/configuration/encrypting-remote-syslog-with-tls-ssl/ # +# For sending logs to a remote aggregator enable these variables: +# +# RAILS_LOG_REMOTE_NAME=logxx.papertrailapp.com +# RAILS_LOG_REMOTE_PORT=9999 +# RAILS_LOG_REMOTE_TAG=greenlight +# +# Force SSL +# # ENABLE_SSL=true diff --git a/spec/controllers/rooms_controller_spec.rb b/spec/controllers/rooms_controller_spec.rb index 803a82bb..9098d1da 100644 --- a/spec/controllers/rooms_controller_spec.rb +++ b/spec/controllers/rooms_controller_spec.rb @@ -133,7 +133,7 @@ describe RoomsController, type: :controller do @request.session[:user_id] = @user.id post :join, params: { room_uid: @room, join_name: @user.name } - expect(response).to redirect_to(@user.main_room.join_path(@user.name, {}, @user.uid)) + expect(response).to redirect_to(@owner.main_room.join_path(@user.name, {}, @user.uid)) end it "should use join name if user is not logged in and meeting running" do @@ -141,7 +141,7 @@ describe RoomsController, type: :controller do post :join, params: { room_uid: @room, join_name: "Join Name" } - expect(response).to redirect_to(@user.main_room.join_path("Join Name", {})) + expect(response).to redirect_to(@owner.main_room.join_path("Join Name", {})) end it "should render wait if meeting isn't running" do @@ -159,7 +159,7 @@ describe RoomsController, type: :controller do @request.session[:user_id] = @owner.id post :join, params: { room_uid: @room, join_name: @owner.name } - expect(response).to redirect_to(@user.main_room.join_path(@owner.name, { user_is_moderator: true }, @owner.uid)) + expect(response).to redirect_to(@owner.main_room.join_path(@owner.name, { user_is_moderator: true }, @owner.uid)) end it "redirects to root if owner of room is not verified" do