govuk_app_config 4.0.0.pre.3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64e3b5e80cdc107dd26911c7bf2cf9e298fe37fbb7b7cc28b3c860f74424843e
4
- data.tar.gz: 45051a0d49d02e14b1385894ac53f61ebdaffa11f9379c6f2ac7c1c5752d0794
3
+ metadata.gz: 035dcbe366b0f0f062233f632cbdd44363f0fd145da5bf8d1f567c8827f6ef7f
4
+ data.tar.gz: 8a3eda8f28a196cf032e437369b08505a9c71d7ec6ee1c11e4ff8489ad51cec9
5
5
  SHA512:
6
- metadata.gz: 33ac4913c546cbf10958b1efca95792886bb4d2dac81aa4303bea4343515d23fabedc94e272a5aa6383cff6c27448d4bcd8ceda27d4329f7be3dbb651f86ca79
7
- data.tar.gz: aee0bd0ff3a81e6ade12461b81a10073c903eb7c35762f744c89d4feec0fe5f933bcb20609e75add6b94d8e60c0c49d836527517c8defcdcc3ee23856143be02
6
+ metadata.gz: 17439c255bc340863a3ea220021920a9ad4081bad08cfee2101ff618715fb21ddc6c8c1579826c53a7e05e41d85654c5a23de3be01678a85b8c842887fc611cd
7
+ data.tar.gz: 2e285f5737b24f5e1407a4f6112e25d73da1a055ba27fda7f97d60efaeccefea145455be97409c6f4b52f833234a3f0b2b8d445eb7c21699a2be20facce9422c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # 4.1.0
2
+
3
+ - Add Puma to dependencies ([#214](https://github.com/alphagov/govuk_app_config/pull/214)).
4
+
5
+ # 4.0.1
6
+
7
+ - Update Content Security Policy with new klick2contact.com subdomain ([#213](https://github.com/alphagov/govuk_app_config/pull/213)).
8
+
9
+ # 4.0.0
10
+
11
+ - BREAKING: replaces deprecated `sentry-raven` with `sentry-ruby` and `sentry-rails`. Follow the **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** before upgrading to this version of govuk_app_config to ensure full compatibility with the new gems.
12
+ - BREAKING: `GovukError.configure` can only be called once, and non-Rails apps will have to manually call `GovukError.configure` in order to initialise Sentry.
13
+ - BREAKING: apps will no longer increment the `error_reports_failed` statsd if events fail to get sent to Sentry.
14
+ - BREAKING: the behaviour of `before_send` has changed, and the `should_capture` method is deprecated.
15
+ - See pre-release notes below for details.
16
+ - PR: [#212](https://github.com/alphagov/govuk_app_config/pull/212)
17
+
18
+ # 4.0.0.pre.4
19
+
20
+ - Fix Sentry client initialisation ([#205](https://github.com/alphagov/govuk_app_config/pull/205)).
21
+ - BREAKING: non-Rails apps will need to manually call `GovukError.configure` in order to initialise Sentry.
22
+ - BREAKING: `GovukError.configure` can only be called once by the downstream application.
23
+
1
24
  # 4.0.0.pre.3
2
25
 
3
26
  - Include [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails) by default ([#203](https://github.com/alphagov/govuk_app_config/pull/203)).
@@ -10,9 +33,17 @@
10
33
  # 4.0.0.pre.1
11
34
 
12
35
  - BREAKING: upgrades Sentry gem from `sentry-raven` to `sentry-ruby` ([#199](https://github.com/alphagov/govuk_app_config/pull/199)). There is a **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** you should follow before upgrading to this version of govuk_app_config.
13
- - This release also fixes the `data_sync_excluded_exceptions` behaviour that has been broken since v3.1.0.
36
+ - This release also fixes the `data_sync_excluded_exceptions` behaviour that was broken in v3.1.0 (later fixed in v3.3.0, which was released after 4.0.0.pre.1).
14
37
  - Released as a pre-release to identify and fix any problems before a wider rollout.
15
38
 
39
+ # 3.3.0
40
+
41
+ - Revert the `should_capture`/`before_send` consolidation introduced in 3.1.0. This fixes the `data_sync_excluded_exceptions` behaviour that has been broken since v3.1.0. ([#211](https://github.com/alphagov/govuk_app_config/pull/211))
42
+
43
+ # 3.2.0
44
+
45
+ - Add Speedcurve's LUX to connect-src policy ([#206](https://github.com/alphagov/govuk_app_config/pull/206))
46
+
16
47
  # 3.1.1
17
48
 
18
49
  - Fix the new before_send behaviour & tests, and add documentation ([#197](https://github.com/alphagov/govuk_app_config/pull/197))
data/README.md CHANGED
@@ -87,7 +87,7 @@ You can add your environment to the list of active Sentry environments like so:
87
87
 
88
88
  ```ruby
89
89
  GovukError.configure do |config|
90
- config.active_sentry_environments << "my-test-environment"
90
+ config.enabled_environments << "my-test-environment"
91
91
  end
92
92
  ```
93
93
 
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = %w[lib]
22
22
 
23
23
  spec.add_dependency "logstasher", ">= 1.2.2", "< 2.2.0"
24
+ spec.add_dependency "puma", "~> 5.0"
24
25
  spec.add_dependency "sentry-rails", "~> 4.5.0"
25
26
  spec.add_dependency "sentry-ruby", "~> 4.5.0"
26
27
  spec.add_dependency "statsd-ruby", "~> 1.5.0"
@@ -76,9 +76,15 @@ module GovukContentSecurityPolicy
76
76
  # Allow JSON call to Nuance - HMRC web chat provider
77
77
  "hmrc-uk.digital.nuance.com",
78
78
  # Allow JSON call to klick2contact - HMPO web chat provider
79
- "gov.klick2contact.com",
79
+ "hmpowebchat.klick2contact.com",
80
80
  # Allow connecting to Verify to check whether the user is logged in
81
- "www.signin.service.gov.uk"
81
+ "www.signin.service.gov.uk",
82
+ # Allow connection to Speedcurve's CDN for LUX - used for
83
+ # real user metrics on GOV.UK. This loads using an image
84
+ # (see image policy), but returns a JavaScript file -
85
+ # which is why this has to be added to the `connect-src`
86
+ # policy as well.
87
+ "lux.speedcurve.com"
82
88
 
83
89
  # Disallow all <object>, <embed>, and <applet> elements
84
90
  #
@@ -3,20 +3,82 @@ require "govuk_app_config/govuk_error/govuk_data_sync"
3
3
 
4
4
  module GovukError
5
5
  class Configuration < SimpleDelegator
6
- attr_reader :data_sync, :sentry_environment
7
- attr_accessor :active_sentry_environments, :data_sync_excluded_exceptions
6
+ attr_reader :data_sync
7
+ attr_accessor :data_sync_excluded_exceptions
8
8
 
9
9
  def initialize(_sentry_configuration)
10
10
  super
11
- @sentry_environment = ENV["SENTRY_CURRENT_ENV"]
12
11
  @data_sync = GovukDataSync.new(ENV["GOVUK_DATA_SYNC_PERIOD"])
13
- self.active_sentry_environments = []
14
- self.data_sync_excluded_exceptions = []
12
+ set_up_defaults
13
+ end
14
+
15
+ def set_up_defaults
16
+ # These are the environments (described by the `SENTRY_CURRENT_ENV`
17
+ # ENV variable) where we want to capture Sentry errors. If
18
+ # `SENTRY_CURRENT_ENV` isn't in this list, or isn't defined, then
19
+ # don't capture the error.
20
+ self.enabled_environments = %w[
21
+ integration-blue-aws
22
+ staging
23
+ production
24
+ ]
25
+
26
+ self.excluded_exceptions = [
27
+ # Default ActionDispatch rescue responses
28
+ "ActionController::RoutingError",
29
+ "AbstractController::ActionNotFound",
30
+ "ActionController::MethodNotAllowed",
31
+ "ActionController::UnknownHttpMethod",
32
+ "ActionController::NotImplemented",
33
+ "ActionController::UnknownFormat",
34
+ "Mime::Type::InvalidMimeType",
35
+ "ActionController::MissingExactTemplate",
36
+ "ActionController::InvalidAuthenticityToken",
37
+ "ActionController::InvalidCrossOriginRequest",
38
+ "ActionDispatch::Http::Parameters::ParseError",
39
+ "ActionController::BadRequest",
40
+ "ActionController::ParameterMissing",
41
+ "Rack::QueryParser::ParameterTypeError",
42
+ "Rack::QueryParser::InvalidParameterError",
43
+ # Default ActiveRecord rescue responses
44
+ "ActiveRecord::RecordNotFound",
45
+ "ActiveRecord::StaleObjectError",
46
+ "ActiveRecord::RecordInvalid",
47
+ "ActiveRecord::RecordNotSaved",
48
+ # Additional items
49
+ "ActiveJob::DeserializationError",
50
+ "CGI::Session::CookieStore::TamperedWithCookie",
51
+ "GdsApi::HTTPIntermittentServerError",
52
+ "GdsApi::TimedOutException",
53
+ "Mongoid::Errors::DocumentNotFound",
54
+ "Sinatra::NotFound",
55
+ "Slimmer::IntermittentRetrievalError",
56
+ ]
57
+
58
+ # This will exclude exceptions that are triggered by one of the ignored
59
+ # exceptions. For example, when any exception occurs in a template,
60
+ # Rails will raise a ActionView::Template::Error, instead of the original error.
61
+ self.inspect_exception_causes_for_exclusion = true
62
+
63
+ # List of exceptions to ignore if they take place during the data sync.
64
+ # Some errors are transient in nature, e.g. PostgreSQL databases being
65
+ # unavailable, and add little value. In fact, their presence can greatly
66
+ # increase the number of errors being sent and risk genuine errors being
67
+ # rate-limited by Sentry.
68
+ self.data_sync_excluded_exceptions = [
69
+ "PG::Error",
70
+ "GdsApi::ContentStore::ItemNotFound",
71
+ ]
72
+
15
73
  @before_send_callbacks = [
16
- ignore_exceptions_if_not_in_active_sentry_env,
17
74
  ignore_excluded_exceptions_in_data_sync,
18
75
  increment_govuk_statsd_counters,
19
76
  ]
77
+ # Need to invoke an arbitrary `before_send=` in order to trigger the
78
+ # `before_send_callbacks` behaviour
79
+ self.before_send = lambda { |error_or_event, _hint|
80
+ error_or_event
81
+ }
20
82
  end
21
83
 
22
84
  def before_send=(closure)
@@ -26,10 +88,6 @@ module GovukError
26
88
 
27
89
  protected
28
90
 
29
- def ignore_exceptions_if_not_in_active_sentry_env
30
- ->(event, _hint) { event if active_sentry_environments.include?(sentry_environment) }
31
- end
32
-
33
91
  def ignore_excluded_exceptions_in_data_sync
34
92
  lambda { |event, hint|
35
93
  data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore|
@@ -5,6 +5,12 @@ require "govuk_app_config/govuk_error/configuration"
5
5
  require "govuk_app_config/version"
6
6
 
7
7
  module GovukError
8
+ class AlreadyInitialised < StandardError
9
+ def initialize(msg = "You can only call GovukError.configure once!")
10
+ super
11
+ end
12
+ end
13
+
8
14
  def self.notify(exception_or_message, args = {})
9
15
  # Allow users to use `parameters` as a key like the Airbrake
10
16
  # client, allowing easy upgrades.
@@ -14,11 +20,23 @@ module GovukError
14
20
  args[:tags] ||= {}
15
21
  args[:tags][:govuk_app_config_version] = GovukAppConfig::VERSION
16
22
 
17
- Sentry.capture_exception(exception_or_message, args)
23
+ if exception_or_message.is_a?(String)
24
+ Sentry.capture_message(exception_or_message, args)
25
+ else
26
+ Sentry.capture_exception(exception_or_message, args)
27
+ end
28
+ end
29
+
30
+ def self.is_configured?
31
+ Sentry.get_current_client != nil
18
32
  end
19
33
 
20
34
  def self.configure
21
- @configuration ||= Configuration.new(Sentry::Configuration.new)
22
- yield @configuration
35
+ raise GovukError::AlreadyInitialised if is_configured?
36
+
37
+ Sentry.init do |sentry_config|
38
+ config = Configuration.new(sentry_config)
39
+ yield config if block_given?
40
+ end
23
41
  end
24
42
  end
@@ -0,0 +1,37 @@
1
+ module GovukPuma
2
+ def self.configure_rails(config)
3
+ config.port ENV.fetch("PORT", 3000)
4
+
5
+ config.environment ENV.fetch("RAILS_ENV", "development")
6
+
7
+ if ENV["GOVUK_APP_LOGROOT"]
8
+ config.stdout_redirect "#{ENV['GOVUK_APP_LOGROOT']}/app.out.log" "#{ENV['GOVUK_APP_LOGROOT']}/app.err.log"
9
+ end
10
+
11
+ # `worker_timeout` specifies how many seconds Puma will wait before terminating a worker.
12
+ timeout = ENV.fetch("RAILS_ENV", "development") == "development" ? 3600 : 15
13
+ config.worker_timeout timeout
14
+
15
+ # When changing the min/max threads for Puma, also consider changing ActiveRecord to match.
16
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
17
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count)
18
+ config.threads min_threads_count, max_threads_count
19
+
20
+ # `workers` specifies the number of worker processes that Puma will fork.
21
+ # The overall concurrency limit is worker count * max threads per worker.
22
+ config.workers ENV.fetch("WEB_CONCURRENCY", 2)
23
+
24
+ # `preload_app!` tells Puma to load application code before forking worker processes.
25
+ # This reduces RAM wastage by making better use of copy-on-write.
26
+ config.preload_app!
27
+
28
+ config.before_fork do |_server|
29
+ next unless ENV["GOVUK_APP_ROOT"]
30
+
31
+ ENV["BUNDLE_GEMFILE"] = "#{ENV['GOVUK_APP_ROOT']}/Gemfile"
32
+ end
33
+
34
+ # Allow puma to be restarted by `rails restart` command.
35
+ config.plugin :tmp_restart
36
+ end
37
+ end
@@ -3,5 +3,9 @@ module GovukAppConfig
3
3
  config.before_initialize do
4
4
  GovukLogging.configure if Rails.env.production?
5
5
  end
6
+
7
+ config.after_initialize do
8
+ GovukError.configure unless GovukError.is_configured?
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "4.0.0.pre.3".freeze
2
+ VERSION = "4.1.0".freeze
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require "govuk_app_config/version"
2
2
  require "govuk_app_config/govuk_statsd"
3
3
  require "govuk_app_config/govuk_error"
4
- require "govuk_app_config/govuk_error/configure"
5
4
  require "govuk_app_config/govuk_healthcheck"
6
5
  require "govuk_app_config/govuk_i18n"
7
6
  # This require is deprecated and should be removed on next major version bump
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.pre.3
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstasher
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: puma
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: sentry-rails
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -244,7 +258,6 @@ files:
244
258
  - lib/govuk_app_config/govuk_content_security_policy.rb
245
259
  - lib/govuk_app_config/govuk_error.rb
246
260
  - lib/govuk_app_config/govuk_error/configuration.rb
247
- - lib/govuk_app_config/govuk_error/configure.rb
248
261
  - lib/govuk_app_config/govuk_error/govuk_data_sync.rb
249
262
  - lib/govuk_app_config/govuk_healthcheck.rb
250
263
  - lib/govuk_app_config/govuk_healthcheck/active_record.rb
@@ -255,6 +268,7 @@ files:
255
268
  - lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
256
269
  - lib/govuk_app_config/govuk_i18n.rb
257
270
  - lib/govuk_app_config/govuk_logging.rb
271
+ - lib/govuk_app_config/govuk_puma.rb
258
272
  - lib/govuk_app_config/govuk_statsd.rb
259
273
  - lib/govuk_app_config/govuk_unicorn.rb
260
274
  - lib/govuk_app_config/rails_ext/action_dispatch/debug_exceptions.rb
@@ -275,9 +289,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
275
289
  version: '2.6'
276
290
  required_rubygems_version: !ruby/object:Gem::Requirement
277
291
  requirements:
278
- - - ">"
292
+ - - ">="
279
293
  - !ruby/object:Gem::Version
280
- version: 1.3.1
294
+ version: '0'
281
295
  requirements: []
282
296
  rubygems_version: 3.0.3
283
297
  signing_key:
@@ -1,62 +0,0 @@
1
- GovukError.configure do |config|
2
- # These are the environments (described by the `SENTRY_CURRENT_ENV`
3
- # ENV variable) where we want to capture Sentry errors. If
4
- # `SENTRY_CURRENT_ENV` isn't in this list, or isn't defined, then
5
- # don't capture the error.
6
- config.active_sentry_environments = %w[
7
- integration-blue-aws
8
- staging
9
- production
10
- ]
11
-
12
- config.excluded_exceptions = [
13
- # Default ActionDispatch rescue responses
14
- "ActionController::RoutingError",
15
- "AbstractController::ActionNotFound",
16
- "ActionController::MethodNotAllowed",
17
- "ActionController::UnknownHttpMethod",
18
- "ActionController::NotImplemented",
19
- "ActionController::UnknownFormat",
20
- "Mime::Type::InvalidMimeType",
21
- "ActionController::MissingExactTemplate",
22
- "ActionController::InvalidAuthenticityToken",
23
- "ActionController::InvalidCrossOriginRequest",
24
- "ActionDispatch::Http::Parameters::ParseError",
25
- "ActionController::BadRequest",
26
- "ActionController::ParameterMissing",
27
- "Rack::QueryParser::ParameterTypeError",
28
- "Rack::QueryParser::InvalidParameterError",
29
- # Default ActiveRecord rescue responses
30
- "ActiveRecord::RecordNotFound",
31
- "ActiveRecord::StaleObjectError",
32
- "ActiveRecord::RecordInvalid",
33
- "ActiveRecord::RecordNotSaved",
34
- # Additional items
35
- "ActiveJob::DeserializationError",
36
- "CGI::Session::CookieStore::TamperedWithCookie",
37
- "GdsApi::HTTPIntermittentServerError",
38
- "GdsApi::TimedOutException",
39
- "Mongoid::Errors::DocumentNotFound",
40
- "Sinatra::NotFound",
41
- "Slimmer::IntermittentRetrievalError",
42
- ]
43
-
44
- # This will exclude exceptions that are triggered by one of the ignored
45
- # exceptions. For example, when any exception occurs in a template,
46
- # Rails will raise a ActionView::Template::Error, instead of the original error.
47
- config.inspect_exception_causes_for_exclusion = true
48
-
49
- # List of exceptions to ignore if they take place during the data sync.
50
- # Some errors are transient in nature, e.g. PostgreSQL databases being
51
- # unavailable, and add little value. In fact, their presence can greatly
52
- # increase the number of errors being sent and risk genuine errors being
53
- # rate-limited by Sentry.
54
- config.data_sync_excluded_exceptions = [
55
- "PG::Error",
56
- "GdsApi::ContentStore::ItemNotFound",
57
- ]
58
-
59
- config.before_send = lambda { |error_or_event, _hint|
60
- error_or_event
61
- }
62
- end