health-monitor-rails 12.1.0 → 12.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/health_monitor/configuration.rb +1 -1
- data/lib/health_monitor/providers/solr.rb +86 -0
- 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: 952a62b089d3b56df2b8ab11b329dae2512d285db4027bde6705892e171ff755
|
4
|
+
data.tar.gz: 36a7996a83a871a82814caef5d31d2cc880b1f40bd12e2f191290e72a9d1537f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9878debcd730c9848ec50af8ed0b1ed912adffc240c1aab657c82a40e0113ac32a335f53ef32c9c7a3487eee68483235b767009e900c376eb1df55dd28cf2cd
|
7
|
+
data.tar.gz: d361fd7cf5fe894de0d2bce196b06c23f9c3015d1dfa545ba0158c441e2c4f1caed1d6053975a9ff545082025ec1a1c387644a7aaa4dbede0e020c8869289cac
|
data/README.md
CHANGED
@@ -176,6 +176,7 @@ The following services are currently supported:
|
|
176
176
|
* Sidekiq
|
177
177
|
* Resque
|
178
178
|
* Delayed Job
|
179
|
+
* Solr
|
179
180
|
|
180
181
|
## Configuration
|
181
182
|
|
@@ -312,6 +313,11 @@ Please note that `url` or `connection` can't be used at the same time.
|
|
312
313
|
|
313
314
|
* `queue_size`: the size (maximum) of a queue which is considered unhealthy (the default is 100).
|
314
315
|
|
316
|
+
### Solr
|
317
|
+
|
318
|
+
* `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/'`)
|
319
|
+
* `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
|
320
|
+
|
315
321
|
### Adding a Custom Provider
|
316
322
|
|
317
323
|
It's also possible to add custom health check providers suited for your needs (of course, it's highly appreciated and encouraged if you'd contribute useful providers to the project).
|
@@ -434,6 +440,24 @@ nicolas@desktop:$ echo $?
|
|
434
440
|
2
|
435
441
|
```
|
436
442
|
|
443
|
+
## Development
|
444
|
+
In order to work on development on the gem itself
|
445
|
+
|
446
|
+
### Installing the gems
|
447
|
+
Use the [appraisal gem](https://github.com/thoughtbot/appraisal) to install the bundles for different rails versions:
|
448
|
+
|
449
|
+
```bash
|
450
|
+
appraisal clean
|
451
|
+
appraisal generate
|
452
|
+
appraisal install
|
453
|
+
```
|
454
|
+
|
455
|
+
### Running the tests
|
456
|
+
Use appraisal to run the tests using rake
|
457
|
+
```bash
|
458
|
+
appraisal rake
|
459
|
+
```
|
460
|
+
|
437
461
|
## License
|
438
462
|
|
439
463
|
The MIT License (MIT)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'health_monitor/providers/base'
|
4
|
+
|
5
|
+
module HealthMonitor
|
6
|
+
module Providers
|
7
|
+
class SolrException < StandardError; end
|
8
|
+
|
9
|
+
class Solr < Base
|
10
|
+
class Configuration < Base::Configuration
|
11
|
+
DEFAULT_URL = nil
|
12
|
+
DEFAULT_COLLECTION = nil
|
13
|
+
attr_accessor :url, :collection
|
14
|
+
|
15
|
+
def initialize(provider)
|
16
|
+
super(provider)
|
17
|
+
|
18
|
+
@url = DEFAULT_URL
|
19
|
+
@collection = DEFAULT_COLLECTION
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def check!
|
24
|
+
check_solr_connection!
|
25
|
+
rescue Exception => e
|
26
|
+
raise SolrException.new(e.message)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def configuration_class
|
32
|
+
::HealthMonitor::Providers::Solr::Configuration
|
33
|
+
end
|
34
|
+
|
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!
|
52
|
+
json = JSON.parse(solr_response.body)
|
53
|
+
raise "The solr has an invalid status #{status_uri}" if json['responseHeader']['status'] != 0
|
54
|
+
end
|
55
|
+
|
56
|
+
def status_uri
|
57
|
+
@status_uri ||= begin
|
58
|
+
uri = URI(configuration.url)
|
59
|
+
uri.path = '/solr/admin/cores'
|
60
|
+
uri.query = 'action=STATUS'
|
61
|
+
uri
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
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)
|
74
|
+
@solr_request ||= begin
|
75
|
+
req = Net::HTTP::Get.new(uri)
|
76
|
+
req.basic_auth(uri.user, uri.password) if uri.user && uri.password
|
77
|
+
req
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def solr_response(uri: status_uri)
|
82
|
+
Net::HTTP.start(status_uri.hostname, status_uri.port) { |http| http.request(solr_request(uri: uri)) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
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.3.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-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/health_monitor/providers/redis.rb
|
49
49
|
- lib/health_monitor/providers/resque.rb
|
50
50
|
- lib/health_monitor/providers/sidekiq.rb
|
51
|
+
- lib/health_monitor/providers/solr.rb
|
51
52
|
- lib/health_monitor/version.rb
|
52
53
|
homepage: https://github.com/lbeder/health-monitor-rails
|
53
54
|
licenses:
|