Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gem "elasticsearch", "~> 7.17", ">= 7.17.10"
gem "elasticsearch-model", "~> 7.2.1", ">= 7.2.1", require: "elasticsearch/model"
gem "elasticsearch-rails", "~> 7.2.1", ">= 7.2.1"
gem "elasticsearch-transport", "~> 7.17", ">= 7.17.10"
gem "git", "~> 1.5"

# This gem will allow us to write tests without the need for a database
gem "activerecord-nulldb-adapter", "~> 1.1", ">= 1.1.1"
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ GEM
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
aws-eventstream (1.3.1)
aws-partitions (1.1060.0)
Expand Down Expand Up @@ -151,6 +153,9 @@ GEM
ffi (1.17.1-aarch64-linux-gnu)
ffi (1.17.1-arm64-darwin)
ffi (1.17.1-x86_64-linux-gnu)
git (1.19.1)
addressable (~> 2.8)
rchardet (~> 1.8)
globalid (1.2.1)
activesupport (>= 6.1)
hashie (5.0.0)
Expand Down Expand Up @@ -226,6 +231,7 @@ GEM
psych (5.2.3)
date
stringio
public_suffix (6.0.1)
racc (1.8.1)
rack (3.1.11)
rack-cors (2.0.2)
Expand Down Expand Up @@ -268,6 +274,7 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rchardet (1.9.0)
rdoc (6.12.0)
psych (>= 4.0.0)
regexp_parser (2.10.0)
Expand Down Expand Up @@ -364,6 +371,7 @@ DEPENDENCIES
elasticsearch-rails (~> 7.2.1, >= 7.2.1)
elasticsearch-transport (~> 7.17, >= 7.17.10)
factory_bot_rails
git (~> 1.5)
lograge (~> 0.11.2)
logstash-event (~> 1.2, >= 1.2.02)
logstash-logger (~> 0.26.1)
Expand Down
35 changes: 2 additions & 33 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,7 @@ class Application < Rails::Application

config.secret_key_base = "blipblapblup"

# Start: Configure Logging
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Logstash.new
config.lograge.logger = LogStashLogger.new(type: :stdout)
config.logger = config.lograge.logger ## LogStashLogger needs to be pass to rails logger, see roidrage/lograge#26
config.log_level = ENV["LOG_LEVEL"].to_sym

config.lograge.ignore_actions = [
"HeartbeatController#index",
"IndexController#index",
]
config.lograge.ignore_custom = lambda do |event|
event.payload.inspect.length > 100_000
end
config.lograge.base_controller_class = "ActionController::API"

config.lograge.custom_options = lambda do |event|
correlation = Datadog::Tracing.correlation
exceptions = ["controller", "action", "format", "id"]
{
dd: {
env: correlation.env,
service: correlation.service,
version: correlation.version,
trace_id: correlation.trace_id,
span_id: correlation.span_id,
},
ddsource: ["ruby"],
params: event.payload[:params].except(*exceptions),
uid: event.payload[:uid],
}
end
# End: Configure Logging
config.logger = Logger.new($stdout)
config.log_level = :info
end
end
30 changes: 0 additions & 30 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,40 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.enable_reloading = true

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports.
config.consider_all_requests_local = true

# Enable server timing
config.server_timing = true

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join("tmp/caching-dev.txt").exist?
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}",
}
else
config.action_controller.perform_caching = false

config.cache_store = :null_store
end

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise exceptions for disallowed deprecations.
config.active_support.disallowed_deprecation = :raise

# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Highlight code that enqueued background job in logs.
config.active_job.verbose_enqueue_logs = true

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
end
37 changes: 33 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,39 @@
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

# Log to STDOUT by default
# config.logger = ActiveSupport::Logger.new($stdout)
# .tap { |logger| logger.formatter = Logger::Formatter.new }
# .then { |logger| ActiveSupport::TaggedLogging.new(logger) }
# Start: Configure Logging
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Logstash.new
config.lograge.logger = LogStashLogger.new(type: :stdout)
config.logger = config.lograge.logger ## LogStashLogger needs to be pass to rails logger, see roidrage/lograge#26
config.log_level = ENV["LOG_LEVEL"].to_sym

config.lograge.ignore_actions = [
"HeartbeatController#index",
"IndexController#index",
]
config.lograge.ignore_custom = lambda do |event|
event.payload.inspect.length > 100_000
end
config.lograge.base_controller_class = "ActionController::API"

config.lograge.custom_options = lambda do |event|
correlation = Datadog::Tracing.correlation
exceptions = ["controller", "action", "format", "id"]
{
dd: {
env: correlation.env,
service: correlation.service,
version: correlation.version,
trace_id: correlation.trace_id,
span_id: correlation.span_id,
},
ddsource: ["ruby"],
params: event.payload[:params].except(*exceptions),
uid: event.payload[:uid],
}
end
# End: Configure Logging

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
Expand Down
63 changes: 63 additions & 0 deletions config/environments/stage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

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

# Global enable/disable all memcached usage
config.perform_caching = true

# Disable/enable fragment and page caching in ActionController
config.action_controller.perform_caching = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
# config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

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

# 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

# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

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

# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "content-negotiation_#{Rails.env}"
# config.action_mailer.perform_caching = false

# 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

# 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

config.active_storage.service = :amazon

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

# Do not dump schema after migrations.
# config.active_record.dump_schema_after_migration = false
end
9 changes: 9 additions & 0 deletions config/initializers/_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Events
class Application
g = Git.open(Rails.root)
VERSION = g.tags.map { |t| Gem::Version.new(t.name) }.max.to_s
REVISION = g.object("HEAD").sha
end
end
26 changes: 26 additions & 0 deletions config/initializers/datadog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

Datadog.configure do |c|
# Global
c.agent.host = "datadog.local"
c.runtime_metrics.enabled = true
c.service = "events"
c.env = Rails.env

# Tracing settings

# Enable tracing for production and staging envs
c.tracing.enabled = Rails.env.production? || ENV["RAILS_ENV"] == "stage"

# We disable automatic log injection because it doesn't play nice with our formatter
c.tracing.log_injection = false

# Instrumentation
c.tracing.instrument(:rails)
c.tracing.instrument(:elasticsearch)
c.tracing.instrument(:shoryuken)
c.tracing.instrument(:graphql, enabled: false, with_deprecated_tracers: true)

# Profiling setup
c.profiling.enabled = ENV["RAILS_ENV"] == "stage"
end if defined?(Datadog)
9 changes: 9 additions & 0 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

Raven.configure do |config|
config.environments = ["stage", "production"]
config.dsn = ENV["SENTRY_DSN"]
config.release = "events:" + Events::Application::VERSION
config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
config.logger = Rails.application.config.lograge.logger
end
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
services:
api:
container_name: events_api
environment:
- LOG_LEVEL=debug
- MYSQL_USER=root
- MYSQL_PASSWORD=
- MYSQL_DATABASE=datacite
- MYSQL_HOST=lupo_mysql
- MYSQL_PORT=3306
- MYSQL_ALLOW_EMPTY_PASSWORD=true
build:
context: ./
dockerfile: Dockerfile
Expand Down