govuk_app_config 2.2.2 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/README.md +21 -0
- data/docs/healthchecks.md +9 -18
- 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 +41 -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 -1
- 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 -22
- data/lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_size_check.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c21acad0f7309884269c7e2e1bcca15285f6ee8d43de0c9ac4cb2320438858d6
|
4
|
+
data.tar.gz: 4ecabaceee90ea13755cd262b825a9f5c54ad4bbb106e830b8f61a3bf923c11d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09dbcb815fca0dd6e2f05e2eca147a2a9e7fd1580c343a9bb2c356312e0a43a9918f99f0d795a88ad989bc11552bfe6154944ba7a3189b24522e62767aa5262
|
7
|
+
data.tar.gz: bf3328f7ee32405b825d24386016b49d5cb80e87c0cf2465419120f6e73f1f5c67e68b239b52505a045cb6a11a9b95ddbec68704c0d0540b4531b5d1ab2b02ce
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# 2.5.1
|
2
|
+
|
3
|
+
* Increase scope of `data_sync_excluded_exceptions` so that it includes subclasses (https://github.com/alphagov/govuk_app_config/pull/165)
|
4
|
+
|
5
|
+
# 2.5.0
|
6
|
+
|
7
|
+
* Use delegator pattern for `GovukError.configure`, to allow custom `should_capture` (https://github.com/alphagov/govuk_app_config/pull/160)
|
8
|
+
|
9
|
+
# 2.4.1
|
10
|
+
|
11
|
+
* Bump 'sentry-raven' to 3.1.1 to improve grouping of errors (https://github.com/alphagov/govuk_app_config/pull/162)
|
12
|
+
|
13
|
+
# 2.4.0
|
14
|
+
|
15
|
+
* Add new GovukHealthcheck::Mongoid and GovukHealthcheck::RailsCache health checks (https://github.com/alphagov/govuk_app_config/pull/161)
|
16
|
+
|
17
|
+
# 2.3.0
|
18
|
+
|
19
|
+
* Remove unused SidekiqQueueSizeCheck healthcheck base class (https://github.com/alphagov/govuk_app_config/pull/156)
|
20
|
+
|
1
21
|
# 2.2.2
|
2
22
|
|
3
23
|
* Add www.googletagmanager.com and www.gstatic.com to Content Security Policy (https://github.com/alphagov/govuk_app_config/pull/153)
|
@@ -254,7 +274,7 @@
|
|
254
274
|
* Add Unicorn (our web server) as a dependency
|
255
275
|
* Use version [2.7.0 of the Sentry client][sentry-270].
|
256
276
|
* Set up logging configuration for Rails applications.
|
257
|
-
* Don't send `ActionController::BadRequest`
|
277
|
+
* Don't send `ActionController::BadRequest`
|
258
278
|
|
259
279
|
[sentry-270]: https://github.com/getsentry/raven-ruby/commit/ef623824cb0a8a2f60be5fb7e12f80454da54fd7
|
260
280
|
|
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.
|
@@ -128,24 +137,6 @@ class MySidekiqQueueLatencyCheck < GovukHealthcheck::SidekiqQueueLatencyCheck
|
|
128
137
|
end
|
129
138
|
```
|
130
139
|
|
131
|
-
### `SidekiqQueueSizeCheck`
|
132
|
-
|
133
|
-
This class is the basis for a check which compares the Sidekiq queue sizes
|
134
|
-
with warning or critical thresholds.
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
class MySidekiqQueueSizeCheck < GovukHealthcheck::SidekiqQueueSizeCheck
|
138
|
-
def warning_threshold(queue:)
|
139
|
-
# the warning threshold for a particular queue
|
140
|
-
end
|
141
|
-
|
142
|
-
def critical_threshold(queue:)
|
143
|
-
# the critical threshold for a particular queue
|
144
|
-
end
|
145
|
-
end
|
146
|
-
```
|
147
|
-
|
148
|
-
|
149
140
|
### `SidekiqRetrySizeCheck`
|
150
141
|
|
151
142
|
Similar to `SidekiqQueueSizeCheck`, this class is the basis for a check which
|
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,41 @@
|
|
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_to_ignore = Object.const_get(exception_to_ignore) unless exception_to_ignore.is_a?(Module)
|
29
|
+
exception_chain = Raven::Utils::ExceptionCauseChain.exception_to_array(error_or_event)
|
30
|
+
exception_chain.any? { |exception| exception.is_a?(exception_to_ignore) }
|
31
|
+
rescue NameError
|
32
|
+
# the exception type represented by the exception_to_ignore string
|
33
|
+
# doesn't even exist in this environment, so won't be found in the chain
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
!(data_sync.in_progress? && data_sync_ignored_error)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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,10 +1,11 @@
|
|
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"
|
6
8
|
require "govuk_app_config/govuk_healthcheck/sidekiq_queue_latency_check"
|
7
|
-
require "govuk_app_config/govuk_healthcheck/sidekiq_queue_size_check"
|
8
9
|
require "govuk_app_config/govuk_healthcheck/sidekiq_retry_size_check"
|
9
10
|
require "json"
|
10
11
|
|
@@ -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.1
|
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-21 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,15 +226,18 @@ 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
|
-
- lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_size_check.rb
|
244
241
|
- lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
|
245
242
|
- lib/govuk_app_config/govuk_healthcheck/sidekiq_retry_size_check.rb
|
246
243
|
- lib/govuk_app_config/govuk_healthcheck/threshold_check.rb
|
@@ -269,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
266
|
- !ruby/object:Gem::Version
|
270
267
|
version: '0'
|
271
268
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
269
|
+
rubygems_version: 3.1.4
|
273
270
|
signing_key:
|
274
271
|
specification_version: 4
|
275
272
|
summary: Base configuration for GOV.UK applications
|