health-monitor-rails 12.5.0 → 12.7.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: c16cdc04971eb81463bb19da409b3e1d41cf83683840819882ad33a6d8cdf4b0
4
- data.tar.gz: 8091013b1770de119a9d9448696f97c3ec7baadafac9ce4173d6c279b65bc313
3
+ metadata.gz: 65ddef8cba3d98c9824273f2eb677bb4eb5797a88ea3a020d846ab9e7b170bf9
4
+ data.tar.gz: 30b1ff30cdc3c8c95a180701b251756514cacc4f8a6969c07dc07b21fddb538c
5
5
  SHA512:
6
- metadata.gz: 2d6f3818a0dabb60c514382d32815832e94f516ccd3d76751acf90889b61e90edfcfd62b4df44e34669909ed475e2c25585b4c08b5ebc0cfebea33f8f8c965a4
7
- data.tar.gz: 7f519417d7e0adee2f367f776c0d193bc44b0cb8dd48661d5e0067171618efced5e0834ba26a66b51e6b0335a9c8ee81f4d483e1d01ae51a3951a4f872200d36
6
+ metadata.gz: bdba690258230630638d475e00cad004127a086cf548460504864038ec1e02eeb434e083cf49e7c23ab00f08ef764e7bacee01a1beaec16d01c1486854ee6a76
7
+ data.tar.gz: ca61f98fca9a3adc8b89c47748d82ce7a9523842b807d757171474e73f13721d2db6085f65813b3be2829b7f1b3ff3a176020727eae4d11f5392e5e2b4b1314d
data/README.md CHANGED
@@ -202,6 +202,21 @@ HealthMonitor.configure do |config|
202
202
  end
203
203
  ```
204
204
 
205
+ When you have multiple databases and and want to check each configuration separately you can use following method:
206
+ ```ruby
207
+ HealthMonitor.configure do |config|
208
+ config.no_database # Disable default all databases check
209
+ config.database.configure do |provider_config|
210
+ provider_config.config_name = 'primary'
211
+ end
212
+ config.database.configure do |provider_config|
213
+ provider_config.name = 'Secondary'
214
+ provider_config.config_name = 'secondary'
215
+ provider_config.critical = false
216
+ end
217
+ end
218
+ ```
219
+
205
220
  ### Provider Configuration
206
221
 
207
222
  All providers accept a general set of baseline configuration:
@@ -216,7 +231,7 @@ end
216
231
  ```
217
232
 
218
233
  * __name__: Custom name for the provider (Defaults to __class name__. Ex: 'Redis', 'Sidekiq')
219
- * __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
234
+ * __critical__: Whether or not the provider is a critical dependency (Defaults to: __true__). If set to __false__, the monitor will report its status as `WARNING` but ignore it when determining overall application health status. This could be used to send to a non critical notifications channel
220
235
 
221
236
  > 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
222
237
 
@@ -273,7 +288,7 @@ HealthMonitor.configure do |config|
273
288
  end
274
289
  ```
275
290
 
276
- For providers that can be configured with its endpoits/urls you can also add multiple declarations to ensure you are reporting across all dependencies:
291
+ For providers that can be configured with its endpoints/urls you can also add multiple declarations to ensure you are reporting across all dependencies:
277
292
 
278
293
  ```ruby
279
294
  HealthMonitor.configure do |config|
@@ -320,9 +335,9 @@ Please note that `url` or `connection` can't be used at the same time.
320
335
 
321
336
  ### FileAbsence
322
337
 
323
- This check allows you to create a file on your server when you would like to force the check to fail. For example if you are utilizing the `health.json` as you health check page for your load balancer and would like to force a machine offline.
338
+ This check allows you to create a file on your server when you would like to force the check to fail. For example, if utilizing the `health.json` as the health check page for your load balancer and would like to force a machine offline.
324
339
 
325
- * `filename`: the file relative to the rails root that must remain absent for the health check to remain passing. For example: `public/remove-from-nginx`
340
+ * `filename`: the file relative to the rails root that must remain absent for the health check to remain passing. For example: `public/remove-from-nginx` (Can also be a full path `/opt/app/remove-from-nginx`)
326
341
 
327
342
  ### Adding a Custom Provider
328
343
 
@@ -5,6 +5,7 @@ require 'health_monitor/configuration'
5
5
  module HealthMonitor
6
6
  STATUSES = {
7
7
  ok: 'OK',
8
+ warning: 'WARNING',
8
9
  error: 'ERROR'
9
10
  }.freeze
10
11
 
@@ -25,10 +26,9 @@ module HealthMonitor
25
26
  end
26
27
 
27
28
  results = providers.map { |provider| provider_result(provider, request) }
28
-
29
29
  {
30
- results: results.map { |c| c.without(:critical) },
31
- status: results.any? { |res| res[:status] != STATUSES[:ok] && res[:critical] } ? :service_unavailable : :ok,
30
+ results: results,
31
+ status: results.any? { |res| res[:status] == STATUSES[:error] } ? :service_unavailable : :ok,
32
32
  timestamp: Time.now.to_formatted_s(:rfc2822)
33
33
  }
34
34
  end
@@ -43,8 +43,7 @@ module HealthMonitor
43
43
  {
44
44
  name: provider.name,
45
45
  message: '',
46
- status: STATUSES[:ok],
47
- critical: provider.critical
46
+ status: STATUSES[:ok]
48
47
  }
49
48
  rescue StandardError => e
50
49
  configuration.error_callback.try(:call, e)
@@ -52,8 +51,7 @@ module HealthMonitor
52
51
  {
53
52
  name: provider.name,
54
53
  message: e.message,
55
- status: STATUSES[:error],
56
- critical: provider.critical
54
+ status: provider.critical ? STATUSES[:error] : STATUSES[:warning]
57
55
  }
58
56
  end
59
57
  end
@@ -7,23 +7,58 @@ module HealthMonitor
7
7
  class DatabaseException < StandardError; end
8
8
 
9
9
  class Database < Base
10
+ class Configuration < Base::Configuration
11
+ DEFAULT_CONFIG_NAME = nil
12
+
13
+ attr_reader :config_name
14
+
15
+ def initialize(provider)
16
+ super
17
+
18
+ @config_name = DEFAULT_CONFIG_NAME
19
+ end
20
+
21
+ def config_name=(value)
22
+ @config_name = value.presence&.to_s
23
+ end
24
+ end
25
+
10
26
  def check!
27
+ checked = false
11
28
  failed_databases = []
12
29
 
13
30
  ActiveRecord::Base.connection_handler.connection_pool_list(:all).each do |cp|
14
- if cp.respond_to? :lease_connection
15
- cp.lease_connection.execute('SELECT 1')
16
- else
17
- cp.connection.execute('SELECT 1')
18
- end
31
+ next unless check_connection_pool?(cp)
32
+
33
+ checked = true
34
+ check_connection(cp)
19
35
  rescue Exception
20
36
  failed_databases << cp.db_config.name
21
37
  end
22
38
 
23
39
  raise "unable to connect to: #{failed_databases.uniq.join(',')}" unless failed_databases.empty?
40
+ raise "no connections checked with name: #{configuration.config_name}" if configuration.config_name && !checked
24
41
  rescue Exception => e
25
42
  raise DatabaseException.new(e.message)
26
43
  end
44
+
45
+ private
46
+
47
+ def configuration_class
48
+ ::HealthMonitor::Providers::Database::Configuration
49
+ end
50
+
51
+ def check_connection_pool?(connection_pool)
52
+ configuration.config_name.nil? || configuration.config_name == connection_pool.db_config.name
53
+ end
54
+
55
+ def check_connection(connection_pool)
56
+ if connection_pool.respond_to?(:lease_connection)
57
+ connection_pool.lease_connection.execute('SELECT 1')
58
+ else
59
+ connection_pool.connection.execute('SELECT 1')
60
+ end
61
+ end
27
62
  end
28
63
  end
29
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '12.5.0'
4
+ VERSION = '12.7.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: 12.5.0
4
+ version: 12.7.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: 2024-12-15 00:00:00.000000000 Z
11
+ date: 2025-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties