govuk_app_config 2.10.0 → 4.0.0.pre.2

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: f98f57ba0b9010154d3aefbc2540acd056d35ef42af9e3b22b00495255f46899
4
- data.tar.gz: c5315e4ba1f476e7c0fcb99839ad9e8705a1546e4b48e3246a16e94f6552b383
3
+ metadata.gz: b1a08f51ba88f28b8694fd0f40f94a92ac053a424b25e860b5795e96da7431b7
4
+ data.tar.gz: 6dd0f7061f779450c5fdc029002dc5474070306daa5acf3de5f78a9867667c93
5
5
  SHA512:
6
- metadata.gz: cea414c28b13d2b9cb359bade9dd6626eceb9dfd0f76ca79f77b2b8bff9f4807c01858951860e6888f795a32aa50cd2c79cc1ea63f72a01315a6cbd44b49d8cd
7
- data.tar.gz: 3ef1e0ea53a489935775c9475cecb5f55585d2cfba0aed30b6a184430ab7fada8e24670150ebfa60043a59a6d750f76aeb913b89f826da2bbe3db68ca524cc7a
6
+ metadata.gz: 47c5d3a3da84267ef909d3de765bd60a0af8587bc6712523ee8ca44ccb9bc74f7fc76a0b21b413437f2ea7d35829acb77589b8f29c86904876dd88ad23a0845d
7
+ data.tar.gz: 7ebb2c404c7abde0e16c1b22c63d523491ff70465161e806c3a91a3911e6cddebb406b7b774add5668aaf793a2dab6659f1629eb2c9bc575ba0c782927544cc9
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "03:00"
8
+ open-pull-requests-limit: 10
9
+ ignore:
10
+ - dependency-name: aws-xray-sdk
11
+ versions:
12
+ - "> 0.10.0"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # 4.0.0.pre-2
2
+
3
+ - Fix default Sentry configuration ([#202](https://github.com/alphagov/govuk_app_config/pull/202)).
4
+ - BREAKING: this means no more `silence_ready` or `transport_failure_callback` options.
5
+
6
+ # 4.0.0.pre-1
7
+
8
+ - 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.
9
+ - This release also fixes the `data_sync_excluded_exceptions` behaviour that has been broken since v3.1.0.
10
+ - Released as a pre-release to identify and fix any problems before a wider rollout.
11
+
12
+ # 3.1.1
13
+
14
+ - Fix the new before_send behaviour & tests, and add documentation ([#197](https://github.com/alphagov/govuk_app_config/pull/197))
15
+
16
+ # 3.1.0
17
+
18
+ - Remove support for `should_capture` callbacks in favour of `before_send` ([#196](https://github.com/alphagov/govuk_app_config/pull/196))
19
+
20
+ # 3.0.0
21
+
22
+ * BREAKING: Implement RFC 141 - remove unsuitable healthchecks and return a 500 on healthcheck failure ([#193](https://github.com/alphagov/govuk_app_config/pull/193))
23
+
1
24
  # 2.10.0
2
25
  * Allow LUX domain on img-src policy ([#191](https://github.com/alphagov/govuk_app_config/pull/191))
3
26
 
data/README.md CHANGED
@@ -112,12 +112,12 @@ end
112
112
  Finally, you can pass your own callback to evaluate whether or not to capture the exception.
113
113
  Note that if an exception is on the `excluded_exceptions` list, or on the `data_sync_excluded_exceptions`
114
114
  and occurs at the time of a data sync, then it will be excluded even if the custom
115
- `should_capture` callback returns `true`.
115
+ `before_send` callback doesn't return `nil`.
116
116
 
117
117
  ```ruby
118
118
  GovukError.configure do |config|
119
- config.should_capture = lambda do |error_or_event|
120
- error_or_event == "do capture"
119
+ config.before_send = lambda do |event, hint|
120
+ hint[:exception].is_a?(ErrorWeWantToIgnore) ? nil : event
121
121
  end
122
122
  end
123
123
  ```
@@ -13,15 +13,15 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/alphagov/govuk_app_config"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
16
+ spec.required_ruby_version = ">= 2.6"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.bindir = "exe"
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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 "sentry-raven", "~> 3.1.1"
24
+ spec.add_dependency "sentry-ruby", "~> 4.5.0"
25
25
  spec.add_dependency "statsd-ruby", "~> 1.5.0"
26
26
  spec.add_dependency "unicorn", ">= 5.4", "< 5.9"
27
27
 
@@ -1,4 +1,4 @@
1
- require "sentry-raven"
1
+ require "sentry-ruby"
2
2
  require "govuk_app_config/govuk_statsd"
3
3
  require "govuk_app_config/govuk_error/configuration"
4
4
  require "govuk_app_config/version"
@@ -13,11 +13,11 @@ module GovukError
13
13
  args[:tags] ||= {}
14
14
  args[:tags][:govuk_app_config_version] = GovukAppConfig::VERSION
15
15
 
16
- Raven.capture_exception(exception_or_message, args)
16
+ Sentry.capture_exception(exception_or_message, args)
17
17
  end
18
18
 
19
19
  def self.configure
20
- @configuration ||= Configuration.new(Raven.configuration)
20
+ @configuration ||= Configuration.new(Sentry::Configuration.new)
21
21
  yield @configuration
22
22
  end
23
23
  end
@@ -6,41 +6,35 @@ module GovukError
6
6
  attr_reader :data_sync, :sentry_environment
7
7
  attr_accessor :active_sentry_environments, :data_sync_excluded_exceptions
8
8
 
9
- def initialize(_raven_configuration)
9
+ def initialize(_sentry_configuration)
10
10
  super
11
11
  @sentry_environment = ENV["SENTRY_CURRENT_ENV"]
12
12
  @data_sync = GovukDataSync.new(ENV["GOVUK_DATA_SYNC_PERIOD"])
13
13
  self.active_sentry_environments = []
14
14
  self.data_sync_excluded_exceptions = []
15
- self.should_capture = ignore_exceptions_based_on_env_and_data_sync
15
+ @before_send_callbacks = [
16
+ ignore_exceptions_if_not_in_active_sentry_env,
17
+ ignore_excluded_exceptions_in_data_sync,
18
+ increment_govuk_statsd_counters,
19
+ ]
16
20
  end
17
21
 
18
- def should_capture=(closure)
19
- combined = lambda do |error_or_event|
20
- (ignore_exceptions_based_on_env_and_data_sync.call(error_or_event) && closure.call(error_or_event))
21
- end
22
-
23
- super(combined)
22
+ def before_send=(closure)
23
+ @before_send_callbacks.insert(-2, closure)
24
+ super(run_before_send_callbacks)
24
25
  end
25
26
 
26
27
  protected
27
28
 
28
- def ignore_exceptions_based_on_env_and_data_sync
29
- lambda do |error_or_event|
30
- ignore_exceptions_if_not_in_active_sentry_env.call(error_or_event) &&
31
- ignore_excluded_exceptions_in_data_sync.call(error_or_event)
32
- end
33
- end
34
-
35
29
  def ignore_exceptions_if_not_in_active_sentry_env
36
- ->(_error_or_event) { active_sentry_environments.include?(sentry_environment) }
30
+ ->(event, _hint) { event if active_sentry_environments.include?(sentry_environment) }
37
31
  end
38
32
 
39
33
  def ignore_excluded_exceptions_in_data_sync
40
- lambda { |error_or_event|
34
+ lambda { |event, hint|
41
35
  data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore|
42
36
  exception_to_ignore = Object.const_get(exception_to_ignore) unless exception_to_ignore.is_a?(Module)
43
- exception_chain = Raven::Utils::ExceptionCauseChain.exception_to_array(error_or_event)
37
+ exception_chain = Sentry::Utils::ExceptionCauseChain.exception_to_array(hint[:exception])
44
38
  exception_chain.any? { |exception| exception.is_a?(exception_to_ignore) }
45
39
  rescue NameError
46
40
  # the exception type represented by the exception_to_ignore string
@@ -48,8 +42,29 @@ module GovukError
48
42
  false
49
43
  end
50
44
 
51
- !(data_sync.in_progress? && data_sync_ignored_error)
45
+ event unless data_sync.in_progress? && data_sync_ignored_error
52
46
  }
53
47
  end
48
+
49
+ def increment_govuk_statsd_counters
50
+ lambda { |event, hint|
51
+ if hint[:exception]
52
+ GovukStatsd.increment("errors_occurred")
53
+ GovukStatsd.increment("error_types.#{hint[:exception].class.name.split('::').last.underscore}")
54
+ end
55
+ event
56
+ }
57
+ end
58
+
59
+ def run_before_send_callbacks
60
+ lambda do |event, hint|
61
+ result = event
62
+ @before_send_callbacks.each do |callback|
63
+ result = callback.call(event, hint)
64
+ break if result.nil?
65
+ end
66
+ result
67
+ end
68
+ end
54
69
  end
55
70
  end
@@ -1,12 +1,4 @@
1
1
  GovukError.configure do |config|
2
- config.before_send = proc { |e|
3
- GovukStatsd.increment("errors_occurred")
4
- GovukStatsd.increment("error_types.#{e.class.name.demodulize.underscore}")
5
- e
6
- }
7
-
8
- config.silence_ready = !Rails.env.production? if defined?(Rails)
9
-
10
2
  # These are the environments (described by the `SENTRY_CURRENT_ENV`
11
3
  # ENV variable) where we want to capture Sentry errors. If
12
4
  # `SENTRY_CURRENT_ENV` isn't in this list, or isn't defined, then
@@ -64,7 +56,7 @@ GovukError.configure do |config|
64
56
  "GdsApi::ContentStore::ItemNotFound",
65
57
  ]
66
58
 
67
- config.transport_failure_callback = proc {
68
- GovukStatsd.increment("error_reports_failed")
59
+ config.before_send = lambda { |error_or_event, _hint|
60
+ error_or_event
69
61
  }
70
62
  end
@@ -3,14 +3,8 @@ require "time"
3
3
  module GovukError
4
4
  class GovukDataSync
5
5
  class MalformedDataSyncPeriod < RuntimeError
6
- attr_reader :invalid_value
7
-
8
6
  def initialize(invalid_value)
9
- @invalid_value = invalid_value
10
- end
11
-
12
- def message
13
- "\"#{invalid_value}\" is not a valid value (should be of form '22:00-03:00')."
7
+ super("\"#{invalid_value}\" is not a valid value (should be of form '22:00-03:00').")
14
8
  end
15
9
  end
16
10
 
@@ -4,19 +4,16 @@ require "govuk_app_config/govuk_healthcheck/mongoid"
4
4
  require "govuk_app_config/govuk_healthcheck/rails_cache"
5
5
  require "govuk_app_config/govuk_healthcheck/redis"
6
6
  require "govuk_app_config/govuk_healthcheck/sidekiq_redis"
7
- require "govuk_app_config/govuk_healthcheck/threshold_check"
8
- require "govuk_app_config/govuk_healthcheck/sidekiq_queue_check"
9
- require "govuk_app_config/govuk_healthcheck/sidekiq_queue_latency_check"
10
- require "govuk_app_config/govuk_healthcheck/sidekiq_retry_size_check"
11
7
  require "json"
12
8
 
13
9
  module GovukHealthcheck
14
10
  def self.rack_response(*checks)
15
11
  proc do
12
+ checkup = healthcheck(checks)
16
13
  [
17
- 200,
14
+ checkup[:status] == :ok ? 200 : 500,
18
15
  { "Content-Type" => "application/json" },
19
- [JSON.dump(healthcheck(checks))],
16
+ [JSON.dump(checkup)],
20
17
  ]
21
18
  end
22
19
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "2.10.0".freeze
2
+ VERSION = "4.0.0.pre.2".freeze
3
3
  end
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: 2.10.0
4
+ version: 4.0.0.pre.2
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-03-25 00:00:00.000000000 Z
11
+ date: 2021-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstasher
@@ -31,19 +31,19 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.2.0
33
33
  - !ruby/object:Gem::Dependency
34
- name: sentry-raven
34
+ name: sentry-ruby
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 3.1.1
39
+ version: 4.5.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 3.1.1
46
+ version: 4.5.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: statsd-ruby
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -211,6 +211,7 @@ executables: []
211
211
  extensions: []
212
212
  extra_rdoc_files: []
213
213
  files:
214
+ - ".github/dependabot.yml"
214
215
  - ".gitignore"
215
216
  - ".rspec"
216
217
  - ".rubocop.yml"
@@ -237,11 +238,7 @@ files:
237
238
  - lib/govuk_app_config/govuk_healthcheck/mongoid.rb
238
239
  - lib/govuk_app_config/govuk_healthcheck/rails_cache.rb
239
240
  - lib/govuk_app_config/govuk_healthcheck/redis.rb
240
- - lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
241
- - lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_latency_check.rb
242
241
  - lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
243
- - lib/govuk_app_config/govuk_healthcheck/sidekiq_retry_size_check.rb
244
- - lib/govuk_app_config/govuk_healthcheck/threshold_check.rb
245
242
  - lib/govuk_app_config/govuk_i18n.rb
246
243
  - lib/govuk_app_config/govuk_logging.rb
247
244
  - lib/govuk_app_config/govuk_statsd.rb
@@ -261,14 +258,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
258
  requirements:
262
259
  - - ">="
263
260
  - !ruby/object:Gem::Version
264
- version: '0'
261
+ version: '2.6'
265
262
  required_rubygems_version: !ruby/object:Gem::Requirement
266
263
  requirements:
267
- - - ">="
264
+ - - ">"
268
265
  - !ruby/object:Gem::Version
269
- version: '0'
266
+ version: 1.3.1
270
267
  requirements: []
271
- rubygems_version: 3.1.4
268
+ rubygems_version: 3.0.3
272
269
  signing_key:
273
270
  specification_version: 4
274
271
  summary: Base configuration for GOV.UK applications
@@ -1,62 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqQueueCheck
3
- def status
4
- queues.each do |name, value|
5
- if value >= critical_threshold(queue: name)
6
- return :critical
7
- elsif value >= warning_threshold(queue: name)
8
- return :warning
9
- end
10
- end
11
-
12
- :ok
13
- end
14
-
15
- def message
16
- messages = queues.map do |name, value|
17
- critical = critical_threshold(queue: name)
18
- warning = warning_threshold(queue: name)
19
-
20
- if value >= critical
21
- "#{name} (#{value}) is above the critical threshold (#{critical})"
22
- elsif value >= warning
23
- "#{name} (#{value}) is above the warning threshold (#{warning})"
24
- end
25
- end
26
-
27
- messages = messages.compact
28
-
29
- if messages.empty?
30
- "all queues are below the critical and warning thresholds"
31
- else
32
- messages.join("\n")
33
- end
34
- end
35
-
36
- def details
37
- {
38
- queues: queues.each_with_object({}) do |(name, value), hash|
39
- hash[name] = {
40
- value: value,
41
- thresholds: {
42
- critical: critical_threshold(queue: name),
43
- warning: warning_threshold(queue: name),
44
- }.reject { |_, val| val.to_f.infinite? || val.to_f.nan? },
45
- }
46
- end,
47
- }
48
- end
49
-
50
- def queues
51
- raise "This method must be overriden to be a hash of queue names and data."
52
- end
53
-
54
- def critical_threshold(queue:) # rubocop:disable Lint/UnusedMethodArgument
55
- raise "This method must be overriden to be the critical threshold."
56
- end
57
-
58
- def warning_threshold(queue:) # rubocop:disable Lint/UnusedMethodArgument
59
- raise "This method must be overriden to be the warning threshold."
60
- end
61
- end
62
- end
@@ -1,13 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqQueueLatencyCheck < SidekiqQueueCheck
3
- def name
4
- :sidekiq_queue_latency
5
- end
6
-
7
- def queues
8
- @queues ||= Sidekiq::Stats.new.queues.keys.each_with_object({}) do |name, hash|
9
- hash[name] = Sidekiq::Queue.new(name).latency
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqRetrySizeCheck < ThresholdCheck
3
- def name
4
- :sidekiq_retry_size
5
- end
6
-
7
- def value
8
- Sidekiq::Stats.new.retry_size
9
- end
10
- end
11
- end
@@ -1,50 +0,0 @@
1
- module GovukHealthcheck
2
- class ThresholdCheck
3
- def status
4
- if value >= critical_threshold
5
- :critical
6
- elsif value >= warning_threshold
7
- :warning
8
- else
9
- :ok
10
- end
11
- end
12
-
13
- def message
14
- if value >= critical_threshold
15
- "#{value} is above the critical threshold (#{critical_threshold})"
16
- elsif value >= warning_threshold
17
- "#{value} is above the warning threshold (#{warning_threshold})"
18
- else
19
- "#{value} is below the critical and warning thresholds"
20
- end
21
- end
22
-
23
- def details
24
- {
25
- value: value,
26
- total: total,
27
- thresholds: {
28
- critical: critical_threshold,
29
- warning: warning_threshold,
30
- },
31
- }
32
- end
33
-
34
- def value
35
- raise "This method must be overridden to be the check value."
36
- end
37
-
38
- def total
39
- nil # This method can be overriden to provide the total for the check.
40
- end
41
-
42
- def critical_threshold
43
- raise "This method must be overriden to be the critical threshold."
44
- end
45
-
46
- def warning_threshold
47
- raise "This method must be overriden to be the warning threshold."
48
- end
49
- end
50
- end