govuk_app_config 1.4.2 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97c53dced58ec8966b00eafd00aca2ce042ff3537b6d7beb5ef26d3ba7b32d42
4
- data.tar.gz: c2828b3c76b1a9fd81afd7d5c939eaa5ccf31e4c95c457d3317a1f28714a4546
3
+ metadata.gz: 9fc8eb993da7f05c65a86ed611ecca3d47a61c5966482d24f657d2b0799ccfe4
4
+ data.tar.gz: 2e70812a60e8af9649df62acd3c6e2c4db5f011bab737b53f12241afe4670bf0
5
5
  SHA512:
6
- metadata.gz: 7a52a2c462bfe26d9b5db5dacab7ba4407d73b7580f68412412929fa16275222a7ff151fca08912628bdc825cf2a55b24c045c97c1b38cd90a8a2cd33d6c70bd
7
- data.tar.gz: ad5613de6d8d9ba992c6dc432467250cb3db36cecd847b7713716fbaf5313f1bdf625502cf920add7e829853a11830409b6ff387cee00072feb88fedcc9b1f43
6
+ metadata.gz: 4394c0661fad4cf1bf067d3b1a2cf50fa37f93112b2fec97b153e39f040ab10834c47b48056cdb2dc071e64cee182f1183ef095f55292b1998b10db450ae285e
7
+ data.tar.gz: 634551494d9d5691cdd524731e41d94bc3ccbb8b2de218f73acbaca97755a01e0efc7710686a8ae6ec48d3115e3fd849e3b33f9cc1a6221f3a3c2f8f1e7a7c5d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.5.0
2
+
3
+ * Add healthcheck support. See README.md for usage information.
4
+
1
5
  # 1.4.2
2
6
 
3
7
  * Ignore `ActionController::UnknownHttpMethod` errors.
data/README.md CHANGED
@@ -47,12 +47,6 @@ $ bundle exec unicorn -c config/unicorn.rb
47
47
 
48
48
  If you include `govuk_app_config` in your `Gemfile`, Rails' autoloading mechanism will make sure that your application is configured to send errors to Sentry.
49
49
 
50
- If you use the gem outside of Rails you'll have to explicitly require it:
51
-
52
- ```rb
53
- require "govuk_app_config"
54
- ```
55
-
56
50
  Your app will have to have the following environment variables set:
57
51
 
58
52
  - `SENTRY_DSN` - the [Data Source Name (DSN)][dsn] for Sentry
@@ -111,6 +105,51 @@ GovukStatsd.gauge "bork", 100
111
105
  GovukStatsd.time("account.activate") { @account.activate! }
112
106
  ```
113
107
 
108
+ ## Healthchecks
109
+
110
+ Set up a route in your rack-compatible Ruby application, and pick the built-in
111
+ or custom checks you wish to perform.
112
+
113
+ Custom checks must be any class or instance which implements
114
+ [this interface](spec/lib/govuk_healthcheck/shared_interface.rb):
115
+ ```ruby
116
+ module CustomCheck
117
+ def self.name
118
+ :custom_check
119
+ end
120
+
121
+ def self.status
122
+ ThingChecker.everything_okay? ? OK : CRITICAL
123
+ end
124
+
125
+ # Optional
126
+ def self.message
127
+ "This is an optional custom message"
128
+ end
129
+
130
+ # Optional
131
+ def self.details
132
+ {
133
+ extra: "This is an optional details hash",
134
+ }
135
+ end
136
+ end
137
+ ```
138
+
139
+ For Rails apps:
140
+ ```ruby
141
+ get "/healthcheck", to: GovukHealthcheck.rack_response(
142
+ GovukHealthcheck::SidekiqRedis,
143
+ GovukHealthcheck::ActiveRecord,
144
+ CustomCheck,
145
+ )
146
+ ```
147
+
148
+ This will check:
149
+ - Redis connectivity (via Sidekiq)
150
+ - Database connectivity (via ActiveRecord)
151
+ - Your custom healthcheck
152
+
114
153
  ## Rails logging
115
154
 
116
155
  In Rails applications, the application will be configured to send JSON-formatted
@@ -2,6 +2,7 @@ require "govuk_app_config/version"
2
2
  require "govuk_app_config/govuk_statsd"
3
3
  require "govuk_app_config/govuk_error"
4
4
  require "govuk_app_config/govuk_logging"
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"
@@ -0,0 +1,14 @@
1
+ require "govuk_app_config/govuk_healthcheck/checkup"
2
+ require "govuk_app_config/govuk_healthcheck/active_record"
3
+ require "govuk_app_config/govuk_healthcheck/sidekiq_redis"
4
+ require "json"
5
+
6
+ module GovukHealthcheck
7
+ def self.rack_response(*checks)
8
+ proc { [200, {}, [JSON.dump(healthcheck(checks))]] }
9
+ end
10
+
11
+ def self.healthcheck(checks)
12
+ Checkup.new(checks).run
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module GovukHealthcheck
2
+ module ActiveRecord
3
+ def self.name
4
+ :database_connectivity
5
+ end
6
+
7
+ def self.status
8
+ ::ActiveRecord::Base.connected? ? OK : CRITICAL
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ module GovukHealthcheck
2
+ STATUSES = [
3
+ OK = "ok".freeze,
4
+ WARNING = "warning".freeze,
5
+ CRITICAL = "critical".freeze,
6
+ ].freeze
7
+
8
+ class Checkup
9
+ # @param checks [Array] Array of objects/classes that respond to `run`
10
+ def initialize(checks)
11
+ @checks = checks
12
+ end
13
+
14
+ def run
15
+ {
16
+ status: worst_status,
17
+ checks: component_statuses,
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def component_statuses
24
+ @component_statuses ||= @checks.each_with_object({}) do |check, hash|
25
+ hash[check.name] = build_component_status(check)
26
+ end
27
+ end
28
+
29
+ def worst_status
30
+ if status?(CRITICAL)
31
+ CRITICAL
32
+ elsif status?(WARNING)
33
+ WARNING
34
+ else
35
+ OK
36
+ end
37
+ end
38
+
39
+ def status?(status)
40
+ component_statuses.values.any? {|s| s[:status] == status }
41
+ end
42
+
43
+ def build_component_status(check)
44
+ component_status = details(check).merge(status: check.status)
45
+ component_status[:message] = check.message if check.respond_to?(:message)
46
+ component_status
47
+ end
48
+
49
+ def details(check)
50
+ check.respond_to?(:details) ? check.details : {}
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ module GovukHealthcheck
2
+ module SidekiqRedis
3
+ def self.name
4
+ :redis_connectivity
5
+ end
6
+
7
+ def self.status
8
+ Sidekiq.redis_info ? OK : CRITICAL
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  require 'logstasher'
3
2
 
4
3
  module GovukLogging
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "1.4.2"
2
+ VERSION = "1.5.0"
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: 1.4.2
4
+ version: 1.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: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: statsd-ruby
@@ -158,6 +158,10 @@ files:
158
158
  - lib/govuk_app_config.rb
159
159
  - lib/govuk_app_config/configure.rb
160
160
  - lib/govuk_app_config/govuk_error.rb
161
+ - lib/govuk_app_config/govuk_healthcheck.rb
162
+ - lib/govuk_app_config/govuk_healthcheck/active_record.rb
163
+ - lib/govuk_app_config/govuk_healthcheck/checkup.rb
164
+ - lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
161
165
  - lib/govuk_app_config/govuk_logging.rb
162
166
  - lib/govuk_app_config/govuk_statsd.rb
163
167
  - lib/govuk_app_config/govuk_unicorn.rb
@@ -183,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
187
  version: '0'
184
188
  requirements: []
185
189
  rubyforge_project:
186
- rubygems_version: 2.7.3
190
+ rubygems_version: 2.7.6
187
191
  signing_key:
188
192
  specification_version: 4
189
193
  summary: Base configuration for GOV.UK applications