health-monitor-rails 12.2.0 → 12.4.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 +12 -0
- data/lib/health_monitor/configuration.rb +1 -1
- data/lib/health_monitor/providers/file_absence.rb +34 -0
- data/lib/health_monitor/providers/solr.rb +32 -6
- data/lib/health_monitor/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16d418a94d55bfea53470ed8a0b1d4b8614c32b2f3a0f439dd37859c99cb62b1
|
4
|
+
data.tar.gz: 5f53e4f8bcc43d2a2ae27fa02a14f44c277b2a37388b500b7c9450ca6834197d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e09ede9673ea8c30618eeffb12b169920705b4f54376e091141008303c060a6071ec627eec576724901f046d3c697e30c0519235a22175ec100ce58286188c97
|
7
|
+
data.tar.gz: b0383068465c7ebb1e4beedd46c9f26801fcd2fdae8f0b591be3a4967bb72bb94f13a6a62a3c35290c3385f187ec917cafd3ea5add28386afa2c44bda9a6d6de
|
data/README.md
CHANGED
@@ -177,6 +177,7 @@ The following services are currently supported:
|
|
177
177
|
* Resque
|
178
178
|
* Delayed Job
|
179
179
|
* Solr
|
180
|
+
* FileAbsence
|
180
181
|
|
181
182
|
## Configuration
|
182
183
|
|
@@ -316,6 +317,13 @@ Please note that `url` or `connection` can't be used at the same time.
|
|
316
317
|
### Solr
|
317
318
|
|
318
319
|
* `url`: the URL used to connect to your Solr instance - must be a string. You can also use `url` to explicitly configure authentication (e.g., `'https://user:pass@example.solr.com:8983/'`)
|
320
|
+
* `collection`: An optional parameter used to connect to your specific Solr collection - must be a string. By setting this parameter the code will check the status of this individual collection in your Solr instance instead of just the status of the overall Solr instance
|
321
|
+
|
322
|
+
### FileAbsence
|
323
|
+
|
324
|
+
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.
|
325
|
+
|
326
|
+
* `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`
|
319
327
|
|
320
328
|
### Adding a Custom Provider
|
321
329
|
|
@@ -440,9 +448,11 @@ nicolas@desktop:$ echo $?
|
|
440
448
|
```
|
441
449
|
|
442
450
|
## Development
|
451
|
+
|
443
452
|
In order to work on development on the gem itself
|
444
453
|
|
445
454
|
### Installing the gems
|
455
|
+
|
446
456
|
Use the [appraisal gem](https://github.com/thoughtbot/appraisal) to install the bundles for different rails versions:
|
447
457
|
|
448
458
|
```bash
|
@@ -452,7 +462,9 @@ appraisal install
|
|
452
462
|
```
|
453
463
|
|
454
464
|
### Running the tests
|
465
|
+
|
455
466
|
Use appraisal to run the tests using rake
|
467
|
+
|
456
468
|
```bash
|
457
469
|
appraisal rake
|
458
470
|
```
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module HealthMonitor
|
4
4
|
class Configuration
|
5
|
-
PROVIDERS = %i[cache database delayed_job redis resque sidekiq solr].freeze
|
5
|
+
PROVIDERS = %i[cache database delayed_job file_absence redis resque sidekiq solr].freeze
|
6
6
|
|
7
7
|
attr_accessor :basic_auth_credentials,
|
8
8
|
:environment_variables,
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'health_monitor/providers/base'
|
4
|
+
|
5
|
+
module HealthMonitor
|
6
|
+
module Providers
|
7
|
+
class FileAbsenceException < StandardError; end
|
8
|
+
|
9
|
+
class FileAbsence < Base
|
10
|
+
class Configuration < Base::Configuration
|
11
|
+
DEFAULT_FILENAME = nil
|
12
|
+
attr_accessor :filename
|
13
|
+
|
14
|
+
def initialize(provider)
|
15
|
+
super(provider)
|
16
|
+
|
17
|
+
@filename = DEFAULT_FILENAME
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def check!
|
22
|
+
return unless File.exist?(configuration.filename)
|
23
|
+
|
24
|
+
raise FileAbsenceException.new("Unwanted file #{configuration.filename} exists!")
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def configuration_class
|
30
|
+
::HealthMonitor::Providers::FileAbsence::Configuration
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -9,12 +9,14 @@ module HealthMonitor
|
|
9
9
|
class Solr < Base
|
10
10
|
class Configuration < Base::Configuration
|
11
11
|
DEFAULT_URL = nil
|
12
|
-
|
12
|
+
DEFAULT_COLLECTION = nil
|
13
|
+
attr_accessor :url, :collection
|
13
14
|
|
14
15
|
def initialize(provider)
|
15
16
|
super(provider)
|
16
17
|
|
17
18
|
@url = DEFAULT_URL
|
19
|
+
@collection = DEFAULT_COLLECTION
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -31,6 +33,22 @@ module HealthMonitor
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def check_solr_connection!
|
36
|
+
if configuration.collection
|
37
|
+
check_solr_collection!
|
38
|
+
else
|
39
|
+
check_solr_uri!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def check_solr_collection!
|
44
|
+
response = solr_response(uri: collection_uri)
|
45
|
+
json = JSON.parse(response.body) if response.code == '200'
|
46
|
+
return if response.is_a?(Net::HTTPSuccess) && json['status'].casecmp?('OK')
|
47
|
+
|
48
|
+
raise "The Solr collection has an invalid status #{collection_uri}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_solr_uri!
|
34
52
|
json = JSON.parse(solr_response.body)
|
35
53
|
raise "The solr has an invalid status #{status_uri}" if json['responseHeader']['status'] != 0
|
36
54
|
end
|
@@ -44,16 +62,24 @@ module HealthMonitor
|
|
44
62
|
end
|
45
63
|
end
|
46
64
|
|
47
|
-
def
|
65
|
+
def collection_uri
|
66
|
+
@collection_uri ||= begin
|
67
|
+
uri = URI(configuration.url)
|
68
|
+
uri.path = "/solr/#{configuration.collection}/admin/ping"
|
69
|
+
uri
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def solr_request(uri: status_uri)
|
48
74
|
@solr_request ||= begin
|
49
|
-
req = Net::HTTP::Get.new(
|
50
|
-
req.basic_auth(
|
75
|
+
req = Net::HTTP::Get.new(uri)
|
76
|
+
req.basic_auth(uri.user, uri.password) if uri.user && uri.password
|
51
77
|
req
|
52
78
|
end
|
53
79
|
end
|
54
80
|
|
55
|
-
def solr_response
|
56
|
-
Net::HTTP.start(status_uri.hostname, status_uri.port) { |http| http.request(solr_request) }
|
81
|
+
def solr_response(uri: status_uri)
|
82
|
+
Net::HTTP.start(status_uri.hostname, status_uri.port) { |http| http.request(solr_request(uri: uri)) }
|
57
83
|
end
|
58
84
|
end
|
59
85
|
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.
|
4
|
+
version: 12.4.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-
|
11
|
+
date: 2024-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/health_monitor/providers/cache.rb
|
46
46
|
- lib/health_monitor/providers/database.rb
|
47
47
|
- lib/health_monitor/providers/delayed_job.rb
|
48
|
+
- lib/health_monitor/providers/file_absence.rb
|
48
49
|
- lib/health_monitor/providers/redis.rb
|
49
50
|
- lib/health_monitor/providers/resque.rb
|
50
51
|
- lib/health_monitor/providers/sidekiq.rb
|