govuk_app_config 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09d834575f5a08c3fbac882d165d1dbe413693f963d7e8e82b4a17b180fea526'
4
- data.tar.gz: e762adcec651712f0b4172773f7c2128388245ddaba645409ce1ccd37c6326ee
3
+ metadata.gz: dbd89ce53c62443a1bf91f7c782fc121a493323b8f55f77db131e9fab17bc78b
4
+ data.tar.gz: cc5435d8e5a2769c688afa0f37869ec96bc58311b2c7e5051e0dbe226496f50c
5
5
  SHA512:
6
- metadata.gz: 7f75e55060e8204fea9eb2e202ffb2a392f74c4e5d4dbf2ec6acff1cfe0c502bffef302aa870a8cae0b1b114409514976f55d77f7f381d06fd237f98e0d9745e
7
- data.tar.gz: a133f95a954b855b52b22b4aea77bf092a27c23fba96d4ac1171cc60839dda6731eeabc8c6106b8144121c3912fe590df63e6e08ee870c65962c24cafc8346c8
6
+ metadata.gz: 8c9a936938fdb3795e3edd0fdf9f43a368a5130f034d30150bdd4201c5490a47b015b492a1275d8dba4668ec9e44b32b4a8692fa4cddf7bb59eee9242f468e23
7
+ data.tar.gz: ad4e17d9b55e828c4542517a427ba6f35152583fe536f87801a7d2567cff00a0bc6d036103cc29186fab381b61b904b1a7eaa63c0a088a0b55c2735371ea39e1
@@ -1,3 +1,7 @@
1
+ # 2.5.0
2
+
3
+ * Use delegator pattern for `GovukError.configure`, to allow custom `should_capture` (https://github.com/alphagov/govuk_app_config/pull/160)
4
+
1
5
  # 2.4.1
2
6
 
3
7
  * Bump 'sentry-raven' to 3.1.1 to improve grouping of errors (https://github.com/alphagov/govuk_app_config/pull/162)
data/README.md CHANGED
@@ -89,6 +89,27 @@ GovukError.configure do |config|
89
89
  end
90
90
  ```
91
91
 
92
+ And you can exclude errors from being reported if they occur during the nightly data sync (on integration and staging):
93
+
94
+ ```ruby
95
+ GovukError.configure do |config|
96
+ config.data_sync_excluded_exceptions << "PG::Error"
97
+ end
98
+ ```
99
+
100
+ Finally, you can pass your own callback to evaluate whether or not to capture the exception.
101
+ Note that if an exception is on the `excluded_exceptions` list, or on the `data_sync_excluded_exceptions`
102
+ and occurs at the time of a data sync, then it will be excluded even if the custom
103
+ `should_capture` callback returns `true`.
104
+
105
+ ```ruby
106
+ GovukError.configure do |config|
107
+ config.should_capture = lambda do |error_or_event|
108
+ error_or_event == "do capture"
109
+ end
110
+ end
111
+ ```
112
+
92
113
  `GovukError.configure` has the same options as the Sentry client, Raven. See [the Raven docs for all configuration options](https://docs.sentry.io/clients/ruby/config).
93
114
 
94
115
  ## Statsd
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "statsd-ruby", "~> 1.4.0"
26
26
  spec.add_dependency "unicorn", ">= 5.4", "< 5.8"
27
27
 
28
+ spec.add_development_dependency "byebug"
28
29
  spec.add_development_dependency "climate_control"
29
30
  spec.add_development_dependency "rack-test", "~> 1.1.0"
30
31
  spec.add_development_dependency "rails", "~> 6"
@@ -1,11 +1,11 @@
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"
4
5
  require "govuk_app_config/govuk_healthcheck"
5
6
  # This require is deprecated and should be removed on next major version bump
6
7
  # and should be required by applications directly.
7
8
  require "govuk_app_config/govuk_unicorn"
8
- require "govuk_app_config/configure"
9
9
 
10
10
  if defined?(Rails)
11
11
  require "govuk_app_config/govuk_logging"
@@ -1,5 +1,6 @@
1
1
  require "sentry-raven"
2
2
  require "govuk_app_config/govuk_statsd"
3
+ require "govuk_app_config/govuk_error/configuration"
3
4
 
4
5
  module GovukError
5
6
  def self.notify(exception_or_message, args = {})
@@ -12,8 +13,7 @@ module GovukError
12
13
  end
13
14
 
14
15
  def self.configure
15
- Raven.configure do |config|
16
- yield(config)
17
- end
16
+ @configuration ||= Configuration.new(Raven.configuration)
17
+ yield @configuration
18
18
  end
19
19
  end
@@ -0,0 +1,36 @@
1
+ require "govuk_app_config/govuk_error/govuk_data_sync"
2
+
3
+ module GovukError
4
+ class Configuration < SimpleDelegator
5
+ attr_reader :data_sync
6
+ attr_accessor :data_sync_excluded_exceptions
7
+
8
+ def initialize(_raven_configuration)
9
+ super
10
+ @data_sync = GovukDataSync.new(ENV["GOVUK_DATA_SYNC_PERIOD"])
11
+ self.data_sync_excluded_exceptions = []
12
+ self.should_capture = ignore_excluded_exceptions_in_data_sync
13
+ end
14
+
15
+ def should_capture=(closure)
16
+ combined = lambda do |error_or_event|
17
+ (ignore_excluded_exceptions_in_data_sync.call(error_or_event) && closure.call(error_or_event))
18
+ end
19
+
20
+ super(combined)
21
+ end
22
+
23
+ protected
24
+
25
+ def ignore_excluded_exceptions_in_data_sync
26
+ lambda { |error_or_event|
27
+ data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore|
28
+ exception_chain = Raven::Utils::ExceptionCauseChain.exception_to_array(error_or_event)
29
+ exception_chain.any? { |exception| exception.class.to_s == exception_to_ignore }
30
+ end
31
+
32
+ !(data_sync.in_progress? && data_sync_ignored_error)
33
+ }
34
+ end
35
+ end
36
+ end
@@ -43,6 +43,15 @@ GovukError.configure do |config|
43
43
  # Rails will raise a ActionView::Template::Error, instead of the original error.
44
44
  config.inspect_exception_causes_for_exclusion = true
45
45
 
46
+ # List of exceptions to ignore if they take place during the data sync.
47
+ # Some errors are transient in nature, e.g. PostgreSQL databases being
48
+ # unavailable, and add little value. In fact, their presence can greatly
49
+ # increase the number of errors being sent and risk genuine errors being
50
+ # rate-limited by Sentry.
51
+ config.data_sync_excluded_exceptions = [
52
+ "PG::Error",
53
+ ]
54
+
46
55
  config.transport_failure_callback = proc {
47
56
  GovukStatsd.increment("error_reports_failed")
48
57
  }
@@ -0,0 +1,50 @@
1
+ require "time"
2
+
3
+ module GovukError
4
+ class GovukDataSync
5
+ class MalformedDataSyncPeriod < RuntimeError
6
+ attr_reader :invalid_value
7
+
8
+ 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')."
14
+ end
15
+ end
16
+
17
+ attr_reader :from, :to
18
+
19
+ def initialize(govuk_data_sync_period)
20
+ return if govuk_data_sync_period.nil?
21
+
22
+ parts = govuk_data_sync_period.split("-")
23
+ raise MalformedDataSyncPeriod, govuk_data_sync_period unless parts.count == 2
24
+
25
+ @from, @to = parts.map { |time| Time.parse(time) }
26
+ rescue ArgumentError
27
+ raise MalformedDataSyncPeriod, govuk_data_sync_period
28
+ end
29
+
30
+ def in_progress?
31
+ from.present? && to.present? && in_time_range?(from, to)
32
+ end
33
+
34
+ private
35
+
36
+ # `from`/`to` times are in relation to the local server time, which is expected to be in UTC as per:
37
+ # https://github.com/alphagov/govuk-puppet/blob/b588e4ade996e97b8975e69cb00800521fff4a48/modules/govuk_envsys/files/etc/environment#L3
38
+ def in_time_range?(from, to)
39
+ hour_is_in_range = Time.now.hour >= from.hour || Time.now.hour <= to.hour
40
+ minute_is_in_range = if Time.now.hour == from.hour
41
+ Time.now.min >= from.min
42
+ elsif Time.now.hour == to.hour
43
+ Time.now.min <= to.min
44
+ else
45
+ true
46
+ end
47
+ hour_is_in_range && minute_is_in_range
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "2.4.1".freeze
2
+ VERSION = "2.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - "<"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '5.8'
81
+ - !ruby/object:Gem::Dependency
82
+ name: byebug
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: climate_control
83
97
  requirement: !ruby/object:Gem::Requirement
@@ -212,9 +226,11 @@ files:
212
226
  - docs/healthchecks.md
213
227
  - govuk_app_config.gemspec
214
228
  - lib/govuk_app_config.rb
215
- - lib/govuk_app_config/configure.rb
216
229
  - lib/govuk_app_config/govuk_content_security_policy.rb
217
230
  - lib/govuk_app_config/govuk_error.rb
231
+ - lib/govuk_app_config/govuk_error/configuration.rb
232
+ - lib/govuk_app_config/govuk_error/configure.rb
233
+ - lib/govuk_app_config/govuk_error/govuk_data_sync.rb
218
234
  - lib/govuk_app_config/govuk_healthcheck.rb
219
235
  - lib/govuk_app_config/govuk_healthcheck/active_record.rb
220
236
  - lib/govuk_app_config/govuk_healthcheck/checkup.rb