Skip to content

Commit

Permalink
Only run datadog in production (#2349)
Browse files Browse the repository at this point in the history
- Add more staging and qa configuration
- Only run Datadog initializer in production
  • Loading branch information
maxkadel authored Apr 17, 2024
1 parent 1bf58a5 commit 3d71924
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 32 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- run: sudo apt-get -y update
- run: sudo apt-get install -y postgresql-client || true
- run: gem install bundler -v '~> 2.0'
- run: bundle config set --local without production
- run:
name: Install dependencies
command: bundle install --path=vendor/bundle --jobs 4 --retry 3
Expand Down
14 changes: 7 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gem 'capistrano-rails'
gem 'capistrano-rails-console', require: false
gem 'capybara'
gem 'change_the_subject', '~> 0.3.2'
gem 'ddtrace', '~> 0.54.2'
gem 'devise'
gem 'ed25519'
gem 'faraday', '~> 1.0'
Expand All @@ -24,6 +23,7 @@ gem 'friendly_id'
gem 'gyoku', '~> 1.0'
gem 'high_voltage', '~> 3.0'
gem 'honeybadger'
gem 'human_languages', '~> 0.7'
gem 'jbuilder'
gem 'jquery-rails'
gem 'jquery-tablesorter', '~> 1.21'
Expand All @@ -44,6 +44,8 @@ gem 'net-sftp'
gem 'net-smtp', require: false
gem 'oj'
gem 'omniauth-cas'
gem 'omniauth-rails_csrf_protection'
gem 'open3'
gem 'orangetheses', github: 'pulibrary/orangetheses', ref: '4ac8dc2bd04b10db764fc37df3261531c9937061'
gem 'pg'
gem "rack", ">= 2.0.6"
Expand All @@ -68,6 +70,10 @@ gem 'turbolinks'
gem 'whenever', "~> 0.10"
gem 'yard'

group :production do
gem "ddtrace", '~> 0.54.2'
end

group :development, :test do
# bundler and rake come in from the voyager_helpers gemspec
gem 'coveralls_reborn'
Expand All @@ -89,9 +95,3 @@ group :test do
gem 'axe-core-api'
gem 'axe-core-rspec'
end

gem "omniauth-rails_csrf_protection"

gem "human_languages", "~> 0.7"

gem "open3"
6 changes: 6 additions & 0 deletions config/alma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ test:

production:
<<: *default

qa:
<<: *default

staging:
<<: *default
6 changes: 3 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
require 'rails/all'
require_relative 'lando_env' if Rails.env.development? || Rails.env.test?

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
# Require the gems listed in Gemfile, but only the default ones
# and those for the environment rails is running in
Bundler.require(:default, Rails.env)

module MarcLiberation
class Application < Rails::Application
Expand Down
6 changes: 6 additions & 0 deletions config/authz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ test:

production:
<<: *default

qa:
<<: *default

staging:
<<: *default
4 changes: 4 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ production:
staging:
<<: *default
pool: 20

qa:
<<: *default
pool: 20
2 changes: 1 addition & 1 deletion config/deploy/qa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
set :application, 'bibdata'

set :stage, :production
set :rails_env, 'production'
set :rails_env, 'qa'
server 'bibdata-qa1.princeton.edu', user: 'deploy', roles: [:web, :app, :db, :hr_cron, :poller]
server 'bibdata-qa2.princeton.edu', user: 'deploy', roles: [:web, :app, :db, :hr_cron, :poller]
server 'bibdata-worker-qa1.princeton.edu', user: 'deploy', roles: [:db, :worker, :cron, :cron_staging, :poller]
Expand Down
2 changes: 1 addition & 1 deletion config/deploy/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set :application, 'bibdata'
set :stage, :production
set :rails_env, 'production'
set :rails_env, 'staging'
server 'bibdata-alma-staging1.princeton.edu', user: 'deploy', roles: [:web, :app, :db, :hr_cron, :poller]
server 'bibdata-alma-staging2.princeton.edu', user: 'deploy', roles: [:web, :app, :db, :hr_cron, :poller]
server 'bibdata-alma-worker-staging1.princeton.edu', user: 'deploy', roles: [:db, :worker, :cron, :cron_staging, :poller]
Expand Down
91 changes: 91 additions & 0 deletions config/environments/qa.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

view_logger = Logger.new(STDOUT)
view_logger.level = Logger::WARN
config.action_view.logger = view_logger

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_files = false

# Compress JavaScripts and CSS.
config.assets.js_compressor = :terser
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# Set to :debug to see everything in the log.
config.log_level = :info

# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]

# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# config.action_mailer.delivery_method = :sendmail
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'lib-ponyexpr.princeton.edu'
}
config.action_mailer.default_options = {
from: '[email protected]'
}
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_mailer.default_url_options = { host: ENV["APPLICATION_URL"] || "bibdata-qa.princeton.edu", protocol: "https" }
end
91 changes: 91 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

view_logger = Logger.new(STDOUT)
view_logger.level = Logger::WARN
config.action_view.logger = view_logger

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_files = false

# Compress JavaScripts and CSS.
config.assets.js_compressor = :terser
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# Set to :debug to see everything in the log.
config.log_level = :info

# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]

# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# config.action_mailer.delivery_method = :sendmail
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'lib-ponyexpr.princeton.edu'
}
config.action_mailer.default_options = {
from: '[email protected]'
}
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_mailer.default_url_options = { host: ENV["APPLICATION_URL"] || "bibdata-staging.princeton.edu", protocol: "https" }
end
39 changes: 20 additions & 19 deletions config/initializers/datadog.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# frozen_string_literal: true

Datadog.configure do |c|
c.tracer(enabled: false) unless Rails.env.production?
c.env = 'production'
c.service = 'bibdata'
# Rails
c.use :rails

# Redis
c.use :redis

# Net::HTTP
c.use :http

# Sidekiq
c.use :sidekiq

# Faraday
c.use :faraday
if Rails.env.production?
Datadog.configure do |c|
c.tracer(enabled: false) unless Rails.env.production?
c.env = Rails.env
c.service = 'bibdata'
# Rails
c.use :rails

# Redis
c.use :redis

# Net::HTTP
c.use :http

# Sidekiq
c.use :sidekiq

# Faraday
c.use :faraday
end
end
9 changes: 8 additions & 1 deletion config/ip_allowlist.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
default: &default
addresses: <%= ENV["BIBDATA_IP_ALLOWLIST"] || "" %>

development:
addresses: "127.0.0.1 ::1"

test:
addresses: "127.0.0.1"

staging:
<<: *default
qa:
<<: *default
production:
addresses: <%= ENV["BIBDATA_IP_ALLOWLIST"] || "" %>
<<: *default
6 changes: 6 additions & 0 deletions config/traject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ test:

production:
<<: *default

staging:
<<: *default

qa:
<<: *default

0 comments on commit 3d71924

Please sign in to comment.