Skip to content

Commit

Permalink
Add govuk app config
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism committed Sep 24, 2024
1 parent c2d82d8 commit 13fa8b1
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 387 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby file: ".ruby-version"

gem "config"
gem "govuk_app_config"
gem "govuk-components"
gem "govuk_design_system_formbuilder"
gem "govuk_notify_rails", ">= 2.1.2"
Expand All @@ -13,7 +14,6 @@ gem "logstasher"
gem "mail", ">= 2.8"
gem "mechanize", "~> 2.12"
gem "pg", "~> 1.5"
gem "prometheus_exporter"
gem "puma"
gem "rails", "~> 7.0"
gem "responders", "~> 3.1"
Expand Down
223 changes: 222 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,27 @@ GEM
i18n (>= 1.8.11, < 2)
globalid (1.2.1)
activesupport (>= 6.1)
google-protobuf (4.27.3-arm64-darwin)
bigdecimal
rake (>= 13)
googleapis-common-protos-types (1.15.0)
google-protobuf (>= 3.18, < 5.a)
govuk-components (5.4.0)
html-attributes-utils (~> 1.0.0, >= 1.0.0)
pagy (>= 6, < 9)
view_component (>= 3.9, < 3.13)
govuk_app_config (9.14.0)
logstasher (~> 2.1)
opentelemetry-exporter-otlp (>= 0.25, < 0.29)
opentelemetry-instrumentation-all (>= 0.39.1, < 0.63.0)
opentelemetry-sdk (~> 1.2)
plek (>= 4, < 6)
prometheus_exporter (~> 2.0)
puma (>= 5.6, < 7.0)
rack-proxy (~> 0.7)
sentry-rails (~> 5.3)
sentry-ruby (~> 5.3)
statsd-ruby (~> 1.5)
govuk_design_system_formbuilder (5.6.0)
actionview (>= 6.1)
activemodel (>= 6.1)
Expand Down Expand Up @@ -244,12 +261,213 @@ GEM
racc (~> 1.4)
notifications-ruby-client (6.2.0)
jwt (>= 1.5, < 3)
opentelemetry-api (1.3.0)
opentelemetry-common (0.21.0)
opentelemetry-api (~> 1.0)
opentelemetry-exporter-otlp (0.28.1)
google-protobuf (>= 3.18)
googleapis-common-protos-types (~> 1.3)
opentelemetry-api (~> 1.1)
opentelemetry-common (~> 0.20)
opentelemetry-sdk (~> 1.2)
opentelemetry-semantic_conventions
opentelemetry-helpers-mysql (0.1.1)
opentelemetry-api (~> 1.0)
opentelemetry-common (~> 0.21)
opentelemetry-helpers-sql-obfuscation (0.1.1)
opentelemetry-common (~> 0.21)
opentelemetry-instrumentation-action_mailer (0.1.0)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-active_support (~> 0.1)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-action_pack (0.9.0)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rack (~> 0.21)
opentelemetry-instrumentation-action_view (0.7.1)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-active_support (~> 0.1)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-active_job (0.7.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-active_model_serializers (0.20.2)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-active_record (0.7.2)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-active_support (0.6.0)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-all (0.62.1)
opentelemetry-instrumentation-active_model_serializers (~> 0.20.1)
opentelemetry-instrumentation-aws_lambda (~> 0.1.0)
opentelemetry-instrumentation-aws_sdk (~> 0.5.0)
opentelemetry-instrumentation-bunny (~> 0.21.0)
opentelemetry-instrumentation-concurrent_ruby (~> 0.21.1)
opentelemetry-instrumentation-dalli (~> 0.25.0)
opentelemetry-instrumentation-delayed_job (~> 0.22.0)
opentelemetry-instrumentation-ethon (~> 0.21.1)
opentelemetry-instrumentation-excon (~> 0.22.0)
opentelemetry-instrumentation-faraday (~> 0.24.0)
opentelemetry-instrumentation-grape (~> 0.2.0)
opentelemetry-instrumentation-graphql (~> 0.28.0)
opentelemetry-instrumentation-gruf (~> 0.2.0)
opentelemetry-instrumentation-http (~> 0.23.1)
opentelemetry-instrumentation-http_client (~> 0.22.1)
opentelemetry-instrumentation-koala (~> 0.20.1)
opentelemetry-instrumentation-lmdb (~> 0.22.1)
opentelemetry-instrumentation-mongo (~> 0.22.1)
opentelemetry-instrumentation-mysql2 (~> 0.27.0)
opentelemetry-instrumentation-net_http (~> 0.22.1)
opentelemetry-instrumentation-pg (~> 0.27.0)
opentelemetry-instrumentation-que (~> 0.8.0)
opentelemetry-instrumentation-racecar (~> 0.3.0)
opentelemetry-instrumentation-rack (~> 0.24.0)
opentelemetry-instrumentation-rails (~> 0.31.0)
opentelemetry-instrumentation-rake (~> 0.2.1)
opentelemetry-instrumentation-rdkafka (~> 0.4.0)
opentelemetry-instrumentation-redis (~> 0.25.1)
opentelemetry-instrumentation-resque (~> 0.5.0)
opentelemetry-instrumentation-restclient (~> 0.22.1)
opentelemetry-instrumentation-ruby_kafka (~> 0.21.0)
opentelemetry-instrumentation-sidekiq (~> 0.25.0)
opentelemetry-instrumentation-sinatra (~> 0.24.0)
opentelemetry-instrumentation-trilogy (~> 0.59.0)
opentelemetry-instrumentation-aws_lambda (0.1.1)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-aws_sdk (0.5.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-base (0.22.5)
opentelemetry-api (~> 1.0)
opentelemetry-common (~> 0.21)
opentelemetry-registry (~> 0.1)
opentelemetry-instrumentation-bunny (0.21.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-concurrent_ruby (0.21.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-dalli (0.25.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-delayed_job (0.22.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-ethon (0.21.8)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-excon (0.22.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-faraday (0.24.6)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-grape (0.2.0)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rack (~> 0.21)
opentelemetry-instrumentation-graphql (0.28.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-gruf (0.2.1)
opentelemetry-api (>= 1.0.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-http (0.23.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-http_client (0.22.7)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-koala (0.20.5)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-lmdb (0.22.3)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-mongo (0.22.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-mysql2 (0.27.2)
opentelemetry-api (~> 1.0)
opentelemetry-helpers-mysql
opentelemetry-helpers-sql-obfuscation
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-net_http (0.22.7)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-pg (0.27.4)
opentelemetry-api (~> 1.0)
opentelemetry-helpers-sql-obfuscation
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-que (0.8.3)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-racecar (0.3.4)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rack (0.24.6)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rails (0.31.1)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-action_mailer (~> 0.1.0)
opentelemetry-instrumentation-action_pack (~> 0.9.0)
opentelemetry-instrumentation-action_view (~> 0.7.0)
opentelemetry-instrumentation-active_job (~> 0.7.0)
opentelemetry-instrumentation-active_record (~> 0.7.0)
opentelemetry-instrumentation-active_support (~> 0.6.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rake (0.2.2)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rdkafka (0.4.8)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-redis (0.25.7)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-resque (0.5.2)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-restclient (0.22.7)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-ruby_kafka (0.21.3)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-sidekiq (0.25.7)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-sinatra (0.24.1)
opentelemetry-api (~> 1.0)
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-instrumentation-rack (~> 0.21)
opentelemetry-instrumentation-trilogy (0.59.3)
opentelemetry-api (~> 1.0)
opentelemetry-helpers-mysql
opentelemetry-helpers-sql-obfuscation
opentelemetry-instrumentation-base (~> 0.22.1)
opentelemetry-semantic_conventions (>= 1.8.0)
opentelemetry-registry (0.3.1)
opentelemetry-api (~> 1.1)
opentelemetry-sdk (1.5.0)
opentelemetry-api (~> 1.1)
opentelemetry-common (~> 0.20)
opentelemetry-registry (~> 0.2)
opentelemetry-semantic_conventions
opentelemetry-semantic_conventions (1.10.1)
opentelemetry-api (~> 1.0)
pagy (8.4.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pg (1.5.8)
plek (5.2.0)
prometheus_exporter (2.1.1)
webrick
psych (5.1.2)
Expand All @@ -259,6 +477,8 @@ GEM
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.9)
rack-proxy (0.7.7)
rack
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
Expand Down Expand Up @@ -417,6 +637,7 @@ GEM
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
statsd-ruby (1.5.0)
stopwords-filter2 (0.1.0)
stringio (3.1.1)
strscan (3.1.0)
Expand Down Expand Up @@ -466,6 +687,7 @@ DEPENDENCIES
factory_bot_rails
faker
govuk-components
govuk_app_config
govuk_design_system_formbuilder
govuk_notify_rails (>= 2.1.2)
httparty
Expand All @@ -476,7 +698,6 @@ DEPENDENCIES
mail (>= 2.8)
mechanize (~> 2.12)
pg (~> 1.5)
prometheus_exporter
puma
rails (~> 7.0)
rails-controller-testing (>= 1.0.5)
Expand Down
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: bundle exec puma -C config/puma.rb -p 3000
web: bundle exec puma
# worker: bundle exec sidekiq -C config/sidekiq.yml
js: yarn build --watch
css: yarn build:css --watch
2 changes: 1 addition & 1 deletion app/services/gov_uk_search_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def search
http_response = HTTParty.get(json_query_url)
Response.new(@original_query, http_response)
rescue StandardError => e
Rails.logger.error(event: "query_search", search_term: @original_query, error_class: e.class, message: e.message)
GovukError.notify("Search failed", extra: { event: "query_search", search_term: @original_query, error_class: e.class, message: e.message })
Response.new(@original_query, { error: { event: "query_search", search_term: @original_query, error_class: e.class.to_s, message: e.message } }.to_json)
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
host: Settings.aaq_email_url,
}

Rails.configuration.time_zone = "London"
Rails.configuration.govuk_time_zone = "London"

# Initialize the Rails application.
Rails.application.initialize!
11 changes: 2 additions & 9 deletions config/initializers/prometheus_exporter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
unless Rails.env.test? || Rails.env.development?
require "prometheus_exporter/middleware"
require "prometheus_exporter/instrumentation"

# This reports stats per request like HTTP status and timings
Rails.application.middleware.unshift PrometheusExporter::Middleware
# this reports basic process stats like RSS and GC info
PrometheusExporter::Instrumentation::Process.start(type: "master")
end
require "govuk_app_config/govuk_prometheus_exporter"
GovukPrometheusExporter.configure
67 changes: 2 additions & 65 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,2 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#

max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT", 3000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the `pidfile` that Puma will use.
# pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers ENV.fetch("WEB_CONCURRENCY", 2)

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
preload_app!

# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end

# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

# Activerecord Connection Pool Metrics
after_worker_boot do
if Rails.env.production?
require "prometheus_exporter/instrumentation"
require "prometheus_exporter/client"
PrometheusExporter::Instrumentation::Puma.start
PrometheusExporter::Instrumentation::Process.start(type: "web")

PrometheusExporter::Instrumentation::ActiveRecord.start(
custom_labels: { type: "puma_worker" },
config_labels: %i[database host],
)
end
end
require "govuk_app_config/govuk_puma"
GovukPuma.configure_rails(self)
Loading

0 comments on commit 13fa8b1

Please sign in to comment.