From 9c524d8e0e91dce870fad274bde8daa6fea252e3 Mon Sep 17 00:00:00 2001 From: Alex Kriuchykhin Date: Wed, 23 Oct 2024 16:58:03 +0200 Subject: [PATCH] Exclude API status and health endpoints, scheduled jobs from NewRelic monitoring, update APM agent [SCI-11212] (#7987) --- Gemfile.lock | 2 +- app/controllers/api/api_controller.rb | 2 ++ app/jobs/my_modules/due_date_reminder_job.rb | 2 ++ app/jobs/notification_cleanup_job.rb | 2 ++ app/jobs/repository_item_date_reminder_job.rb | 2 ++ app/services/label_printers/fluics/sync_service.rb | 1 + app/services/templates_service.rb | 1 + config/environments/production.rb | 2 +- config/initializers/silencer.rb | 3 ++- config/routes.rb | 6 ++++-- 10 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 878d8ba33..e26778e55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -456,7 +456,7 @@ GEM timeout net-smtp (0.5.0) net-protocol - newrelic_rpm (9.2.2) + newrelic_rpm (9.14.0) nio4r (2.7.3) nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 27141eded..3eb460f18 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -8,6 +8,8 @@ module Api before_action :authenticate_request!, except: %i(status health) + newrelic_ignore only: %i(health status) + rescue_from StandardError do |e| logger.error e.message logger.error e.backtrace.join("\n") diff --git a/app/jobs/my_modules/due_date_reminder_job.rb b/app/jobs/my_modules/due_date_reminder_job.rb index 839f4d07f..8db0409cc 100644 --- a/app/jobs/my_modules/due_date_reminder_job.rb +++ b/app/jobs/my_modules/due_date_reminder_job.rb @@ -2,6 +2,8 @@ module MyModules class DueDateReminderJob < ApplicationJob + newrelic_ignore + def perform my_modules = MyModule.uncomplete.approaching_due_dates diff --git a/app/jobs/notification_cleanup_job.rb b/app/jobs/notification_cleanup_job.rb index cea9fa32f..61a939cb9 100644 --- a/app/jobs/notification_cleanup_job.rb +++ b/app/jobs/notification_cleanup_job.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class NotificationCleanupJob < ApplicationJob + newrelic_ignore + def perform Notification.where('created_at < ?', 3.months.ago).delete_all end diff --git a/app/jobs/repository_item_date_reminder_job.rb b/app/jobs/repository_item_date_reminder_job.rb index 0ed56f118..fe35ea0a8 100644 --- a/app/jobs/repository_item_date_reminder_job.rb +++ b/app/jobs/repository_item_date_reminder_job.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class RepositoryItemDateReminderJob < ApplicationJob + newrelic_ignore + queue_as :default def perform diff --git a/app/services/label_printers/fluics/sync_service.rb b/app/services/label_printers/fluics/sync_service.rb index 987a42c33..3510d3c48 100644 --- a/app/services/label_printers/fluics/sync_service.rb +++ b/app/services/label_printers/fluics/sync_service.rb @@ -9,6 +9,7 @@ module LabelPrinters end def sync_templates! + NewRelic::Agent.ignore_transaction LabelPrinter.fluics.each do |printer| api_client = ApiClient.new(printer.fluics_api_key) templates = api_client.list_templates diff --git a/app/services/templates_service.rb b/app/services/templates_service.rb index 8bdb18caf..5b2f5ba37 100644 --- a/app/services/templates_service.rb +++ b/app/services/templates_service.rb @@ -49,6 +49,7 @@ class TemplatesService end def update_all_templates + NewRelic::Agent.ignore_transaction processed_counter = 0 updated_counter = 0 Team.find_each do |team| diff --git a/config/environments/production.rb b/config/environments/production.rb index 5480eee37..bc4505cb3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,7 +73,7 @@ Rails.application.configure do # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = ENV['RAILS_FORCE_SSL'].present? - config.ssl_options = { redirect: { exclude: ->(request) { request.path =~ %r{api\/health} } } } + config.ssl_options = { redirect: { exclude: ->(request) { request.path =~ %r{api/health|status} } } } # Use the lowest log level to ensure availability of diagnostic information # when problems arise. diff --git a/config/initializers/silencer.rb b/config/initializers/silencer.rb index cccc5657b..2b442e781 100644 --- a/config/initializers/silencer.rb +++ b/config/initializers/silencer.rb @@ -8,7 +8,8 @@ Rails.application.configure do silence: [ # Silence WickedPDF rendering in logs %r{/projects/[0-9]*/reports/generate.pdf}, - '/api/health' + '/api/health', + '/api/status' ] ) end diff --git a/config/routes.rb b/config/routes.rb index 0fdc7fe93..7a08d12f2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,10 @@ Rails.application.routes.draw do skip_controllers :applications, :authorized_applications, :token_info end + # Global healthcheck endpoints + get 'api/health', to: 'api/api#health', as: 'api_health' + get 'api/status', to: 'api/api#status', as: 'api_status' + post 'access_tokens/revoke', to: 'doorkeeper/access_tokens#revoke' # Addons @@ -901,8 +905,6 @@ Rails.application.routes.draw do end namespace :api, defaults: { format: 'json' } do - get 'health', to: 'api#health' - get 'status', to: 'api#status' namespace :service do post 'projects_json_export', to: 'projects_json_export#projects_json_export' resources :teams, only: [] do