govuk_app_config 2.3.0 → 2.5.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 +4 -4
- data/CHANGELOG.md +22 -2
- data/README.md +21 -0
- data/docs/healthchecks.md +9 -0
- data/govuk_app_config.gemspec +3 -3
- data/lib/govuk_app_config.rb +1 -1
- data/lib/govuk_app_config/govuk_error.rb +3 -3
- data/lib/govuk_app_config/govuk_error/configuration.rb +42 -0
- data/lib/govuk_app_config/{configure.rb → govuk_error/configure.rb} +9 -0
- data/lib/govuk_app_config/govuk_error/govuk_data_sync.rb +50 -0
- data/lib/govuk_app_config/govuk_healthcheck.rb +2 -0
- data/lib/govuk_app_config/govuk_healthcheck/mongoid.rb +14 -0
- data/lib/govuk_app_config/govuk_healthcheck/rails_cache.rb +16 -0
- data/lib/govuk_app_config/rails_ext/action_dispatch/debug_exceptions.rb +1 -1
- data/lib/govuk_app_config/version.rb +1 -1
- metadata +19 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac69416b5c20576e14410fd9f46d4b0992b13d823b64983f702ea0226dc40461
|
4
|
+
data.tar.gz: eb47104d4c81dc24f9c6919d650a21acc388986948819a971294a46594bc7ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 171a7f28f2d6daf265b3829a487d8b2b6a355915a535f9d3c728edce1f4d6bf89aa8163e11c37ce0c5976cd18f6c7ca9a5bddf3ca0bca4ccbdf3453d19470c9f
|
7
|
+
data.tar.gz: cc5a3382d6fdc1ce5ac1cd868c18fc6e7a77b68d8da04d32190c1317ec8def77969dab9528821cea8e5257676f7a15155fced541148dfd8c4dd850f342235005
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,26 @@
|
|
1
|
+
# 2.5.2
|
2
|
+
|
3
|
+
* Fix govuk_app_config in Ruby 2.7 environments by explicitly requiring the 'delegate' library (https://github.com/alphagov/govuk_app_config/pull/167)
|
4
|
+
|
5
|
+
# 2.5.1
|
6
|
+
|
7
|
+
* Increase scope of `data_sync_excluded_exceptions` so that it includes subclasses (https://github.com/alphagov/govuk_app_config/pull/165)
|
8
|
+
|
9
|
+
# 2.5.0
|
10
|
+
|
11
|
+
* Use delegator pattern for `GovukError.configure`, to allow custom `should_capture` (https://github.com/alphagov/govuk_app_config/pull/160)
|
12
|
+
|
13
|
+
# 2.4.1
|
14
|
+
|
15
|
+
* Bump 'sentry-raven' to 3.1.1 to improve grouping of errors (https://github.com/alphagov/govuk_app_config/pull/162)
|
16
|
+
|
17
|
+
# 2.4.0
|
18
|
+
|
19
|
+
* Add new GovukHealthcheck::Mongoid and GovukHealthcheck::RailsCache health checks (https://github.com/alphagov/govuk_app_config/pull/161)
|
20
|
+
|
1
21
|
# 2.3.0
|
2
22
|
|
3
|
-
* Remove unused SidekiqQueueSizeCheck healthcheck base class
|
23
|
+
* Remove unused SidekiqQueueSizeCheck healthcheck base class (https://github.com/alphagov/govuk_app_config/pull/156)
|
4
24
|
|
5
25
|
# 2.2.2
|
6
26
|
|
@@ -258,7 +278,7 @@
|
|
258
278
|
* Add Unicorn (our web server) as a dependency
|
259
279
|
* Use version [2.7.0 of the Sentry client][sentry-270].
|
260
280
|
* Set up logging configuration for Rails applications.
|
261
|
-
* Don't send `ActionController::BadRequest`
|
281
|
+
* Don't send `ActionController::BadRequest`
|
262
282
|
|
263
283
|
[sentry-270]: https://github.com/getsentry/raven-ruby/commit/ef623824cb0a8a2f60be5fb7e12f80454da54fd7
|
264
284
|
|
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
|
data/docs/healthchecks.md
CHANGED
@@ -73,6 +73,15 @@ if it must be subclassed to work, but a concrete class which works on its own
|
|
73
73
|
doesn't need that suffix. You should aim to follow this convention in your own
|
74
74
|
apps, ideally putting custom health checks into a `Healthcheck` module.
|
75
75
|
|
76
|
+
### `RailsCache`
|
77
|
+
|
78
|
+
This checks that the Rails cache store, such as Memcached, is acessible by
|
79
|
+
writing and reading back a cache entry called "healthcheck-cache".
|
80
|
+
|
81
|
+
### `Mongoid`
|
82
|
+
|
83
|
+
This checks that the app has a connection to its Mongo database via Mongoid.
|
84
|
+
|
76
85
|
### `SidekiqRedis`
|
77
86
|
|
78
87
|
This checks that the app has a connection to Redis via Sidekiq.
|
data/govuk_app_config.gemspec
CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = %w[lib]
|
22
22
|
|
23
23
|
spec.add_dependency "logstasher", ">= 1.2.2", "< 1.4.0"
|
24
|
-
spec.add_dependency "sentry-raven", "
|
24
|
+
spec.add_dependency "sentry-raven", "~> 3.1.1"
|
25
25
|
spec.add_dependency "statsd-ruby", "~> 1.4.0"
|
26
|
-
spec.add_dependency "unicorn", ">= 5.4", "< 5.
|
26
|
+
spec.add_dependency "unicorn", ">= 5.4", "< 5.8"
|
27
27
|
|
28
|
-
spec.add_development_dependency "
|
28
|
+
spec.add_development_dependency "byebug"
|
29
29
|
spec.add_development_dependency "climate_control"
|
30
30
|
spec.add_development_dependency "rack-test", "~> 1.1.0"
|
31
31
|
spec.add_development_dependency "rails", "~> 6"
|
data/lib/govuk_app_config.rb
CHANGED
@@ -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.
|
16
|
-
|
17
|
-
end
|
16
|
+
@configuration ||= Configuration.new(Raven.configuration)
|
17
|
+
yield @configuration
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "delegate"
|
2
|
+
require "govuk_app_config/govuk_error/govuk_data_sync"
|
3
|
+
|
4
|
+
module GovukError
|
5
|
+
class Configuration < SimpleDelegator
|
6
|
+
attr_reader :data_sync
|
7
|
+
attr_accessor :data_sync_excluded_exceptions
|
8
|
+
|
9
|
+
def initialize(_raven_configuration)
|
10
|
+
super
|
11
|
+
@data_sync = GovukDataSync.new(ENV["GOVUK_DATA_SYNC_PERIOD"])
|
12
|
+
self.data_sync_excluded_exceptions = []
|
13
|
+
self.should_capture = ignore_excluded_exceptions_in_data_sync
|
14
|
+
end
|
15
|
+
|
16
|
+
def should_capture=(closure)
|
17
|
+
combined = lambda do |error_or_event|
|
18
|
+
(ignore_excluded_exceptions_in_data_sync.call(error_or_event) && closure.call(error_or_event))
|
19
|
+
end
|
20
|
+
|
21
|
+
super(combined)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def ignore_excluded_exceptions_in_data_sync
|
27
|
+
lambda { |error_or_event|
|
28
|
+
data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore|
|
29
|
+
exception_to_ignore = Object.const_get(exception_to_ignore) unless exception_to_ignore.is_a?(Module)
|
30
|
+
exception_chain = Raven::Utils::ExceptionCauseChain.exception_to_array(error_or_event)
|
31
|
+
exception_chain.any? { |exception| exception.is_a?(exception_to_ignore) }
|
32
|
+
rescue NameError
|
33
|
+
# the exception type represented by the exception_to_ignore string
|
34
|
+
# doesn't even exist in this environment, so won't be found in the chain
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
!(data_sync.in_progress? && data_sync_ignored_error)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
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,5 +1,7 @@
|
|
1
1
|
require "govuk_app_config/govuk_healthcheck/checkup"
|
2
2
|
require "govuk_app_config/govuk_healthcheck/active_record"
|
3
|
+
require "govuk_app_config/govuk_healthcheck/mongoid"
|
4
|
+
require "govuk_app_config/govuk_healthcheck/rails_cache"
|
3
5
|
require "govuk_app_config/govuk_healthcheck/sidekiq_redis"
|
4
6
|
require "govuk_app_config/govuk_healthcheck/threshold_check"
|
5
7
|
require "govuk_app_config/govuk_healthcheck/sidekiq_queue_check"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GovukHealthcheck
|
2
|
+
class RailsCache
|
3
|
+
def name
|
4
|
+
:rails_cache
|
5
|
+
end
|
6
|
+
|
7
|
+
def status
|
8
|
+
::Rails.cache.write("healthcheck-cache", true)
|
9
|
+
raise unless ::Rails.cache.read("healthcheck-cache")
|
10
|
+
|
11
|
+
GovukHealthcheck::OK
|
12
|
+
rescue StandardError
|
13
|
+
GovukHealthcheck::CRITICAL
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.
|
4
|
+
version: 2.5.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: 2020-
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstasher
|
@@ -34,22 +34,16 @@ dependencies:
|
|
34
34
|
name: sentry-raven
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 2.7.1
|
40
|
-
- - "<"
|
37
|
+
- - "~>"
|
41
38
|
- !ruby/object:Gem::Version
|
42
|
-
version: 3.1.
|
39
|
+
version: 3.1.1
|
43
40
|
type: :runtime
|
44
41
|
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
46
43
|
requirements:
|
47
|
-
- - "
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 2.7.1
|
50
|
-
- - "<"
|
44
|
+
- - "~>"
|
51
45
|
- !ruby/object:Gem::Version
|
52
|
-
version: 3.1.
|
46
|
+
version: 3.1.1
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: statsd-ruby
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +67,7 @@ dependencies:
|
|
73
67
|
version: '5.4'
|
74
68
|
- - "<"
|
75
69
|
- !ruby/object:Gem::Version
|
76
|
-
version: '5.
|
70
|
+
version: '5.8'
|
77
71
|
type: :runtime
|
78
72
|
prerelease: false
|
79
73
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -83,21 +77,21 @@ dependencies:
|
|
83
77
|
version: '5.4'
|
84
78
|
- - "<"
|
85
79
|
- !ruby/object:Gem::Version
|
86
|
-
version: '5.
|
80
|
+
version: '5.8'
|
87
81
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
82
|
+
name: byebug
|
89
83
|
requirement: !ruby/object:Gem::Requirement
|
90
84
|
requirements:
|
91
|
-
- - "
|
85
|
+
- - ">="
|
92
86
|
- !ruby/object:Gem::Version
|
93
|
-
version: '
|
87
|
+
version: '0'
|
94
88
|
type: :development
|
95
89
|
prerelease: false
|
96
90
|
version_requirements: !ruby/object:Gem::Requirement
|
97
91
|
requirements:
|
98
|
-
- - "
|
92
|
+
- - ">="
|
99
93
|
- !ruby/object:Gem::Version
|
100
|
-
version: '
|
94
|
+
version: '0'
|
101
95
|
- !ruby/object:Gem::Dependency
|
102
96
|
name: climate_control
|
103
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -232,12 +226,16 @@ files:
|
|
232
226
|
- docs/healthchecks.md
|
233
227
|
- govuk_app_config.gemspec
|
234
228
|
- lib/govuk_app_config.rb
|
235
|
-
- lib/govuk_app_config/configure.rb
|
236
229
|
- lib/govuk_app_config/govuk_content_security_policy.rb
|
237
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
|
238
234
|
- lib/govuk_app_config/govuk_healthcheck.rb
|
239
235
|
- lib/govuk_app_config/govuk_healthcheck/active_record.rb
|
240
236
|
- lib/govuk_app_config/govuk_healthcheck/checkup.rb
|
237
|
+
- lib/govuk_app_config/govuk_healthcheck/mongoid.rb
|
238
|
+
- lib/govuk_app_config/govuk_healthcheck/rails_cache.rb
|
241
239
|
- lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
|
242
240
|
- lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_latency_check.rb
|
243
241
|
- lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
|
@@ -268,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
266
|
- !ruby/object:Gem::Version
|
269
267
|
version: '0'
|
270
268
|
requirements: []
|
271
|
-
rubygems_version: 3.
|
269
|
+
rubygems_version: 3.1.4
|
272
270
|
signing_key:
|
273
271
|
specification_version: 4
|
274
272
|
summary: Base configuration for GOV.UK applications
|