health-monitor-rails 10.1.0 → 11.0.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: f31145948d53277b016035e3dd3b1580ccc47afc452f2a9a197141c3c96b21ad
4
- data.tar.gz: 80f759c330d6086287abd668c6c9bf5c9666092a3ac2d8ac2f0a8439981a36ff
3
+ metadata.gz: ebb626c2a794dc6f2b1a0e657fb126179155ad88ec12b8d67bb356519517204d
4
+ data.tar.gz: 45beac4910b662ca499ce4017a53a0bf5671b6b5791a11fa357b432c31ee130e
5
5
  SHA512:
6
- metadata.gz: c3b4d89aa49a1d799f23ec6e98bf718a584e8c7954e1c4544d61159f0ed012609bb8eb213714cf987f52a537dd00c14bfbce6b92fa8f5f7e64b50fdf1f94310f
7
- data.tar.gz: 6e1f95ccc047a279d7cb8658a3186de8b20ae62260ea9832beec3ca7a944522b1a91171ee3aa9c4d9ddc672f964d8c55f2f8005a036d0423281d42dc038d34a0
6
+ metadata.gz: 368decd1adde6046ec5561573afe27f1423bde4a37ed8c4dee7a99a93bcbde1f2752ff1370ff09f1a807815ebe012f73b514a44ba23231ac5442e99b9d885869
7
+ data.tar.gz: 4d413a6fdce8c28ce49279867f39ca208274f1c6a226c7ae68a1b2b2b4c80f8ed7dd7a7331be30bae2f7eac0eff81f8e2298cfc76b44b61aa205df789b667c28
data/README.md CHANGED
@@ -203,6 +203,22 @@ end
203
203
 
204
204
  ### Provider Configuration
205
205
 
206
+ All providers accept a general set of baseline configuration:
207
+
208
+ ```ruby
209
+ HealthMonitor.configure do |config|
210
+ config.[provider].configure do |provider_config|
211
+ provider_config.name = 'Redis'
212
+ provider_config.critical = true
213
+ end
214
+ end
215
+ ```
216
+
217
+ * __name__: Custom name for the provider (Defaults to __class name__. Ex: 'Redis', 'Sidekiq')
218
+ * __critical__: Whether or not the provider is a critical dependency (Defaults to: __true__). If set to __false__, the monitor will report its status but ignore it when determining overall application health status
219
+
220
+ > The __critical__ option allows you to monitor for additional non-critical dependencies that are not fully required for your application to be operational, like a cache database for instance
221
+
206
222
  Some of the providers can also accept additional configuration:
207
223
 
208
224
  ```ruby
@@ -256,6 +272,25 @@ HealthMonitor.configure do |config|
256
272
  end
257
273
  ```
258
274
 
275
+ For providers that can be configured with its endpoits/urls you can also add multiple declarations to ensure you are reporting across all dependencies:
276
+
277
+ ```ruby
278
+ HealthMonitor.configure do |config|
279
+ config.redis.configure do |c|
280
+ c.name = 'Redis: Cache'
281
+ c.url = ENV.fetch('REDISCLOUD_URL', 'redis://localhost:6379/0')
282
+ end
283
+ config.redis.configure do |c|
284
+ c.name = 'Redis: Action Cable'
285
+ c.url = ENV.fetch('REDISCLOUD_URL', 'redis://localhost:6379/0')
286
+ end
287
+ config.redis.configure do |c|
288
+ c.name = 'Redis: Sidekiq'
289
+ c.url = ENV.fetch('REDISCLOUD_URL', 'redis://localhost:6379/1')
290
+ end
291
+ end
292
+ ```
293
+
259
294
  The currently supported settings are:
260
295
 
261
296
  #### Sidekiq
@@ -16,8 +16,8 @@ module HealthMonitor
16
16
 
17
17
  respond_to do |format|
18
18
  format.html
19
- format.json { render json: statuses.to_json, status: statuses[:status] }
20
- format.xml { render xml: statuses.to_xml, status: statuses[:status] }
19
+ format.json { render json: @statuses.to_json, status: @statuses[:status] }
20
+ format.xml { render xml: @statuses.to_xml, status: @statuses[:status] }
21
21
  end
22
22
  end
23
23
 
@@ -16,7 +16,7 @@ module HealthMonitor
16
16
  end
17
17
 
18
18
  def no_database
19
- @providers.delete(HealthMonitor::Providers::Database)
19
+ @providers.shift
20
20
  end
21
21
 
22
22
  PROVIDERS.each do |provider_name|
@@ -25,7 +25,7 @@ module HealthMonitor
25
25
 
26
26
  add_provider(
27
27
  "HealthMonitor::Providers::#{provider_name.to_s.titleize.delete(' ')}"
28
- .constantize
28
+ .constantize.new
29
29
  )
30
30
  end
31
31
  end
@@ -40,10 +40,10 @@ module HealthMonitor
40
40
 
41
41
  private
42
42
 
43
- def add_provider(provider_class)
44
- (@providers ||= Set.new) << provider_class
43
+ def add_provider(provider)
44
+ (@providers ||= []) << provider
45
45
 
46
- provider_class
46
+ provider
47
47
  end
48
48
  end
49
49
  end
@@ -21,14 +21,14 @@ module HealthMonitor
21
21
  def check(request: nil, params: {})
22
22
  providers = configuration.providers
23
23
  if params[:providers].present?
24
- providers = providers.select { |provider| params[:providers].include?(provider.provider_name.downcase) }
24
+ providers = providers.select { |provider| params[:providers].include?(provider.name.downcase) }
25
25
  end
26
26
 
27
27
  results = providers.map { |provider| provider_result(provider, request) }
28
28
 
29
29
  {
30
- results: results,
31
- status: results.any? { |res| res[:status] != STATUSES[:ok] } ? :service_unavailable : :ok,
30
+ results: results.map { |c| c.without(:critical) },
31
+ status: results.any? { |res| res[:status] != STATUSES[:ok] && res[:critical] } ? :service_unavailable : :ok,
32
32
  timestamp: Time.now.to_formatted_s(:rfc2822)
33
33
  }
34
34
  end
@@ -36,21 +36,24 @@ module HealthMonitor
36
36
  private
37
37
 
38
38
  def provider_result(provider, request)
39
- monitor = provider.new(request: request)
39
+ monitor = provider
40
+ monitor.request = request
40
41
  monitor.check!
41
42
 
42
43
  {
43
- name: provider.provider_name,
44
+ name: provider.name,
44
45
  message: '',
45
- status: STATUSES[:ok]
46
+ status: STATUSES[:ok],
47
+ critical: provider.critical
46
48
  }
47
49
  rescue StandardError => e
48
50
  configuration.error_callback.try(:call, e)
49
51
 
50
52
  {
51
- name: provider.provider_name,
53
+ name: provider.name,
52
54
  message: e.message,
53
- status: STATUSES[:error]
55
+ status: STATUSES[:error],
56
+ critical: provider.critical
54
57
  }
55
58
  end
56
59
  end
@@ -1,35 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'forwardable'
4
+
3
5
  module HealthMonitor
4
6
  module Providers
5
7
  class Base
6
- @global_configuration = nil
7
-
8
- attr_reader :request
9
- attr_accessor :configuration
8
+ extend Forwardable
10
9
 
11
- def self.provider_name
12
- @provider_name ||= name.demodulize
13
- end
10
+ class Configuration
11
+ attr_accessor :name, :critical
14
12
 
15
- def self.global_configuration
16
- @global_configuration ||= configuration_class.new
13
+ def initialize(provider)
14
+ @name = provider.class.name.demodulize
15
+ @critical = true
16
+ end
17
17
  end
18
18
 
19
- def self.configure
20
- return unless configurable?
19
+ attr_accessor :request
20
+ attr_reader :configuration
21
21
 
22
- @global_configuration ||= configuration_class.new
22
+ def_delegators :@configuration, :name, :critical
23
23
 
24
- yield @global_configuration if block_given?
24
+ def initialize
25
+ @configuration = configuration_class.new(self)
25
26
  end
26
27
 
27
- def initialize(request: nil)
28
- @request = request
29
-
30
- return unless self.class.configurable?
31
-
32
- self.configuration = self.class.global_configuration
28
+ def configure
29
+ yield @configuration if block_given?
33
30
  end
34
31
 
35
32
  # @abstract
@@ -37,12 +34,11 @@ module HealthMonitor
37
34
  raise NotImplementedError
38
35
  end
39
36
 
40
- def self.configurable?
41
- configuration_class
42
- end
37
+ private
43
38
 
44
- # @abstract
45
- def self.configuration_class; end
39
+ def configuration_class
40
+ Configuration
41
+ end
46
42
  end
47
43
  end
48
44
  end
@@ -8,12 +8,14 @@ module HealthMonitor
8
8
  class DelayedJobException < StandardError; end
9
9
 
10
10
  class DelayedJob < Base
11
- class Configuration
11
+ class Configuration < Base::Configuration
12
12
  DEFAULT_QUEUES_SIZE = 100
13
13
 
14
14
  attr_accessor :queue_size
15
15
 
16
- def initialize
16
+ def initialize(provider)
17
+ super(provider)
18
+
17
19
  @queue_size = DEFAULT_QUEUES_SIZE
18
20
  end
19
21
  end
@@ -24,16 +26,6 @@ module HealthMonitor
24
26
  raise DelayedJobException.new(e.message)
25
27
  end
26
28
 
27
- private
28
-
29
- class << self
30
- private
31
-
32
- def configuration_class
33
- ::HealthMonitor::Providers::DelayedJob::Configuration
34
- end
35
- end
36
-
37
29
  def check_queue_size!
38
30
  size = job_class.count
39
31
 
@@ -45,6 +37,12 @@ module HealthMonitor
45
37
  def job_class
46
38
  @job_class ||= ::Delayed::Job
47
39
  end
40
+
41
+ private
42
+
43
+ def configuration_class
44
+ ::HealthMonitor::Providers::DelayedJob::Configuration
45
+ end
48
46
  end
49
47
  end
50
48
  end
@@ -9,12 +9,14 @@ module HealthMonitor
9
9
  class RedisException < StandardError; end
10
10
 
11
11
  class Redis < Base
12
- class Configuration
12
+ class Configuration < Base::Configuration
13
13
  DEFAULT_URL = nil
14
14
 
15
15
  attr_accessor :url, :connection, :max_used_memory
16
16
 
17
- def initialize
17
+ def initialize(provider)
18
+ super(provider)
19
+
18
20
  @url = DEFAULT_URL
19
21
  end
20
22
  end
@@ -22,10 +24,6 @@ module HealthMonitor
22
24
  class << self
23
25
  private
24
26
 
25
- def configuration_class
26
- ::HealthMonitor::Providers::Redis::Configuration
27
- end
28
-
29
27
  def as_connection_pool(connection)
30
28
  ConnectionPool.new(size: CONNECTION_POOL_SIZE) { connection }
31
29
  end
@@ -40,6 +38,10 @@ module HealthMonitor
40
38
 
41
39
  private
42
40
 
41
+ def configuration_class
42
+ ::HealthMonitor::Providers::Redis::Configuration
43
+ end
44
+
43
45
  def check_values!
44
46
  time = Time.now.to_formatted_s(:rfc2822)
45
47
 
@@ -8,7 +8,7 @@ module HealthMonitor
8
8
  class SidekiqException < StandardError; end
9
9
 
10
10
  class Sidekiq < Base
11
- class Configuration
11
+ class Configuration < Base::Configuration
12
12
  DEFAULT_QUEUE_NAME = 'default'
13
13
  DEFAULT_LATENCY_TIMEOUT = 30
14
14
  DEFAULT_QUEUES_SIZE = 100
@@ -16,7 +16,9 @@ module HealthMonitor
16
16
 
17
17
  attr_reader :queues
18
18
 
19
- def initialize
19
+ def initialize(provider)
20
+ super(provider)
21
+
20
22
  @queues = {}
21
23
  @queues[DEFAULT_QUEUE_NAME] = { latency: DEFAULT_LATENCY_TIMEOUT, queue_size: DEFAULT_QUEUES_SIZE }
22
24
  end
@@ -61,12 +63,8 @@ module HealthMonitor
61
63
 
62
64
  private
63
65
 
64
- class << self
65
- private
66
-
67
- def configuration_class
68
- ::HealthMonitor::Providers::Sidekiq::Configuration
69
- end
66
+ def configuration_class
67
+ ::HealthMonitor::Providers::Sidekiq::Configuration
70
68
  end
71
69
 
72
70
  def check_workers!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '10.1.0'
4
+ VERSION = '11.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health-monitor-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.1.0
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Beder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-16 00:00:00.000000000 Z
11
+ date: 2023-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,258 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.1'
27
- - !ruby/object:Gem::Dependency
28
- name: appraisal
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: capybara
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: capybara-screenshot
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: coveralls_reborn
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: database_cleaner
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: delayed_job_active_record
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '4.1'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '4.1'
111
- - !ruby/object:Gem::Dependency
112
- name: mock_redis
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: pry
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rake
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: resque
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rspec-rails
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: rubocop-rake
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: rubocop-rspec
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: sidekiq
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- version: '3.0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- version: '3.0'
237
- - !ruby/object:Gem::Dependency
238
- name: spork
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - ">="
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '0'
251
- - !ruby/object:Gem::Dependency
252
- name: sqlite3
253
- requirement: !ruby/object:Gem::Requirement
254
- requirements:
255
- - - ">="
256
- - !ruby/object:Gem::Version
257
- version: '1.3'
258
- type: :development
259
- prerelease: false
260
- version_requirements: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - ">="
263
- - !ruby/object:Gem::Version
264
- version: '1.3'
265
- - !ruby/object:Gem::Dependency
266
- name: timecop
267
- requirement: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - ">="
270
- - !ruby/object:Gem::Version
271
- version: '0'
272
- type: :development
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - ">="
277
- - !ruby/object:Gem::Version
278
- version: '0'
279
27
  description: Health monitoring Rails plug-in, which checks various services (db, cache,
280
28
  sidekiq, redis, etc.).
281
29
  email: