health-monitor-rails 1.1.0 → 2.0.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
  SHA1:
3
- metadata.gz: 8dd284083597e8564ff0ebb0b5f22e7f8ecd0bbd
4
- data.tar.gz: 941c1740e843d4cb151b7165ce9bb78279e7bc7c
3
+ metadata.gz: 202a4502ef0b79a948915e6511a598166b3399ed
4
+ data.tar.gz: a7901956e05d4dd6a56e675f84e2f5eb9e027c65
5
5
  SHA512:
6
- metadata.gz: ef8bd0be46c38901593884fb28ed5f50c994df8c32298565afda225436b453e9970ba0ba833d71e211698c65b8f363f580f25e93643d958f7a0032e177fbfd6c
7
- data.tar.gz: 4a9a270da4c1d11e6c14dcbac488d0078a202fc4d8496efee86a7a4d098bac09cf75a296af662ae6f806a852cb493246afb03fd1f7dcf0e3a35516fc5c859b3f
6
+ metadata.gz: e9e374e7f8f4b40a945dbe94b9cc2b0d970124d5bd8d03d5ac3ad683f4f96fb12ec0e4b4833fe3be35be0d950d77c9add29f264af460f1d4d508f33489131d5c
7
+ data.tar.gz: c4743ec2a9839f826db25622825ccdd823c03b93859f0f391fd820f92fe20a8e2345837d4ef07f3ccbd57de6b3f07ae3beb5b922a6535ccdcff61affa7a2e5b8
data/README.md CHANGED
@@ -47,21 +47,34 @@ The following services are currently supported:
47
47
  ## Configuration
48
48
 
49
49
  ### Adding providers
50
- By default, only the database check is enabled. You can add more service providers via an initializer:
50
+ By default, only the database check is enabled. You can add more service providers by explicitly enabling them via an initializer:
51
51
 
52
52
  ```ruby
53
53
  HealthMonitor.configure do |config|
54
- config.providers += [:cache, :redis, :sidekiq]
54
+ config.cache
55
+ config.redis
56
+ config.sidekiq
55
57
  end
56
58
  ```
57
59
 
58
- You can also override the list with a custom set of providers:
60
+ ### Providers configuration
61
+
62
+ Some of the providers can also accept additional configuration:
63
+
59
64
  ```ruby
60
65
  HealthMonitor.configure do |config|
61
- config.providers = [:sidekiq]
66
+ config.sidekiq.configure do |sidekiq_config|
67
+ sidekiq_config.latency = 3.hours
68
+ end
62
69
  end
63
70
  ```
64
71
 
72
+ The currently supported settings are:
73
+
74
+ #### Sidekiq
75
+
76
+ * `latency`: the latency (in seconds) of a queue (now - when the oldest job was enqueued) which is considered unhealthy (the default is 30 seconds, but larger processing queue should have a larger latency value).
77
+
65
78
  ### Adding a custom error callback
66
79
  If you need to perform any additional error handling (for example, for additional error reporting), you can configure a custom error callback:
67
80
 
@@ -1,9 +1,20 @@
1
1
  module HealthMonitor
2
2
  class Configuration
3
- attr_accessor :providers, :error_callback, :basic_auth_credentials
3
+ PROVIDERS = [:cache, :database, :redis, :resque, :sidekiq].freeze
4
+
5
+ attr_accessor :error_callback, :basic_auth_credentials
6
+ attr_reader :providers
4
7
 
5
8
  def initialize
6
- @providers = [:database]
9
+ @providers = Set.new([:database])
10
+ end
11
+
12
+ PROVIDERS.each do |provider|
13
+ define_method provider do |&block|
14
+ @providers << provider
15
+
16
+ "HealthMonitor::Providers::#{provider.capitalize}".constantize
17
+ end
7
18
  end
8
19
  end
9
20
  end
@@ -2,15 +2,36 @@ module HealthMonitor
2
2
  module Providers
3
3
  class Base
4
4
  attr_reader :request
5
+ cattr_accessor :configuration
6
+
7
+ def self.configure
8
+ return unless configurable?
9
+
10
+ self.configuration ||= configuration_class.new
11
+
12
+ yield self.configuration if block_given?
13
+ end
5
14
 
6
15
  def initialize(request: nil)
7
16
  @request = request
17
+
18
+ self.class.configure
8
19
  end
9
20
 
10
21
  # @abstract
11
22
  def check!
12
23
  raise NotImplementedError
13
24
  end
25
+
26
+ private
27
+
28
+ def self.configurable?
29
+ configuration_class
30
+ end
31
+
32
+ # @abstract
33
+ def self.configuration_class
34
+ end
14
35
  end
15
36
  end
16
37
  end
@@ -3,11 +3,19 @@ require 'sidekiq/api'
3
3
 
4
4
  module HealthMonitor
5
5
  module Providers
6
- LATENCY_TIMEOUT = 30.freeze
7
-
8
6
  class SidekiqException < StandardError; end
9
7
 
10
8
  class Sidekiq < Base
9
+ class Configuration
10
+ DEFAULT_LATENCY_TIMEOUT = 30.freeze
11
+
12
+ attr_accessor :latency
13
+
14
+ def initialize
15
+ @latency = DEFAULT_LATENCY_TIMEOUT
16
+ end
17
+ end
18
+
11
19
  def check!
12
20
  check_workers!
13
21
  check_latency!
@@ -18,6 +26,10 @@ module HealthMonitor
18
26
 
19
27
  private
20
28
 
29
+ def self.configuration_class
30
+ Configuration
31
+ end
32
+
21
33
  def check_workers!
22
34
  ::Sidekiq::Workers.new.size
23
35
  end
@@ -25,7 +37,9 @@ module HealthMonitor
25
37
  def check_latency!
26
38
  latency = ::Sidekiq::Queue.new.latency
27
39
 
28
- raise "latency #{latency} is greater than #{LATENCY_TIMEOUT}" if latency > LATENCY_TIMEOUT
40
+ if latency > self.configuration.latency
41
+ raise "latency #{latency} is greater than #{self.configuration.latency}"
42
+ end
29
43
  end
30
44
 
31
45
  def check_redis!
@@ -1,3 +1,3 @@
1
1
  module HealthMonitor
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  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: 1.1.0
4
+ version: 2.0.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: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -213,3 +213,4 @@ specification_version: 4
213
213
  summary: Health monitoring Rails plug-in, which checks various services (db, cache,
214
214
  sidekiq, redis, etc.)
215
215
  test_files: []
216
+ has_rdoc: