newrelic: fix newrelic starting without license key.

Fix an issue where the New Relic agent always started in the production
environment, even when a license key wasn't configured.

Also make the New Relic agent log to stdout instead of log/newrelic_agent.log.
This commit is contained in:
evazion
2021-05-24 21:48:15 -05:00
parent 896ddab55d
commit 4439293bf1
6 changed files with 21 additions and 57 deletions

View File

@@ -52,6 +52,7 @@ gem 'google-cloud-storage', require: "google/cloud/storage"
gem 'ed25519'
gem 'bcrypt_pbkdf' # https://github.com/net-ssh/net-ssh/issues/565
gem 'terminal-table'
gem 'newrelic_rpm', require: false
group :production, :staging do
gem 'unicorn', :platforms => :ruby
@@ -60,7 +61,6 @@ end
group :production do
gem 'unicorn-worker-killer'
gem 'newrelic_rpm'
gem 'capistrano-deploytags', '~> 1.0.0', require: false
end

View File

@@ -581,6 +581,12 @@ module Danbooru
def redis_url
# "redis://localhost:6379"
end
# Optional. The license key for your New Relic account.
# https://newrelic.com/
# https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/new-relic-license-key/
def new_relic_license_key
end
end
EnvironmentConfiguration = Struct.new(:config) do

View File

@@ -0,0 +1,14 @@
if Danbooru.config.new_relic_license_key.present?
require "new_relic/control"
# https://github.com/newrelic/newrelic-ruby-agent/blob/1ef4082fe97fd19aeccb3f392a44ef3becae66d3/lib/newrelic_rpm.rb#L40
# https://github.com/newrelic/newrelic-ruby-agent/blob/1ef4082fe97fd19aeccb3f392a44ef3becae66d3/lib/new_relic/agent.rb#L349
NewRelic::Control.instance.init_plugin(
app_name: Danbooru.config.canonical_app_name,
license_key: Danbooru.config.new_relic_license_key,
log_level: Danbooru.config.debug_mode ? "debug" : "error",
log: Rails.logger,
"rake.tasks": ["maintenance:.*"],
config: Rails.application.config,
)
end

View File

@@ -1,7 +0,0 @@
# Ensure the agent is started using Unicorn.
# This is needed when using Unicorn and preload_app is not set to true.
# See https://newrelic.com/docs/ruby/no-data-with-unicorn
if defined? ::NewRelic
::NewRelic::Agent.manual_start
::NewRelic::Agent.after_fork(:force_reconnect => true)
end

View File

@@ -3,9 +3,6 @@ namespace :symlink do
task :local_files do
on roles(:app, :worker) do
execute :ln, "-s", "#{deploy_to}/shared/config/danbooru_local_config.rb", "#{release_path}/config/danbooru_local_config.rb"
if test("[ -f #{deploy_to}/shared/config/newrelic.yml ]")
execute :ln, "-s", "#{deploy_to}/shared/config/newrelic.yml", "#{release_path}/config/newrelic.yml"
end
end
end

View File

@@ -1,46 +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.
#
# 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.
license_key: YOUR_LICENCE_KEY_HERE
# 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: Danbooru
# To disable the agent regardless of other settings, uncomment the following:
# agent_enabled: false
# Logging level for log/newrelic_agent.log
log_level: info
# https://docs.newrelic.com/docs/agents/ruby-agent/background-jobs/rake-instrumentation
rake:
tasks: ["maintenance:.*"]
# 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: Danbooru (Development)
# New Relic is disabled by default in the development environment. Uncomment to enable.
# monitor_mode: true
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: Danbooru (Staging)
production:
<<: *default_settings