health-monitor-rails 12.0.0 → 12.2.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: 27b214b33b4ea1a6deaca8dd0a2b7dfb568d4f268435dcc781074a18ce0f4be3
4
- data.tar.gz: 1610408710e79f17a8c02706ecd917f4123c6796430e50a579ed732b41b7f2b7
3
+ metadata.gz: 5b598be966486e38fe823322c1f067e033543ad2df2eb3175c4f48464fd486c0
4
+ data.tar.gz: c75ceeeffb9d18b5427d2791359a74616b91e830fce1cafd7f737e78b7b87c23
5
5
  SHA512:
6
- metadata.gz: 8efc25eb888dd3bdeebd2c7766824f002c52ab2516d1361f32e91581d73065c0481cbf3688bdddd108164fed76814abfece4a58e66aa5aec7cfc84c325f0be2b
7
- data.tar.gz: '048ca3f7345e38f63a4b86f5877a9e1c97864dc37c553502d2e53a7a1aa028be83dd47edf0c0c4fa39f75258d16dc3efab4fdf5c348f0afd8a7b8d708cca1c0c'
6
+ metadata.gz: 54c82d499f5230ffb29d25d1f2ae07a82df5b2c31babfae8759c213488c88024beaa286f64adeaa63a932064e8f5d7496dc263136422b694ee130481c2a1fde4
7
+ data.tar.gz: 446c5607d7eb1f96803318cfca0c460147e45fce68ba0b243f52c91913211f3c1df98a5d0a8a087269ccecd45bf67f882955d46b658e954e9cd240bc0e16f284
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,10 @@ 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
+
315
320
  ### Adding a Custom Provider
316
321
 
317
322
  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 +439,24 @@ nicolas@desktop:$ echo $?
434
439
  2
435
440
  ```
436
441
 
442
+ ## Development
443
+ In order to work on development on the gem itself
444
+
445
+ ### Installing the gems
446
+ Use the [appraisal gem](https://github.com/thoughtbot/appraisal) to install the bundles for different rails versions:
447
+
448
+ ```bash
449
+ appraisal clean
450
+ appraisal generate
451
+ appraisal install
452
+ ```
453
+
454
+ ### Running the tests
455
+ Use appraisal to run the tests using rake
456
+ ```bash
457
+ appraisal rake
458
+ ```
459
+
437
460
  ## License
438
461
 
439
462
  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,
@@ -14,11 +14,14 @@ module HealthMonitor
14
14
  DEFAULT_QUEUES_SIZE = 100
15
15
  DEFAULT_RETRY_CHECK = 20
16
16
 
17
+ attr_accessor :maximum_amount_of_retries
17
18
  attr_reader :queues
18
19
 
19
20
  def initialize(provider)
20
21
  super(provider)
21
22
 
23
+ @maximum_amount_of_retries = DEFAULT_RETRY_CHECK
24
+
22
25
  @queues = {}
23
26
  @queues[DEFAULT_QUEUE_NAME] = { latency: DEFAULT_LATENCY_TIMEOUT, queue_size: DEFAULT_QUEUES_SIZE }
24
27
  end
@@ -96,10 +99,13 @@ module HealthMonitor
96
99
  end
97
100
 
98
101
  def check_amount_of_retries!
99
- maximum_amount_of_retries = ::HealthMonitor::Providers::Sidekiq::Configuration::DEFAULT_RETRY_CHECK
100
- jobs_over_limit = ::Sidekiq::RetrySet.new.select { |job| job.item['retry_count'] >= maximum_amount_of_retries }
102
+ jobs_over_limit = ::Sidekiq::RetrySet.new.select do |job|
103
+ job.item['retry_count'] >= configuration.maximum_amount_of_retries
104
+ end
105
+
106
+ return unless jobs_over_limit.any?
101
107
 
102
- raise "amount of retries for a job is greater than #{maximum_amount_of_retries}" if jobs_over_limit.any?
108
+ raise "amount of retries for a job is greater than #{configuration.maximum_amount_of_retries}"
103
109
  end
104
110
 
105
111
  def check_redis!
@@ -0,0 +1,60 @@
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
+ attr_accessor :url
13
+
14
+ def initialize(provider)
15
+ super(provider)
16
+
17
+ @url = DEFAULT_URL
18
+ end
19
+ end
20
+
21
+ def check!
22
+ check_solr_connection!
23
+ rescue Exception => e
24
+ raise SolrException.new(e.message)
25
+ end
26
+
27
+ private
28
+
29
+ def configuration_class
30
+ ::HealthMonitor::Providers::Solr::Configuration
31
+ end
32
+
33
+ def check_solr_connection!
34
+ json = JSON.parse(solr_response.body)
35
+ raise "The solr has an invalid status #{status_uri}" if json['responseHeader']['status'] != 0
36
+ end
37
+
38
+ def status_uri
39
+ @status_uri ||= begin
40
+ uri = URI(configuration.url)
41
+ uri.path = '/solr/admin/cores'
42
+ uri.query = 'action=STATUS'
43
+ uri
44
+ end
45
+ end
46
+
47
+ def solr_request
48
+ @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
51
+ req
52
+ end
53
+ end
54
+
55
+ def solr_response
56
+ Net::HTTP.start(status_uri.hostname, status_uri.port) { |http| http.request(solr_request) }
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '12.0.0'
4
+ VERSION = '12.2.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.0.0
4
+ version: 12.2.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-25 00:00:00.000000000 Z
11
+ date: 2024-07-26 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: