govuk_app_config 2.4.1 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +34 -1
- data/govuk_app_config.gemspec +4 -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 +55 -0
- data/lib/govuk_app_config/{configure.rb → govuk_error/configure.rb} +20 -0
- data/lib/govuk_app_config/govuk_error/govuk_data_sync.rb +50 -0
- data/lib/govuk_app_config/version.rb +1 -1
- metadata +25 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa45d48161bdb68ef1bb2adee7901a3b236ffb829ca83a57b7ef6019fa6323fc
|
4
|
+
data.tar.gz: 341a67dd46d52bc0a6e423b16485e27af63976ab668f957ba31d1849e1bd7aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f65f512a4ce726b72a15772196b4b67aed030a4df1d79ebd304c528eb52948f9ea3e64405b608dbd25ddd36f02dea219b24365be7f117c45ecf1a63270c838a6
|
7
|
+
data.tar.gz: edd08dc605fbd6112fecb6def2dcb9f0ad7c08b94db78321fd68c363b19f450f89aae5a81bf42c1cfb9c1eedfbd2ccb9983c2e981c65f8e33947255fe3f9bfb8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# 2.7.0
|
2
|
+
|
3
|
+
* Ignore intermittent template retrieval errors from Slimmer
|
4
|
+
|
5
|
+
# 2.6.0
|
6
|
+
|
7
|
+
* Ignore errors that occur in temporary environments (adds `active_sentry_environments` config) (https://github.com/alphagov/govuk_app_config/pull/168)
|
8
|
+
|
9
|
+
# 2.5.2
|
10
|
+
|
11
|
+
* Fix govuk_app_config in Ruby 2.7 environments by explicitly requiring the 'delegate' library (https://github.com/alphagov/govuk_app_config/pull/167)
|
12
|
+
|
13
|
+
# 2.5.1
|
14
|
+
|
15
|
+
* Increase scope of `data_sync_excluded_exceptions` so that it includes subclasses (https://github.com/alphagov/govuk_app_config/pull/165)
|
16
|
+
|
17
|
+
# 2.5.0
|
18
|
+
|
19
|
+
* Use delegator pattern for `GovukError.configure`, to allow custom `should_capture` (https://github.com/alphagov/govuk_app_config/pull/160)
|
20
|
+
|
1
21
|
# 2.4.1
|
2
22
|
|
3
23
|
* 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
@@ -51,7 +51,7 @@ If you include `govuk_app_config` in your `Gemfile`, Rails' autoloading mechanis
|
|
51
51
|
Your app will have to have the following environment variables set:
|
52
52
|
|
53
53
|
- `SENTRY_DSN` - the [Data Source Name (DSN)][dsn] for Sentry
|
54
|
-
- `SENTRY_CURRENT_ENV` - production
|
54
|
+
- `SENTRY_CURRENT_ENV` - e.g. "production". Make sure it is [configured to be active](#active-sentry-environments).
|
55
55
|
- `GOVUK_STATSD_PREFIX` - a Statsd prefix like `govuk.apps.application-name.hostname`
|
56
56
|
|
57
57
|
[dsn]: https://docs.sentry.io/quickstart/#about-the-dsn
|
@@ -79,6 +79,18 @@ GovukError.notify(
|
|
79
79
|
)
|
80
80
|
```
|
81
81
|
|
82
|
+
### Active Sentry environments
|
83
|
+
|
84
|
+
GovukError will only send errors to Sentry if your `SENTRY_CURRENT_ENV` matches one of the 'active environments' in the [default configuration](https://github.com/alphagov/govuk_app_config/blob/master/lib/govuk_app_config/govuk_error/configure.rb). This is to prevent temporary test environments from flooding our Sentry account with errors.
|
85
|
+
|
86
|
+
You can add your environment to the list of active Sentry environments like so:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
GovukError.configure do |config|
|
90
|
+
config.active_sentry_environments << "my-test-environment"
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
82
94
|
### Error configuration
|
83
95
|
|
84
96
|
You can exclude certain errors from being reported using this:
|
@@ -89,6 +101,27 @@ GovukError.configure do |config|
|
|
89
101
|
end
|
90
102
|
```
|
91
103
|
|
104
|
+
And you can exclude errors from being reported if they occur during the nightly data sync (on integration and staging):
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
GovukError.configure do |config|
|
108
|
+
config.data_sync_excluded_exceptions << "PG::Error"
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
Finally, you can pass your own callback to evaluate whether or not to capture the exception.
|
113
|
+
Note that if an exception is on the `excluded_exceptions` list, or on the `data_sync_excluded_exceptions`
|
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`.
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
GovukError.configure do |config|
|
119
|
+
config.should_capture = lambda do |error_or_event|
|
120
|
+
error_or_event == "do capture"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
92
125
|
`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
126
|
|
94
127
|
## Statsd
|
data/govuk_app_config.gemspec
CHANGED
@@ -25,12 +25,13 @@ 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
|
-
spec.add_development_dependency "rack-test", "~> 1.1
|
30
|
+
spec.add_development_dependency "rack-test", "~> 1.1"
|
30
31
|
spec.add_development_dependency "rails", "~> 6"
|
31
32
|
spec.add_development_dependency "rake", "~> 13.0"
|
32
|
-
spec.add_development_dependency "rspec", "~> 3.
|
33
|
-
spec.add_development_dependency "rspec-its", "~> 1.3
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
34
|
+
spec.add_development_dependency "rspec-its", "~> 1.3"
|
34
35
|
spec.add_development_dependency "rubocop-govuk"
|
35
36
|
spec.add_development_dependency "webmock"
|
36
37
|
end
|
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,55 @@
|
|
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, :sentry_environment
|
7
|
+
attr_accessor :active_sentry_environments, :data_sync_excluded_exceptions
|
8
|
+
|
9
|
+
def initialize(_raven_configuration)
|
10
|
+
super
|
11
|
+
@sentry_environment = ENV["SENTRY_CURRENT_ENV"]
|
12
|
+
@data_sync = GovukDataSync.new(ENV["GOVUK_DATA_SYNC_PERIOD"])
|
13
|
+
self.active_sentry_environments = []
|
14
|
+
self.data_sync_excluded_exceptions = []
|
15
|
+
self.should_capture = ignore_exceptions_based_on_env_and_data_sync
|
16
|
+
end
|
17
|
+
|
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)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
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
|
+
def ignore_exceptions_if_not_in_active_sentry_env
|
36
|
+
->(_error_or_event) { active_sentry_environments.include?(sentry_environment) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def ignore_excluded_exceptions_in_data_sync
|
40
|
+
lambda { |error_or_event|
|
41
|
+
data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore|
|
42
|
+
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)
|
44
|
+
exception_chain.any? { |exception| exception.is_a?(exception_to_ignore) }
|
45
|
+
rescue NameError
|
46
|
+
# the exception type represented by the exception_to_ignore string
|
47
|
+
# doesn't even exist in this environment, so won't be found in the chain
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
!(data_sync.in_progress? && data_sync_ignored_error)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -7,6 +7,16 @@ GovukError.configure do |config|
|
|
7
7
|
|
8
8
|
config.silence_ready = !Rails.env.production? if defined?(Rails)
|
9
9
|
|
10
|
+
# These are the environments (described by the `SENTRY_CURRENT_ENV`
|
11
|
+
# ENV variable) where we want to capture Sentry errors. If
|
12
|
+
# `SENTRY_CURRENT_ENV` isn't in this list, or isn't defined, then
|
13
|
+
# don't capture the error.
|
14
|
+
config.active_sentry_environments = %w[
|
15
|
+
integration-blue-aws
|
16
|
+
staging
|
17
|
+
production
|
18
|
+
]
|
19
|
+
|
10
20
|
config.excluded_exceptions = [
|
11
21
|
# Default ActionDispatch rescue responses
|
12
22
|
"ActionController::RoutingError",
|
@@ -36,6 +46,7 @@ GovukError.configure do |config|
|
|
36
46
|
"GdsApi::TimedOutException",
|
37
47
|
"Mongoid::Errors::DocumentNotFound",
|
38
48
|
"Sinatra::NotFound",
|
49
|
+
"Slimmer::IntermittentRetrievalError",
|
39
50
|
]
|
40
51
|
|
41
52
|
# This will exclude exceptions that are triggered by one of the ignored
|
@@ -43,6 +54,15 @@ GovukError.configure do |config|
|
|
43
54
|
# Rails will raise a ActionView::Template::Error, instead of the original error.
|
44
55
|
config.inspect_exception_causes_for_exclusion = true
|
45
56
|
|
57
|
+
# List of exceptions to ignore if they take place during the data sync.
|
58
|
+
# Some errors are transient in nature, e.g. PostgreSQL databases being
|
59
|
+
# unavailable, and add little value. In fact, their presence can greatly
|
60
|
+
# increase the number of errors being sent and risk genuine errors being
|
61
|
+
# rate-limited by Sentry.
|
62
|
+
config.data_sync_excluded_exceptions = [
|
63
|
+
"PG::Error",
|
64
|
+
]
|
65
|
+
|
46
66
|
config.transport_failure_callback = proc {
|
47
67
|
GovukStatsd.increment("error_reports_failed")
|
48
68
|
}
|
@@ -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
|
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.7.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: 2020-10
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstasher
|
@@ -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
|
@@ -98,14 +112,14 @@ dependencies:
|
|
98
112
|
requirements:
|
99
113
|
- - "~>"
|
100
114
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.1
|
115
|
+
version: '1.1'
|
102
116
|
type: :development
|
103
117
|
prerelease: false
|
104
118
|
version_requirements: !ruby/object:Gem::Requirement
|
105
119
|
requirements:
|
106
120
|
- - "~>"
|
107
121
|
- !ruby/object:Gem::Version
|
108
|
-
version: 1.1
|
122
|
+
version: '1.1'
|
109
123
|
- !ruby/object:Gem::Dependency
|
110
124
|
name: rails
|
111
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,28 +154,28 @@ dependencies:
|
|
140
154
|
requirements:
|
141
155
|
- - "~>"
|
142
156
|
- !ruby/object:Gem::Version
|
143
|
-
version: 3.
|
157
|
+
version: '3.10'
|
144
158
|
type: :development
|
145
159
|
prerelease: false
|
146
160
|
version_requirements: !ruby/object:Gem::Requirement
|
147
161
|
requirements:
|
148
162
|
- - "~>"
|
149
163
|
- !ruby/object:Gem::Version
|
150
|
-
version: 3.
|
164
|
+
version: '3.10'
|
151
165
|
- !ruby/object:Gem::Dependency
|
152
166
|
name: rspec-its
|
153
167
|
requirement: !ruby/object:Gem::Requirement
|
154
168
|
requirements:
|
155
169
|
- - "~>"
|
156
170
|
- !ruby/object:Gem::Version
|
157
|
-
version: 1.3
|
171
|
+
version: '1.3'
|
158
172
|
type: :development
|
159
173
|
prerelease: false
|
160
174
|
version_requirements: !ruby/object:Gem::Requirement
|
161
175
|
requirements:
|
162
176
|
- - "~>"
|
163
177
|
- !ruby/object:Gem::Version
|
164
|
-
version: 1.3
|
178
|
+
version: '1.3'
|
165
179
|
- !ruby/object:Gem::Dependency
|
166
180
|
name: rubocop-govuk
|
167
181
|
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
|