rails_health_checks 0.2.0 → 0.3.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 +4 -4
- data/README.md +6 -1
- data/lib/rails_health_checks/check_registry.rb +6 -1
- data/lib/rails_health_checks/checks/cache_check.rb +21 -0
- data/lib/rails_health_checks/checks/good_job_check.rb +31 -0
- data/lib/rails_health_checks/checks/resque_check.rb +28 -0
- data/lib/rails_health_checks/checks/sidekiq_check.rb +28 -0
- data/lib/rails_health_checks/checks/solid_queue_check.rb +27 -0
- data/lib/rails_health_checks/configuration.rb +6 -1
- data/lib/rails_health_checks/version.rb +1 -1
- data/lib/rails_health_checks.rb +5 -0
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 726057067f5f90f64123fe8aa2772bd94149b111f9bda7b51914fed99233f219
|
|
4
|
+
data.tar.gz: a7baa24da9b0a1b04aa446612a73b062fe3e4ef20ff9b1e8efe7c10e74cab065
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: deb2906855bafc33635d8aeb3432fcced690f41cee05e8f3d7b288eec4908de97458291610dbb4b3c554e03b36ec85519e656fb38d67410517c0d6f056b0e81b
|
|
7
|
+
data.tar.gz: f0e14a473c6f6ad646733a170f0c83232393a776a0e4b5dee124330b428e9402ed780644d97fb800611405636b7c9306599fd7b3ebcc17e8c0a6a86eec23c5aa
|
data/README.md
CHANGED
|
@@ -76,7 +76,7 @@ Status values: `ok` | `degraded` | `critical`. Overall status is `critical` if a
|
|
|
76
76
|
```ruby
|
|
77
77
|
# config/initializers/rails_health_checks.rb
|
|
78
78
|
RailsHealthChecks.configure do |config|
|
|
79
|
-
config.checks = [:database] # checks to run (default: [:database])
|
|
79
|
+
config.checks = [:database, :cache] # checks to run (default: [:database])
|
|
80
80
|
config.timeout = 5 # global timeout per check in seconds (default: 5)
|
|
81
81
|
end
|
|
82
82
|
```
|
|
@@ -126,6 +126,11 @@ The block receives the `ActionDispatch::Request` object and must return a truthy
|
|
|
126
126
|
| Check | Description |
|
|
127
127
|
|-------|-------------|
|
|
128
128
|
| `:database` | ActiveRecord `SELECT 1` against the primary connection, includes latency |
|
|
129
|
+
| `:cache` | `Rails.cache` read/write probe; works with Redis, Memcached, or in-process store |
|
|
130
|
+
| `:sidekiq` | Sidekiq Redis connectivity; optional `config.sidekiq_queue_size` threshold for queue depth |
|
|
131
|
+
| `:solid_queue` | Solid Queue DB connectivity; optional `config.solid_queue_job_count` threshold for pending jobs |
|
|
132
|
+
| `:good_job` | GoodJob queue latency; optional `config.good_job_latency` (seconds) threshold for oldest pending job |
|
|
133
|
+
| `:resque` | Resque Redis connectivity; optional `config.resque_queue_size` threshold for total queue depth |
|
|
129
134
|
|
|
130
135
|
[↑ Back to top](#table-of-contents)
|
|
131
136
|
|
|
@@ -5,7 +5,12 @@ require "timeout"
|
|
|
5
5
|
module RailsHealthChecks
|
|
6
6
|
class CheckRegistry
|
|
7
7
|
BUILT_INS = {
|
|
8
|
-
database: -> { Checks::DatabaseCheck.new }
|
|
8
|
+
database: -> { Checks::DatabaseCheck.new },
|
|
9
|
+
cache: -> { Checks::CacheCheck.new },
|
|
10
|
+
sidekiq: -> { Checks::SidekiqCheck.new(queue_size: RailsHealthChecks.configuration.sidekiq_queue_size) },
|
|
11
|
+
solid_queue: -> { Checks::SolidQueueCheck.new(job_count: RailsHealthChecks.configuration.solid_queue_job_count) },
|
|
12
|
+
good_job: -> { Checks::GoodJobCheck.new(latency: RailsHealthChecks.configuration.good_job_latency) },
|
|
13
|
+
resque: -> { Checks::ResqueCheck.new(queue_size: RailsHealthChecks.configuration.resque_queue_size) }
|
|
9
14
|
}.freeze
|
|
10
15
|
|
|
11
16
|
def self.build(check_names)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsHealthChecks
|
|
4
|
+
module Checks
|
|
5
|
+
class CacheCheck < Check
|
|
6
|
+
PROBE_KEY = "rails_health_checks:cache_probe"
|
|
7
|
+
PROBE_VALUE = "ok"
|
|
8
|
+
|
|
9
|
+
def call
|
|
10
|
+
measure do
|
|
11
|
+
Rails.cache.write(PROBE_KEY, PROBE_VALUE, expires_in: 10)
|
|
12
|
+
result = Rails.cache.read(PROBE_KEY)
|
|
13
|
+
raise "unexpected value: #{result.inspect}" unless result == PROBE_VALUE
|
|
14
|
+
end
|
|
15
|
+
pass
|
|
16
|
+
rescue StandardError => e
|
|
17
|
+
fail_with(e.message)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsHealthChecks
|
|
4
|
+
module Checks
|
|
5
|
+
class GoodJobCheck < Check
|
|
6
|
+
def initialize(latency: nil)
|
|
7
|
+
unless defined?(::GoodJob)
|
|
8
|
+
raise LoadError, "GoodJob is not installed. Add `gem 'good_job'` to your Gemfile to use the :good_job check."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@latency = latency
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
measure do
|
|
16
|
+
oldest = ::GoodJob::Job
|
|
17
|
+
.where(finished_at: nil, performed_at: nil)
|
|
18
|
+
.minimum(:created_at)
|
|
19
|
+
|
|
20
|
+
if @latency && oldest
|
|
21
|
+
age = (Time.current - oldest).to_i
|
|
22
|
+
return warn_with("queue latency #{age}s exceeds threshold #{@latency}s") if age > @latency
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
pass
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
fail_with(e.message)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsHealthChecks
|
|
4
|
+
module Checks
|
|
5
|
+
class ResqueCheck < Check
|
|
6
|
+
def initialize(queue_size: nil)
|
|
7
|
+
unless defined?(::Resque)
|
|
8
|
+
raise LoadError, "Resque is not installed. Add `gem 'resque'` to your Gemfile to use the :resque check."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@queue_size = queue_size
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
measure { ::Resque.redis.ping }
|
|
16
|
+
|
|
17
|
+
if @queue_size
|
|
18
|
+
depth = ::Resque.queues.sum { |q| ::Resque.size(q) }
|
|
19
|
+
return warn_with("queue depth #{depth} exceeds threshold #{@queue_size}") if depth > @queue_size
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
pass
|
|
23
|
+
rescue StandardError => e
|
|
24
|
+
fail_with(e.message)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsHealthChecks
|
|
4
|
+
module Checks
|
|
5
|
+
class SidekiqCheck < Check
|
|
6
|
+
def initialize(queue_size: nil)
|
|
7
|
+
unless defined?(::Sidekiq)
|
|
8
|
+
raise LoadError, "Sidekiq is not installed. Add `gem 'sidekiq'` to your Gemfile to use the :sidekiq check."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@queue_size = queue_size
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
measure { ::Sidekiq.redis { |conn| conn.ping } }
|
|
16
|
+
|
|
17
|
+
if @queue_size
|
|
18
|
+
depth = ::Sidekiq::Queue.all.sum(&:size)
|
|
19
|
+
return warn_with("queue depth #{depth} exceeds threshold #{@queue_size}") if depth > @queue_size
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
pass
|
|
23
|
+
rescue StandardError => e
|
|
24
|
+
fail_with(e.message)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsHealthChecks
|
|
4
|
+
module Checks
|
|
5
|
+
class SolidQueueCheck < Check
|
|
6
|
+
def initialize(job_count: nil)
|
|
7
|
+
unless defined?(::SolidQueue)
|
|
8
|
+
raise LoadError, "SolidQueue is not installed. Add `gem 'solid_queue'` to your Gemfile to use the :solid_queue check."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
@job_count = job_count
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
measure do
|
|
16
|
+
pending = ::SolidQueue::ReadyExecution.count
|
|
17
|
+
if @job_count && pending > @job_count
|
|
18
|
+
return warn_with("pending job count #{pending} exceeds threshold #{@job_count}")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
pass
|
|
22
|
+
rescue StandardError => e
|
|
23
|
+
fail_with(e.message)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module RailsHealthChecks
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_accessor :checks, :timeout, :allowed_ips, :token
|
|
5
|
+
attr_accessor :checks, :timeout, :allowed_ips, :token, :sidekiq_queue_size, :solid_queue_job_count, :good_job_latency,
|
|
6
|
+
:resque_queue_size
|
|
6
7
|
attr_reader :authenticate_block
|
|
7
8
|
|
|
8
9
|
def initialize
|
|
@@ -11,6 +12,10 @@ module RailsHealthChecks
|
|
|
11
12
|
@allowed_ips = nil
|
|
12
13
|
@token = nil
|
|
13
14
|
@authenticate_block = nil
|
|
15
|
+
@sidekiq_queue_size = nil
|
|
16
|
+
@solid_queue_job_count = nil
|
|
17
|
+
@good_job_latency = nil
|
|
18
|
+
@resque_queue_size = nil
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
def authenticate(&block)
|
data/lib/rails_health_checks.rb
CHANGED
|
@@ -6,6 +6,11 @@ require "rails_health_checks/configuration"
|
|
|
6
6
|
require "rails_health_checks/authentication"
|
|
7
7
|
require "rails_health_checks/check"
|
|
8
8
|
require "rails_health_checks/checks/database_check"
|
|
9
|
+
require "rails_health_checks/checks/cache_check"
|
|
10
|
+
require "rails_health_checks/checks/sidekiq_check"
|
|
11
|
+
require "rails_health_checks/checks/solid_queue_check"
|
|
12
|
+
require "rails_health_checks/checks/good_job_check"
|
|
13
|
+
require "rails_health_checks/checks/resque_check"
|
|
9
14
|
require "rails_health_checks/check_registry"
|
|
10
15
|
require "rails_health_checks/response_builder"
|
|
11
16
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_health_checks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chuck Smith
|
|
@@ -44,7 +44,12 @@ files:
|
|
|
44
44
|
- lib/rails_health_checks/authentication.rb
|
|
45
45
|
- lib/rails_health_checks/check.rb
|
|
46
46
|
- lib/rails_health_checks/check_registry.rb
|
|
47
|
+
- lib/rails_health_checks/checks/cache_check.rb
|
|
47
48
|
- lib/rails_health_checks/checks/database_check.rb
|
|
49
|
+
- lib/rails_health_checks/checks/good_job_check.rb
|
|
50
|
+
- lib/rails_health_checks/checks/resque_check.rb
|
|
51
|
+
- lib/rails_health_checks/checks/sidekiq_check.rb
|
|
52
|
+
- lib/rails_health_checks/checks/solid_queue_check.rb
|
|
48
53
|
- lib/rails_health_checks/configuration.rb
|
|
49
54
|
- lib/rails_health_checks/engine.rb
|
|
50
55
|
- lib/rails_health_checks/response_builder.rb
|