health-monitor-rails 12.2.0 → 12.3.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: 5b598be966486e38fe823322c1f067e033543ad2df2eb3175c4f48464fd486c0
4
- data.tar.gz: c75ceeeffb9d18b5427d2791359a74616b91e830fce1cafd7f737e78b7b87c23
3
+ metadata.gz: 952a62b089d3b56df2b8ab11b329dae2512d285db4027bde6705892e171ff755
4
+ data.tar.gz: 36a7996a83a871a82814caef5d31d2cc880b1f40bd12e2f191290e72a9d1537f
5
5
  SHA512:
6
- metadata.gz: 54c82d499f5230ffb29d25d1f2ae07a82df5b2c31babfae8759c213488c88024beaa286f64adeaa63a932064e8f5d7496dc263136422b694ee130481c2a1fde4
7
- data.tar.gz: 446c5607d7eb1f96803318cfca0c460147e45fce68ba0b243f52c91913211f3c1df98a5d0a8a087269ccecd45bf67f882955d46b658e954e9cd240bc0e16f284
6
+ metadata.gz: a9878debcd730c9848ec50af8ed0b1ed912adffc240c1aab657c82a40e0113ac32a335f53ef32c9c7a3487eee68483235b767009e900c376eb1df55dd28cf2cd
7
+ data.tar.gz: d361fd7cf5fe894de0d2bce196b06c23f9c3015d1dfa545ba0158c441e2c4f1caed1d6053975a9ff545082025ec1a1c387644a7aaa4dbede0e020c8869289cac
data/README.md CHANGED
@@ -316,6 +316,7 @@ Please note that `url` or `connection` can't be used at the same time.
316
316
  ### Solr
317
317
 
318
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
319
320
 
320
321
  ### Adding a Custom Provider
321
322
 
@@ -9,12 +9,14 @@ module HealthMonitor
9
9
  class Solr < Base
10
10
  class Configuration < Base::Configuration
11
11
  DEFAULT_URL = nil
12
- attr_accessor :url
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 solr_request
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(status_uri)
50
- req.basic_auth(status_uri.user, status_uri.password) if status_uri.user && status_uri.password
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '12.2.0'
4
+ VERSION = '12.3.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.2.0
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-07-26 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties