health-monitor-rails 12.5.0 → 12.6.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: 9e05b368505661b4b4a0849035c3449309b6905f92651e2e41701f6651bd36e4
4
+ data.tar.gz: 57fab8c81135598a106a2f07e35956db9bcf3eb2c7bcba91d826a7af5f20b167
5
5
  SHA512:
6
- metadata.gz: 2d6f3818a0dabb60c514382d32815832e94f516ccd3d76751acf90889b61e90edfcfd62b4df44e34669909ed475e2c25585b4c08b5ebc0cfebea33f8f8c965a4
7
- data.tar.gz: 7f519417d7e0adee2f367f776c0d193bc44b0cb8dd48661d5e0067171618efced5e0834ba26a66b51e6b0335a9c8ee81f4d483e1d01ae51a3951a4f872200d36
6
+ metadata.gz: b0f62bf00240926b34f102b96670513caed11686d57a475c0fca7d149da3752bb3331d5a621eccbeea8d233758ec9cc25a359ad537e7399b5a921b1411311529
7
+ data.tar.gz: 148f73504ac45c215629a1761a844b29eef80cac3d72e212bd66caba59a6fddd4d1be6c81061c7e0bbbc22447b1ecaefe01896107cbf91f9c1fef88c27c48242
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:
@@ -322,7 +337,7 @@ Please note that `url` or `connection` can't be used at the same time.
322
337
 
323
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 you are utilizing the `health.json` as you 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
 
@@ -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.6.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.6.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-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties