Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
obs:server:fedora:2.8:testing
obs-server
obs-server-2.8-0106-api-Rails-5.1-Replace-Hopto...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File obs-server-2.8-0106-api-Rails-5.1-Replace-HoptoadNotifier-by-airbrake.patch of Package obs-server
From 08f3dd6a8b66d63ad32a41767c4fdd86ce510e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= <bgeuken@suse.de> Date: Wed, 14 Jun 2017 12:45:24 +0200 Subject: [PATCH] [api] Rails 5.1: Replace HoptoadNotifier by airbrake HoptoadNotifier is deprecated since many years. With the most recent rails update we had to switch to a different tool. The HoptoadNotifier github page is advertising airbrake. --- src/api/Gemfile | 2 +- src/api/Gemfile.lock | 12 ++- .../app/controllers/webui/request_controller.rb | 2 +- src/api/app/jobs/create_job.rb | 4 +- src/api/app/models/package.rb | 2 +- src/api/app/models/update_notification_events.rb | 6 +- src/api/config/initializers/airbrake.rb | 100 +++++++++++++++++++++ src/api/config/initializers/hoptoad.rb | 35 -------- src/api/config/options.yml.example | 1 + 9 files changed, 118 insertions(+), 46 deletions(-) create mode 100644 src/api/config/initializers/airbrake.rb delete mode 100644 src/api/config/initializers/hoptoad.rb diff --git a/src/api/Gemfile b/src/api/Gemfile index 2fa3e0db4..4f60e5bbb 100644 --- a/src/api/Gemfile +++ b/src/api/Gemfile @@ -11,7 +11,7 @@ gem 'nokogiri', '~>1.7.0' # for delayed tasks gem 'delayed_job_active_record', '>= 4.0.0' # to fill errbit -gem 'hoptoad_notifier', "~> 2.3" +gem 'airbrake' # as JSON library - the default json conflicts with activerecord (by means of vice-versa monkey patching) gem 'yajl-ruby' # to search the database diff --git a/src/api/Gemfile.lock b/src/api/Gemfile.lock index 9a1706ae0..547304e5d 100644 --- a/src/api/Gemfile.lock +++ b/src/api/Gemfile.lock @@ -49,6 +49,9 @@ GEM activerecord (>= 3.0.0) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) + airbrake (6.1.2) + airbrake-ruby (~> 2.2, >= 2.2.5) + airbrake-ruby (2.2.6) ansi (1.5.0) arel (8.0.0) ast (2.3.0) @@ -125,9 +128,11 @@ GEM haml (4.0.7) tilt hashdiff (0.3.0) - hoptoad_notifier (2.4.11) - activesupport - builder + html2haml (2.2.0) + erubis (~> 2.7.0) + haml (>= 4.0, < 6) + nokogiri (>= 1.6.0) + ruby_parser (~> 3.5) i18n (0.8.0) innertube (1.1.0) joiner (0.3.4) @@ -362,6 +367,7 @@ DEPENDENCIES activemodel-serializers-xml acts_as_list acts_as_tree + airbrake bundler capybara_minitest_spec chunky_png diff --git a/src/api/app/controllers/webui/request_controller.rb b/src/api/app/controllers/webui/request_controller.rb index 5a38de530..ad313be9c 100644 --- a/src/api/app/controllers/webui/request_controller.rb +++ b/src/api/app/controllers/webui/request_controller.rb @@ -227,7 +227,7 @@ class Webui::RequestController < Webui::WebuiController end end rescue APIException => e - HoptoadNotifier.notify(e, { failed_job: "Failed to forward BsRequest '#{params[:number]}'" }) + Airbrake.notify(e, { failed_job: "Failed to forward BsRequest '#{params[:number]}'" }) flash[:error] = "Unable to forward submit: #{e.message}" redirect_to(request_show_path(params[:number])) && return end diff --git a/src/api/app/jobs/create_job.rb b/src/api/app/jobs/create_job.rb index 15fbb8c6f..1fab0196b 100644 --- a/src/api/app/jobs/create_job.rb +++ b/src/api/app/jobs/create_job.rb @@ -14,11 +14,11 @@ class CreateJob def error(job, exception) if Rails.env.test? - # make debug output useful in test suite, not just showing backtrace to HoptoaddNotifier + # make debug output useful in test suite, not just showing backtrace to Airbrake Rails.logger.debug "ERROR: #{exception.inspect}: #{exception.backtrace}" puts exception.inspect, exception.backtrace return end - HoptoadNotifier.notify(exception, {failed_job: job.inspect}) + Airbrake.notify(exception, {failed_job: job.inspect}) end end diff --git a/src/api/app/models/package.rb b/src/api/app/models/package.rb index 2e1c0f82e..bbb1f864e 100644 --- a/src/api/app/models/package.rb +++ b/src/api/app/models/package.rb @@ -561,7 +561,7 @@ class Package < ApplicationRecord if Rails.env.test? raise e else - HoptoadNotifier.notify(e, { failed_job: "Couldn't store channel" }) + Airbrake.notify(e, { failed_job: "Couldn't store channel" }) end end else diff --git a/src/api/app/models/update_notification_events.rb b/src/api/app/models/update_notification_events.rb index 233ba8153..0bf80ed8d 100644 --- a/src/api/app/models/update_notification_events.rb +++ b/src/api/app/models/update_notification_events.rb @@ -25,15 +25,15 @@ class UpdateNotificationEvents rescue ActiveRecord::StatementInvalid => e retries = retries - 1 retry if retries > 0 - HoptoadNotifier.notify(e, {failed_job: "RETRYED 10 times: #{type.inspect}: #{data}"}) + Airbrake.notify(e, {failed_job: "RETRYED 10 times: #{type.inspect}: #{data}"}) return rescue => e if Rails.env.test? - # make debug output useful in test suite, not just showing backtrace to HoptoaddNotifier + # make debug output useful in test suite, not just showing backtrace to Airbrake Rails.logger.error "ERROR: #{e.inspect}: #{e.backtrace}" puts e.inspect, e.backtrace end - HoptoadNotifier.notify(e, {failed_job: type.inspect}) + Airbrake.notify(e, {failed_job: type.inspect}) return end diff --git a/src/api/config/initializers/airbrake.rb b/src/api/config/initializers/airbrake.rb new file mode 100644 index 000000000..8b9057c5b --- /dev/null +++ b/src/api/config/initializers/airbrake.rb @@ -0,0 +1,100 @@ +# Airbrake is an online tool that provides robust exception tracking in your Rails +# applications. In doing so, it allows you to easily review errors, tie an error +# to an individual piece of code, and trace the cause back to recent +# changes. Airbrake enables for easy categorization, searching, and prioritization +# of exceptions so that when errors occur, your team can quickly determine the +# root cause. +# +# Configuration details: +# https://github.com/airbrake/airbrake-ruby#configuration +Airbrake.configure do |c| + c.host = CONFIG['errbit_host'] + # You must set both project_id & project_key. To find your project_id and + # project_key navigate to your project's General Settings and copy the values + # from the right sidebar. + # https://github.com/airbrake/airbrake-ruby#project_id--project_key + c.project_id = CONFIG['errbit_project_id'] + c.project_key = CONFIG['errbit_api_key'] + + # Configures the root directory of your project. Expects a String or a + # Pathname, which represents the path to your project. Providing this option + # helps us to filter out repetitive data from backtrace frames and link to + # GitHub files from our dashboard. + # https://github.com/airbrake/airbrake-ruby#root_directory + c.root_directory = Rails.root + + # By default, Airbrake Ruby outputs to STDOUT. In Rails apps it makes sense to + # use the Rails' logger. + # https://github.com/airbrake/airbrake-ruby#logger + c.logger = Rails.logger + + # Configures the environment the application is running in. Helps the Airbrake + # dashboard to distinguish between exceptions occurring in different + # environments. + # NOTE: This option must be set in order to make the 'ignore_environments' + # option work. + # https://github.com/airbrake/airbrake-ruby#environment + c.environment = Rails.env + + # Setting this option allows Airbrake to filter exceptions occurring in + # unwanted environments such as :test. + # NOTE: This option *does not* work if you don't set the 'environment' option. + # https://github.com/airbrake/airbrake-ruby#ignore_environments + if CONFIG['errbit_api_key'].blank? + c.ignore_environments = %w(production development test) + else + c.ignore_environments = %w(development test) + end + + # A list of parameters that should be filtered out of what is sent to + # Airbrake. By default, all "password" attributes will have their contents + # replaced. + # https://github.com/airbrake/airbrake-ruby#blacklist_keys + c.blacklist_keys = [/password/i, /authorization/i] + + # Alternatively, you can integrate with Rails' filter_parameters. + # Read more: https://goo.gl/gqQ1xS + # c.blacklist_keys = Rails.application.config.filter_parameters +end + +# A filter that collects request body information. Enable it if you are sure you +# don't send sensitive information to Airbrake in your body (such as passwords). +# https://github.com/airbrake/airbrake#requestbodyfilter +# Airbrake.add_filter(Airbrake::Rack::RequestBodyFilter.new) + +# If you want to convert your log messages to Airbrake errors, we offer an +# integration with the Logger class from stdlib. +# https://github.com/airbrake/airbrake#logger +# Rails.logger = Airbrake::AirbrakeLogger.new(Rails.logger) +def ignore_by_class_and_message?(notice) + notice[:errors].any? do |error| + error[:type] == 'ActionController::RoutingError' && + error[:message] =~ /Required Parameter|\[GET\]|Expected AJAX call/ + end +end + +def ignore_by_class?(notice) + exceptions_to_ignore = %w( + ActiveRecord::RecordNotFound + ActionController::InvalidAuthenticityToken + CGI::Session::CookieStore::TamperedWithCookie + ActionController::UnknownAction + AbstractController::ActionNotFound + ActionView::MissingTemplate + Timeout::Error + Net::HTTPBadResponse + WebuiMatcher::InvalidRequestFormat + ActionController::UnknownFormat + ActiveXML::Transport::NotFoundError + ) + + (notice[:errors].map { |error| error[:type] } & exceptions_to_ignore).any? +end + +def ignore_exception?(notice) + ignore_by_class?(notice) || ignore_by_class_and_message?(notice) +end + +Airbrake.add_filter do |notice| + notice.ignore! if ignore_exception?(notice) +end diff --git a/src/api/config/initializers/hoptoad.rb b/src/api/config/initializers/hoptoad.rb deleted file mode 100644 index 42468f245..000000000 --- a/src/api/config/initializers/hoptoad.rb +++ /dev/null @@ -1,35 +0,0 @@ -HoptoadNotifier.configure do |config| - # Change this to some sensible data for your errbit instance - config.api_key = CONFIG['errbit_api_key'] || 'YOUR_ERRBIT_API_KEY' - config.host = CONFIG['errbit_host'] || 'YOUR_ERRBIT_HOST' - if CONFIG['errbit_api_key'].blank? - config.development_environments = "production development test" - else - config.development_environments = "development test" - end - - config.ignore_only = %w{ - ActiveRecord::RecordNotFound - ActionController::InvalidAuthenticityToken - CGI::Session::CookieStore::TamperedWithCookie - ActionController::UnknownAction - AbstractController::ActionNotFound - ActionView::MissingTemplate - Timeout::Error - Net::HTTPBadResponse - WebuiMatcher::InvalidRequestFormat - ActionController::UnknownFormat - ActiveXML::Transport::NotFoundError - } - - config.ignore_by_filter do |exception_data| - ret = false - if exception_data[:error_class] == "ActionController::RoutingError" - message = exception_data[:error_message] - ret = true if message =~ %r{Required Parameter} - ret = true if message =~ %r{\[GET\]} - ret = true if message =~ %r{Expected AJAX call} - end - ret - end -end diff --git a/src/api/config/options.yml.example b/src/api/config/options.yml.example index d77203e6c..5591dc3dd 100644 --- a/src/api/config/options.yml.example +++ b/src/api/config/options.yml.example @@ -55,6 +55,7 @@ proxy_auth_test_email: coolguy@example.com # see http://colszowka.heroku.com/2011/02/22/setting-up-your-custom-hoptoad-notifier-endpoint-for-free-using-errbit-on-heroku #errbit_api_key: api_key_of_your_app +#errbit_project_id: #errbit_host: installation.of.errbit.com ################## -- 2.14.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Log In
Places
Places
All Projects
Status Monitor