rails_health_checks 1.2.0 → 1.2.1
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/Rakefile +6 -1
- data/lib/rails_health_checks/check_registry.rb +34 -8
- data/lib/rails_health_checks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9bff80f924f018abcc0f67cf61568e29e7aff6e25c9e9c227aaa830290209918
|
|
4
|
+
data.tar.gz: 065ee72ad6e12c56d5dc4d6bd1e527e35a7e546a7c85cacbd5dedc13ecf64e9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a362e27a106bd832c43c2c9a79989e38f26eeb7ce5c1027e2877a3e99ac0ca6f95dca653874bf9ec70edad261a68214e502d930c99f29238c67a2c4d755141c
|
|
7
|
+
data.tar.gz: 4367170dcd946c7f5e20c056f3596cad8a2a01c187aa67ebf582ae38d39c4e55c977b0f45ec1fb002bdafa9cbbbecb8aad32f7a4a7b005d9aa0e209cd98333ba
|
data/Rakefile
CHANGED
|
@@ -11,7 +11,12 @@ RuboCop::RakeTask.new(:lint)
|
|
|
11
11
|
Bundler::Audit::Task.new
|
|
12
12
|
RSpec::Core::RakeTask.new(:spec)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
desc "Run Brakeman static security analysis"
|
|
15
|
+
task :brakeman do
|
|
16
|
+
sh "bundle exec brakeman -q --no-pager --force-scan --skip-files spec/ ."
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
task default: [:lint, :'bundle:audit:update', 'bundle:audit:check', :brakeman, :spec]
|
|
15
20
|
|
|
16
21
|
desc "Run performance benchmarks"
|
|
17
22
|
task :benchmark do
|
|
@@ -51,9 +51,11 @@ module RailsHealthChecks
|
|
|
51
51
|
t = check.timeout || timeout
|
|
52
52
|
Concurrent::Future.execute { run_check(check, timeout: t) }
|
|
53
53
|
end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
permit_concurrent_loads do
|
|
55
|
+
checks.each do |name, check|
|
|
56
|
+
t = check.timeout || timeout
|
|
57
|
+
results[name] = futures[name].value(t + 1) || mark_critical(check, "timed out")
|
|
58
|
+
end
|
|
57
59
|
end
|
|
58
60
|
if payload
|
|
59
61
|
payload[:status] = overall_status(results)
|
|
@@ -69,21 +71,45 @@ module RailsHealthChecks
|
|
|
69
71
|
if defined?(ActiveSupport::Notifications)
|
|
70
72
|
ActiveSupport::Notifications.instrument("health_check.rails_health_checks", &block)
|
|
71
73
|
else
|
|
72
|
-
# :
|
|
74
|
+
# simplecov:disable
|
|
73
75
|
yield nil
|
|
74
|
-
# :
|
|
76
|
+
# simplecov:enable
|
|
75
77
|
end
|
|
76
78
|
end
|
|
77
79
|
|
|
78
80
|
def self.run_check(check, timeout:)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
with_executor do
|
|
82
|
+
Timeout.timeout(timeout) { check.call }
|
|
83
|
+
check
|
|
84
|
+
end
|
|
81
85
|
rescue Timeout::Error
|
|
82
86
|
mark_critical(check, "timed out")
|
|
83
87
|
rescue StandardError => e
|
|
84
88
|
mark_critical(check, e.message)
|
|
85
89
|
end
|
|
86
90
|
|
|
91
|
+
# Checks run on Concurrent's global pool, outside the request thread. Wrapping
|
|
92
|
+
# each one in the Rails executor returns any Active Record connections it
|
|
93
|
+
# leased (primary, cache, queue, ...) when the check finishes, including on
|
|
94
|
+
# timeout; otherwise they stay checked out by the long-lived pool thread.
|
|
95
|
+
def self.with_executor(&block)
|
|
96
|
+
if defined?(Rails) && Rails.application
|
|
97
|
+
Rails.application.executor.wrap(&block)
|
|
98
|
+
else
|
|
99
|
+
yield
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# In development the request thread holds the autoload interlock while it
|
|
104
|
+
# waits on the futures; the check threads need it to load code, so let them.
|
|
105
|
+
def self.permit_concurrent_loads(&block)
|
|
106
|
+
if defined?(ActiveSupport::Dependencies) && ActiveSupport::Dependencies.respond_to?(:interlock)
|
|
107
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads(&block)
|
|
108
|
+
else
|
|
109
|
+
yield
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
87
113
|
def self.mark_critical(check, message)
|
|
88
114
|
check.instance_variable_set(:@status, "critical")
|
|
89
115
|
check.instance_variable_set(:@message, message)
|
|
@@ -98,6 +124,6 @@ module RailsHealthChecks
|
|
|
98
124
|
end
|
|
99
125
|
end
|
|
100
126
|
|
|
101
|
-
private_class_method :run_check, :mark_critical, :overall_status, :instrument
|
|
127
|
+
private_class_method :run_check, :with_executor, :permit_concurrent_loads, :mark_critical, :overall_status, :instrument
|
|
102
128
|
end
|
|
103
129
|
end
|