From e4799d9f837ea11b48d0e3af3f99c108afe293bb Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:52:31 +0100 Subject: [PATCH] [Prod] Dump NewRelic Need to look into alternatives --- .env.sample | 5 -- Gemfile | 1 - Gemfile.lock | 2 - app/logical/danbooru_logger.rb | 10 +-- app/logical/related_tag_calculator.rb | 2 +- app/models/application_record.rb | 2 +- app/models/tag.rb | 2 +- .../initializers/content_security_policy.rb | 4 +- config/newrelic.yml | 72 ------------------- docker-compose.yml | 2 - lib/tasks/maintenance.rake | 2 - 11 files changed, 7 insertions(+), 97 deletions(-) delete mode 100644 config/newrelic.yml diff --git a/.env.sample b/.env.sample index 8f6c37db4..7edea10b9 100644 --- a/.env.sample +++ b/.env.sample @@ -64,8 +64,3 @@ # JOINER_OAUTH2_CLIENT_SECRET= # JOINER_GUILD_ID= # JOINER_FAILED_JOIN_WEBHOOK_URL= - -# Enable the NewRelic integration - -# NEW_RELIC_AGENT_ENABLED=true -# NEW_RELIC_LICENSE_KEY=your_license_key diff --git a/Gemfile b/Gemfile index 7db0bb8dc..29d0d8b61 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,6 @@ gem 'marcel' gem 'sidekiq-unique-jobs' gem 'redis' gem 'request_store' -gem 'newrelic_rpm' gem "diffy" gem "rugged" diff --git a/Gemfile.lock b/Gemfile.lock index 02b6cf781..3c020f23c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -201,7 +201,6 @@ GEM net-smtp (0.4.0.1) net-protocol netrc (0.11.0) - newrelic_rpm (9.7.1) nio4r (2.7.0) nokogiri (1.16.0) mini_portile2 (~> 2.8.2) @@ -392,7 +391,6 @@ DEPENDENCIES mailgun-ruby marcel mocha - newrelic_rpm opensearch-ruby pg puma diff --git a/app/logical/danbooru_logger.rb b/app/logical/danbooru_logger.rb index 3524fedd8..4ce6e740b 100644 --- a/app/logical/danbooru_logger.rb +++ b/app/logical/danbooru_logger.rb @@ -1,17 +1,13 @@ # frozen_string_literal: true class DanbooruLogger - def self.log(exception, expected: false, **params) + def self.log(exception, expected: false, **_params) if expected Rails.logger.info("#{exception.class}: #{exception.message}") else backtrace = Rails.backtrace_cleaner.clean(exception.backtrace).join("\n") Rails.logger.error("#{exception.class}: #{exception.message}\n#{backtrace}") end - - if defined?(::NewRelic) && !expected - ::NewRelic::Agent.notice_error(exception, expected: expected, custom_params: params) - end end def self.initialize(user) @@ -19,8 +15,6 @@ class DanbooruLogger end def self.add_attributes(**) - return unless defined?(::NewRelic) - - ::NewRelic::Agent.add_custom_attributes(**) + # noop end end diff --git a/app/logical/related_tag_calculator.rb b/app/logical/related_tag_calculator.rb index baf16cfc3..d100e88af 100644 --- a/app/logical/related_tag_calculator.rb +++ b/app/logical/related_tag_calculator.rb @@ -22,7 +22,7 @@ class RelatedTagCalculator end def self.calculate_from_sample(tags, sample_size, category_constraint = nil, max_results = MAX_RESULTS) - Post.with_timeout(5_000, [], {:tags => tags}) do + Post.with_timeout(5_000, []) do sample = Post.sample(tags, sample_size) posts_with_tags = sample.with_unflattened_tags diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 8e7385631..fee98b356 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -210,7 +210,7 @@ class ApplicationRecord < ActiveRecord::Base connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env == "test" end - def with_timeout(n, default_value = nil, new_relic_params = {}) + def with_timeout(n, default_value = nil) connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test" yield rescue ::ActiveRecord::StatementInvalid => x diff --git a/app/models/tag.rb b/app/models/tag.rb index e874c8805..819dbdff1 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -117,7 +117,7 @@ class Tag < ApplicationRecord end def update_category_post_counts! - Post.with_timeout(30_000, nil, {:tags => name}) do + Post.with_timeout(30_000, nil) do Post.sql_raw_tag_match(name).find_each do |post| post.set_tag_counts(disable_cache: false) args = TagCategory::CATEGORIES.to_h { |x| ["tag_count_#{x}", post.send("tag_count_#{x}")] }.update("tag_count" => post.tag_count) diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 709c58c34..2023e2207 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -9,9 +9,9 @@ Rails.application.configure do config.content_security_policy do |policy| policy.default_src :self - policy.script_src :self, 'ads.dragonfru.it', 'js-agent.newrelic.com', 'bam.nr-data.net', 'https://www.google.com/recaptcha/', 'https://www.gstatic.com/recaptcha/', 'https://www.recaptcha.net/' + policy.script_src :self, "ads.dragonfru.it", "https://www.google.com/recaptcha/", "https://www.gstatic.com/recaptcha/", "https://www.recaptcha.net/" policy.style_src :self, :unsafe_inline - policy.connect_src :self, 'ads.dragonfru.it', 'bam.nr-data.net', 'plausible.dragonfru.it' + policy.connect_src :self, "ads.dragonfru.it", "plausible.dragonfru.it" policy.object_src :self, 'static1.e621.net', 'static1.e926.net' policy.media_src :self, 'static1.e621.net', 'static1.e926.net' policy.frame_ancestors :none diff --git a/config/newrelic.yml b/config/newrelic.yml deleted file mode 100644 index 33ff054d8..000000000 --- a/config/newrelic.yml +++ /dev/null @@ -1,72 +0,0 @@ -# -# This file configures the New Relic Agent. New Relic monitors Ruby, Java, -# .NET, PHP, Python, Node, and Go applications with deep visibility and low -# overhead. For more information, visit www.newrelic.com. -# -# Generated October 28, 2022 -# -# This configuration file is custom generated for NewRelic Administration -# -# For full documentation of agent configuration options, please refer to -# https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration - -common: &default_settings - # Required license key associated with your New Relic account. - # Set with NEW_RELIC_LICENSE_KEY - license_key: '' - - # Your application name. Renaming here affects where data displays in New - # Relic. For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications - app_name: 'E6ng' - - distributed_tracing: - enabled: true - - # To disable the agent regardless of other settings, uncomment the following: - # agent_enabled: false - - # Logging level for log/newrelic_agent.log - log_level: info - - browser_monitoring: - auto_instrument: false - - attributes: - include: request.parameters.* - - application_logging: - # If `true`, all logging-related features for the agent can be enabled or disabled - # independently. If `false`, all logging-related features are disabled. - enabled: true - forwarding: - # If `true`, the agent captures log records emitted by this application. - enabled: true - # Defines the maximum number of log records to buffer in memory at a time. - max_samples_stored: 10000 - metrics: - # If `true`, the agent captures metrics related to logging for this application. - enabled: true - local_decorating: - # If `true`, the agent decorates logs with metadata to link to entities, hosts, traces, and spans. - # This requires a log forwarder to send your log files to New Relic. - # This should not be used when forwarding is enabled. - enabled: false - -# Environment-specific settings are in this section. -# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment. -# If your application has other named environments, configure them here. -development: - <<: *default_settings - app_name: 'E6ng (Development)' - -test: - <<: *default_settings - # It doesn't make sense to report to New Relic from automated test runs. - monitor_mode: false - -staging: - <<: *default_settings - app_name: 'E6ng (Staging)' - -production: - <<: *default_settings diff --git a/docker-compose.yml b/docker-compose.yml index dcffa23d0..29ce2a8e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,8 +8,6 @@ x-environment: &common-env DANBOORU_IQDB_SERVER: http://iqdb:5588 DANBOORU_DISCORD_SITE: http://localhost:8000 DANBOORU_DISCORD_SECRET: super_secret_for_url_discord - NEW_RELIC_AGENT_ENABLED: ${NEW_RELIC_AGENT_ENABLED:-false} - NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY:-} # These are just development secrets, do not use them in production DANBOORU_PROTECTED_FILE_SECRET: 6686a6413d90c43d5e82403ef271ec25d13cc24e3bfcdd094e73d1eff22a3567 DANBOORU_REPLACEMENT_FILE_SECRET: b35bc54cdc0d0436fc5867c7ef88f9b10a37ae20a06b37e67614fe60019d7bb1 diff --git a/lib/tasks/maintenance.rake b/lib/tasks/maintenance.rake index f572f3df2..9e84a4d77 100644 --- a/lib/tasks/maintenance.rake +++ b/lib/tasks/maintenance.rake @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "tasks/newrelic" if defined?(NewRelic) - namespace :maintenance do desc "Run daily maintenance jobs" task daily: :environment do