govuk_app_config 2.2.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: 11f06b82c25ddd23f985b025b26abdcce2a1c4ab772cdbf129907962d8297da8
4
- data.tar.gz: aa6e55ea958fd54cf9eb833762cbf3dfc24d310af1e3bf6dd8a010f3ad4d9bc9
3
+ metadata.gz: dbd89ce53c62443a1bf91f7c782fc121a493323b8f55f77db131e9fab17bc78b
4
+ data.tar.gz: cc5435d8e5a2769c688afa0f37869ec96bc58311b2c7e5051e0dbe226496f50c
5
5
  SHA512:
6
- metadata.gz: c5f01c3eb3f450616bc04577f788a36a4907d690d5694f9e813c89c985b370ad2b94abc53653a3a98885fed96799d7f34085e2e478d545ee15ac9421e846800d
7
- data.tar.gz: cbe282314f027a01ed6fd1aae0e490b67b0fcb8425dc802dc7311bab8d97dea60f531b30302879fbe4a11d01f95bd61edda203dda1539c01831ec089d71db278
6
+ metadata.gz: 8c9a936938fdb3795e3edd0fdf9f43a368a5130f034d30150bdd4201c5490a47b015b492a1275d8dba4668ec9e44b32b4a8692fa4cddf7bb59eee9242f468e23
7
+ data.tar.gz: ad4e17d9b55e828c4542517a427ba6f35152583fe536f87801a7d2567cff00a0bc6d036103cc29186fab381b61b904b1a7eaa63c0a088a0b55c2735371ea39e1
@@ -1,3 +1,23 @@
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
+
5
+ # 2.4.1
6
+
7
+ * Bump 'sentry-raven' to 3.1.1 to improve grouping of errors (https://github.com/alphagov/govuk_app_config/pull/162)
8
+
9
+ # 2.4.0
10
+
11
+ * Add new GovukHealthcheck::Mongoid and GovukHealthcheck::RailsCache health checks (https://github.com/alphagov/govuk_app_config/pull/161)
12
+
13
+ # 2.3.0
14
+
15
+ * Remove unused SidekiqQueueSizeCheck healthcheck base class (https://github.com/alphagov/govuk_app_config/pull/156)
16
+
17
+ # 2.2.2
18
+
19
+ * Add www.googletagmanager.com and www.gstatic.com to Content Security Policy (https://github.com/alphagov/govuk_app_config/pull/153)
20
+
1
21
  # 2.2.1
2
22
 
3
23
  * Fix linting issues (https://github.com/alphagov/govuk_app_config/pull/149)
@@ -250,7 +270,7 @@
250
270
  * Add Unicorn (our web server) as a dependency
251
271
  * Use version [2.7.0 of the Sentry client][sentry-270].
252
272
  * Set up logging configuration for Rails applications.
253
- * Don't send `ActionController::BadRequest`to Sentry
273
+ * Don't send `ActionController::BadRequest` to Sentry
254
274
 
255
275
  [sentry-270]: https://github.com/getsentry/raven-ruby/commit/ef623824cb0a8a2f60be5fb7e12f80454da54fd7
256
276
 
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
@@ -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
@@ -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", ">= 2.7.1", "< 3.1.0"
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.6"
26
+ spec.add_dependency "unicorn", ">= 5.4", "< 5.8"
27
27
 
28
- spec.add_development_dependency "bundler", "~> 1.15"
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"
@@ -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"
@@ -17,7 +17,10 @@ module GovukContentSecurityPolicy
17
17
 
18
18
  GOOGLE_ANALYTICS_DOMAINS = %w[www.google-analytics.com
19
19
  ssl.google-analytics.com
20
- stats.g.doubleclick.net].freeze
20
+ stats.g.doubleclick.net
21
+ www.googletagmanager.com].freeze
22
+
23
+ GOOGLE_STATIC_DOMAINS = %w[www.gstatic.com].freeze
21
24
 
22
25
  def self.build_policy(policy)
23
26
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
@@ -35,6 +38,7 @@ module GovukContentSecurityPolicy
35
38
  policy.script_src :self,
36
39
  *GOVUK_DOMAINS,
37
40
  *GOOGLE_ANALYTICS_DOMAINS,
41
+ *GOOGLE_STATIC_DOMAINS,
38
42
  # Allow JSONP call to Verify to check whether the user is logged in
39
43
  "www.signin.service.gov.uk",
40
44
  # Allow YouTube Embeds (Govspeak turns YouTube links into embeds)
@@ -51,6 +55,7 @@ module GovukContentSecurityPolicy
51
55
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
52
56
  policy.style_src :self,
53
57
  *GOVUK_DOMAINS,
58
+ *GOOGLE_STATIC_DOMAINS,
54
59
  # We use the `style=""` attribute on some HTML elements
55
60
  :unsafe_inline
56
61
 
@@ -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,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,14 @@
1
+ module GovukHealthcheck
2
+ class Mongoid
3
+ def name
4
+ :database_connectivity
5
+ end
6
+
7
+ def status
8
+ ::Mongoid.default_client.database_names.any?
9
+ GovukHealthcheck::OK
10
+ rescue StandardError
11
+ GovukHealthcheck::CRITICAL
12
+ end
13
+ end
14
+ end
@@ -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
@@ -27,7 +27,7 @@ module GovukLogging
27
27
 
28
28
  def self.monkey_patch_log_error(clazz = ::ActionDispatch::DebugExceptions)
29
29
  clazz.class_eval do
30
- private
30
+ private
31
31
 
32
32
  def log_error(request, wrapper)
33
33
  logger = logger(request)
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "2.2.1".freeze
2
+ VERSION = "2.5.0".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.2.1
4
+ version: 2.5.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-07-20 00:00:00.000000000 Z
11
+ date: 2020-10-20 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.0
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.0
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.6'
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.6'
80
+ version: '5.8'
87
81
  - !ruby/object:Gem::Dependency
88
- name: bundler
82
+ name: byebug
89
83
  requirement: !ruby/object:Gem::Requirement
90
84
  requirements:
91
- - - "~>"
85
+ - - ">="
92
86
  - !ruby/object:Gem::Version
93
- version: '1.15'
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: '1.15'
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.0.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
@@ -1,11 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqQueueSizeCheck < SidekiqQueueCheck
3
- def name
4
- :sidekiq_queue_size
5
- end
6
-
7
- def queues
8
- @queues ||= Sidekiq::Stats.new.queues
9
- end
10
- end
11
- end