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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a4b35be2c84bd3859456f041a978da8828cb72294d86bfab7b97dc3478134b3
4
- data.tar.gz: a393dbc7c46777aae939589d443b67ef41abbeb238879adf4ff6985511aceda9
3
+ metadata.gz: 952a62b089d3b56df2b8ab11b329dae2512d285db4027bde6705892e171ff755
4
+ data.tar.gz: 36a7996a83a871a82814caef5d31d2cc880b1f40bd12e2f191290e72a9d1537f
5
5
  SHA512:
6
- metadata.gz: 1f18d57cdf6471cf63e7ad493b4019bf1a5edfca635393aa1f35def68439dfd859b19ccf2fb3f5ab178015db46b24bf7507ed43fbc8efc8114e44d7d7e8ff736
7
- data.tar.gz: 4da774036fbbf7e4baf0e6abb2bd7eb313282bc2ea3ca39feded6bfe0c099f2fe5549e02b799e255d9d4738d07bf80ecda5dfd2b10caa213f3f68170204d684d
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)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module HealthMonitor
4
4
  class Configuration
5
- PROVIDERS = %i[cache database delayed_job redis resque sidekiq].freeze
5
+ PROVIDERS = %i[cache database delayed_job redis resque sidekiq solr].freeze
6
6
 
7
7
  attr_accessor :basic_auth_credentials,
8
8
  :environment_variables,
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '12.1.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.1.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-03-29 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
@@ -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: