leafy-health 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19b3d546b5202841ed7456d0e3558311f3d485d8
4
- data.tar.gz: 2942aaf142b3c01f4ddaf1ffd07d2d011d5bbc4b
3
+ metadata.gz: feebb04febf01947d0cb9097fe2d2506c8043628
4
+ data.tar.gz: 7ae1c75cd9aef3e40c61110a84bd931fe77e96ba
5
5
  SHA512:
6
- metadata.gz: 11fcc8168409f777ebfed83bc2286615e40b5e0b50223d7dfa992512b57a0ca8fabf41ee108afb1a93f46cd6fec17ce4c53c644157f8a864f21531ab80fea2af
7
- data.tar.gz: dfbb26d6b09877fe02f6a3dacf56aec6d6008868b17e0cd936bab395663bd202274f3dd60449e8d9d474e9ee4d56a05fe8e36f27fe822ab888cb40ae1e62072e
6
+ metadata.gz: 8de968175a2fb17784430b6ff1f557e04c966c6bc5a30b0660d577dda7d0af68e256583e8653b8d3b3ccb1a45118b46732fcc51b550964b89c9f05390f46956b
7
+ data.tar.gz: 99b3f3a0673b6aafd1d0d9a05db5d362a81c798cd6cdd342cdc8125d7d2447b129e7810119c7a81862640eb1b8c32a6d7de4b0b061ac2f627d7dd15678e35f3d
data/README.md CHANGED
@@ -8,7 +8,7 @@ gem install leafy-health
8
8
  ```
9
9
  or add to your Gemfile
10
10
  ```
11
- gem 'leqfy-health'
11
+ gem 'leafy-health'
12
12
  ```
13
13
 
14
14
  installing the gem also takes care of the jar dependencies with jruby-1.7.16+
@@ -35,12 +35,12 @@ simple in the sense that either call returns ```nil``` which means healthy or a
35
35
 
36
36
  or with a health-check object
37
37
 
38
- class AppCheck
38
+ class AppCheck < Leafy::Health::HealthCheck
39
39
  def call
40
40
  if app.crashed
41
41
  'application crashed'
42
42
  end
43
- enf
43
+ end
44
44
  end
45
45
  registry.register( 'simple.class', AppCheck.new )
46
46
 
@@ -49,22 +49,45 @@ or with a health-check object
49
49
  here the call method gets an argument which allows to create both
50
50
  healthy and unhealthy states with message.
51
51
 
52
- registry.register( 'app.block') do |health|
52
+ registry.register( 'app.block') do
53
53
  if app.crashed
54
- health.unhealthy( 'application crashed' )
54
+ unhealthy( 'application crashed' )
55
55
  else
56
- health.healthy( 'application ok' )
56
+ healthy( 'application ok' )
57
57
  end
58
58
  end
59
59
 
60
60
  or with a health-check object
61
61
 
62
- class AppCheck
63
- def call( health )
62
+ class AppCheck < Leafy::Health::HealthCheck
63
+ def call
64
64
  if app.crashed
65
- health.unhealthy( 'application crashed' )
65
+ unhealthy( 'application crashed' )
66
66
  else
67
- health.healthy( 'application ok' )
67
+ healthy( 'application ok' )
68
+ end
69
+ end
70
+ end
71
+ registry.register( 'app.class', AppCheck.new )
72
+
73
+ ### health checks with structural data as message
74
+
75
+ registry.register( 'app.block') do
76
+ if app.crashed
77
+ unhealthy( :host => 'localhost', :msg => 'not good' )
78
+ else
79
+ healthy( :host => 'localhost', :msg => 'application ok' )
80
+ end
81
+ end
82
+
83
+ or as health-check object
84
+
85
+ class AppCheck < Leafy::Health::HealthCheck
86
+ def call
87
+ if app.crashed
88
+ unhealthy( :host => 'localhost', :msg => 'application crashed' )
89
+ else
90
+ healthy( :host => 'localhost', :msg => 'application ok' )
68
91
  end
69
92
  end
70
93
  end
@@ -74,6 +97,10 @@ or with a health-check object
74
97
 
75
98
  registry.unregister( 'app.class' )
76
99
 
100
+ ### builtin ThreadDeadlockHeathCheck
101
+
102
+ registry.register( 'app.deadlock', Leafy::Health::ThreadDeadlockHeathCheck.new )
103
+
77
104
  ### note
78
105
 
79
106
  currently there is not further introspection on the registry and its health-check. with the ```Leafy::Json::HealthWriter``` (from leafy-rack) you can get a json representation of the current **health report**
data/leafy-health.gemspec CHANGED
@@ -12,10 +12,11 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q(provides an API to register healthchecks)
13
13
  s.homepage = 'https://github.com/lookout/leafy'
14
14
  s.description = %q(provides an API to register healthchecks which uses dropwizrd-metrics-healthchecks)
15
-
15
+
16
16
  s.files = `git ls-files`.split($/)
17
17
 
18
18
  s.requirements << 'jar io.dropwizard.metrics:metrics-healthchecks, 3.1.0'
19
+ s.requirements << 'jar io.dropwizard.metrics:metrics-jvm, 3.1.0'
19
20
 
20
21
  s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
21
22
  s.add_development_dependency 'rspec', '~> 3.1.0'
@@ -0,0 +1,72 @@
1
+ require 'leafy/health'
2
+
3
+ # add json serialization definition
4
+ class com.codahale.metrics.health.HealthCheck::Result
5
+
6
+ attr_writer :data
7
+
8
+ def to_json( *args )
9
+ { :healthy => healthy?, :message => @data || message }.to_json( *args )
10
+ end
11
+ end
12
+
13
+ module Leafy
14
+ module Health
15
+ ThreadDeadlockHealthCheck = com.codahale.metrics.health.jvm.ThreadDeadlockHealthCheck
16
+ class HealthCheck < com.codahale.metrics.health.HealthCheck
17
+
18
+ def initialize( &block )
19
+ @block = block if block
20
+ end
21
+
22
+ # create healthy result object with given message
23
+ #
24
+ # param [String] optional result message, can be nil
25
+ # return [com.codahale.metrics.health.HealthCheck::Result]
26
+ def healthy( result = nil )
27
+ if result.is_a? Hash
28
+ r = com.codahale.metrics.health.HealthCheck::Result.healthy( result.to_json )
29
+ r.data = result
30
+ r
31
+ else
32
+ com.codahale.metrics.health.HealthCheck::Result.healthy( result )
33
+ end
34
+ end
35
+
36
+ # create unhealthy result object with given message
37
+ #
38
+ # param [String] result message
39
+ # return [com.codahale.metrics.health.HealthCheck::Result]
40
+ def unhealthy( result )
41
+ if result.is_a? Hash
42
+ r = com.codahale.metrics.health.HealthCheck::Result.unhealthy( result.to_json )
43
+ r.data = result
44
+ r
45
+ else
46
+ com.codahale.metrics.health.HealthCheck::Result.unhealthy( result )
47
+ end
48
+ end
49
+
50
+ def check
51
+ case result = call
52
+ when String
53
+ unhealthy( result )
54
+ when NilClass
55
+ healthy
56
+ when com.codahale.metrics.health.HealthCheck::Result
57
+ result
58
+ else
59
+ raise 'wrong result type'
60
+ end
61
+ end
62
+
63
+ def call
64
+ if @block
65
+ instance_eval( &@block )
66
+ else
67
+ 'health check "call" method not implemented'
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,43 +1,9 @@
1
1
  require 'leafy/health'
2
+ require 'leafy/health/health_check'
2
3
  module Leafy
3
4
  module Health
4
5
  class Registry
5
6
 
6
- class HealthCheck < com.codahale.metrics.health.HealthCheck
7
-
8
- # create healthy result object with given message
9
- #
10
- # param [String] optional result message, can be nil
11
- # return [com.codahale.metrics.health.HealthCheck::Result]
12
- def healthy( result = nil )
13
- com.codahale.metrics.health.HealthCheck::Result.healthy( result )
14
- end
15
-
16
- # create unhealthy result object with given message
17
- #
18
- # param [String] result message
19
- # return [com.codahale.metrics.health.HealthCheck::Result]
20
- def unhealthy( result )
21
- com.codahale.metrics.health.HealthCheck::Result.unhealthy( result )
22
- end
23
-
24
- def initialize( block )
25
- super()
26
- @block = block
27
- end
28
-
29
- def check
30
- case result = @block.call( self )
31
- when String
32
- unhealthy( result )
33
- when NilClass
34
- healthy
35
- else
36
- result
37
- end
38
- end
39
- end
40
-
41
7
  # state ofthe registry
42
8
  attr_reader :health
43
9
 
@@ -54,11 +20,10 @@ module Leafy
54
20
  # @yieldreturn [NilClass] if the healthcheck succeeds
55
21
  # @yieldreturn [com.codahale.metrics.health.HealthCheck::Result] if the check produces its own result object
56
22
  def register(name, check = nil, &block )
57
- if check and not block_given? and check.respond_to? :call
58
- @health.register( name, HealthCheck.new( check ) )
59
-
23
+ if check and not block_given? and check.is_a? com.codahale.metrics.health.HealthCheck
24
+ @health.register( name, check )
60
25
  elsif check.nil? and block_given?
61
- @health.register( name, HealthCheck.new( block ) )
26
+ @health.register( name, HealthCheck.new( &block ) )
62
27
  else
63
28
  raise 'needs either a block and object with call method'
64
29
  end
@@ -1,6 +1,6 @@
1
1
  module Leafy
2
2
  module Health
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
6
-
6
+
@@ -3,3 +3,5 @@ require 'jar_dependencies'
3
3
 
4
4
  require_jar( 'io.dropwizard.metrics', 'metrics-healthchecks', '3.1.0' )
5
5
  require_jar( 'org.slf4j', 'slf4j-api', '1.7.7' )
6
+ require_jar( 'io.dropwizard.metrics', 'metrics-jvm', '3.1.0' )
7
+ require_jar( 'io.dropwizard.metrics', 'metrics-core', '3.1.0' )
@@ -1,61 +1,162 @@
1
1
  require 'leafy/health'
2
+ require 'json'
2
3
 
3
4
  describe Leafy::Health::Registry do
4
5
 
5
6
  subject { Leafy::Health::Registry.new }
6
7
 
8
+ it 'has thread-deadlock-health-check' do
9
+ subject.register( 'app', Leafy::Health::ThreadDeadlockHealthCheck.new )
10
+
11
+ expect(subject.names).to eq ['app']
12
+ end
13
+
7
14
  it 'registers and unregister check as block' do
8
15
  subject.register('me') do
9
16
  'error'
10
17
  end
11
18
  expect(subject.names).to eq ['me']
12
- expect(subject.health.run_health_checks.keys).to eq ['me']
19
+
20
+ results = subject.health.run_health_checks
21
+ expect(results.keys).to eq ['me']
22
+
23
+ first = results.values.to_array.first
24
+ expect(first.message).to eq 'error'
25
+ expect(first.healthy?).to eq false
13
26
 
14
27
  subject.unregister('me')
15
28
  expect(subject.names).to be_empty
16
29
  end
17
30
 
18
- it 'registers and unregister check as object with call method' do
19
- subject.register('me', Proc.new {} )
31
+ it 'registers and unregister check as block using dsl' do
32
+ subject.register('me') do
33
+ healthy 'ok'
34
+ end
20
35
  expect(subject.names).to eq ['me']
21
- expect(subject.health.run_health_checks.keys).to eq ['me']
36
+
37
+ results = subject.health.run_health_checks
38
+ expect(results.keys).to eq ['me']
39
+
40
+ first = results.values.to_array.first
41
+ expect(first.message).to eq 'ok'
42
+ expect(first.healthy?).to eq true
43
+
44
+ subject.unregister('me')
45
+ expect(subject.names).to be_empty
46
+ end
47
+
48
+ it 'registers and unregister check as HealthCheck with block' do
49
+ subject.register('me', Leafy::Health::HealthCheck.new {} )
50
+
51
+ expect(subject.names).to eq ['me']
52
+
53
+ results = subject.health.run_health_checks
54
+ expect(results.keys).to eq ['me']
55
+
56
+ first = results.values.to_array.first
57
+ expect(first.message).to be_nil
58
+ expect(first.healthy?).to eq true
59
+
60
+ subject.unregister('me')
61
+ expect(subject.names).to be_empty
62
+ end
63
+
64
+ it 'registers and unregister check as HealthCheck without implementing call' do
65
+ subject.register('me', Leafy::Health::HealthCheck.new )
66
+
67
+ expect(subject.names).to eq ['me']
68
+
69
+ results = subject.health.run_health_checks
70
+ expect(results.keys).to eq ['me']
71
+
72
+ first = results.values.to_array.first
73
+ expect(first.message).to eq 'health check "call" method not implemented'
74
+ expect(first.healthy?).to eq false
22
75
 
23
76
  subject.unregister('me')
24
77
  expect(subject.names).to be_empty
25
78
  end
26
79
 
27
- it 'fails register check as object without call method' do
80
+ it 'fails register check as wrong object' do
28
81
  expect { subject.register('me', Object.new ) }.to raise_error
29
82
  end
30
83
 
31
- describe Leafy::Health::Registry::HealthCheck do
84
+ describe Leafy::Health::HealthCheck do
32
85
 
33
- it 'is healthy with simple block' do
34
- check = Leafy::Health::Registry::HealthCheck.new( Proc.new { nil } )
86
+ it 'is healthy default with simple block' do
87
+ check = Leafy::Health::HealthCheck.new do
88
+ nil
89
+ end
35
90
  expect( check.check.healthy? ).to be true
36
91
  expect( check.check.message ).to be nil
92
+ expect( check.check.to_json ).to eq "{\"healthy\":true,\"message\":null}"
37
93
  end
38
94
 
39
- it 'is healthy' do
40
- checker = Proc.new do |health|
41
- health.healthy( 'ok' )
95
+ it 'is healthy with simple block' do
96
+ check = Leafy::Health::HealthCheck.new do
97
+ healthy 'happy'
98
+ end
99
+ expect( check.check.healthy? ).to be true
100
+ expect( check.check.message ).to eq 'happy'
101
+ expect( check.check.to_json ).to eq "{\"healthy\":true,\"message\":\"happy\"}"
102
+ end
103
+
104
+ it 'is healthy with structural message' do
105
+ check = Leafy::Health::HealthCheck.new do
106
+ healthy :msg => 'happy', :date => '11-11-2011'
42
107
  end
43
- check = Leafy::Health::Registry::HealthCheck.new( checker )
108
+ expect( check.check.healthy? ).to be true
109
+ expect( check.check.to_json ).to eq "{\"healthy\":true,\"message\":{\"msg\":\"happy\",\"date\":\"11-11-2011\"}}"
110
+ end
111
+
112
+ it 'is healthy default' do
113
+ check = Leafy::Health::HealthCheck.new
114
+ def check.call; nil; end
115
+ expect( check.check.healthy? ).to be true
116
+ expect( check.check.message ).to eq nil
117
+ end
118
+
119
+ it 'is healthy' do
120
+ check = Leafy::Health::HealthCheck.new
121
+ def check.call; healthy( 'ok' ); end
44
122
  expect( check.check.healthy? ).to be true
45
123
  expect( check.check.message ).to eq 'ok'
46
124
  end
47
125
 
48
- it 'is unhealthy with simple block' do
49
- check = Leafy::Health::Registry::HealthCheck.new( Proc.new { 'sick' } )
126
+ it 'is unhealthy default with simple block' do
127
+ check = Leafy::Health::HealthCheck.new do
128
+ 'sick'
129
+ end
50
130
  expect( check.check.healthy? ).to be false
51
131
  expect( check.check.message ).to eq 'sick'
52
132
  end
53
133
 
54
- it 'is unhealthy' do
55
- checker = Proc.new do |health|
56
- health.unhealthy( 'not ok' )
134
+ it 'is unhealthy with simple block' do
135
+ check = Leafy::Health::HealthCheck.new do
136
+ unhealthy 'really sick'
57
137
  end
58
- check = Leafy::Health::Registry::HealthCheck.new( checker )
138
+ expect( check.check.healthy? ).to be false
139
+ expect( check.check.message ).to eq 'really sick'
140
+ end
141
+
142
+ it 'is unhealthy with structural message' do
143
+ check = Leafy::Health::HealthCheck.new do
144
+ unhealthy :msg => 'oh je', :date => '11-11-2011'
145
+ end
146
+ expect( check.check.healthy? ).to be false
147
+ expect( check.check.to_json ).to eq "{\"healthy\":false,\"message\":{\"msg\":\"oh je\",\"date\":\"11-11-2011\"}}"
148
+ end
149
+
150
+ it 'is unhealthy default' do
151
+ check = Leafy::Health::HealthCheck.new
152
+ def check.call; 'not ok'; end
153
+ expect( check.check.healthy? ).to be false
154
+ expect( check.check.message ).to eq 'not ok'
155
+ end
156
+
157
+ it 'is unhealthy' do
158
+ check = Leafy::Health::HealthCheck.new
159
+ def check.call; unhealthy( 'not ok' ); end
59
160
  expect( check.check.healthy? ).to be false
60
161
  expect( check.check.message ).to eq 'not ok'
61
162
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leafy-health
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian meier
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jar-dependencies
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ~>
18
17
  - !ruby/object:Gem::Version
19
18
  version: 0.1.8
20
- type: :runtime
19
+ name: jar-dependencies
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.8
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ~>
32
31
  - !ruby/object:Gem::Version
33
32
  version: 3.1.0
34
- type: :development
33
+ name: rspec
35
34
  prerelease: false
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: yard
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - "~>"
44
+ - - ~>
46
45
  - !ruby/object:Gem::Version
47
46
  version: 0.8.7
48
- type: :development
47
+ name: yard
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.8.7
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - "~>"
58
+ - - ~>
60
59
  - !ruby/object:Gem::Version
61
60
  version: '10.2'
62
- type: :development
61
+ name: rake
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.2'
69
69
  description: provides an API to register healthchecks which uses dropwizrd-metrics-healthchecks
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
76
+ - .gitignore
77
77
  - Gemfile
78
78
  - LICENSE
79
79
  - README.md
@@ -82,6 +82,7 @@ files:
82
82
  - lib/leafy-health.rb
83
83
  - lib/leafy-health_jars.rb
84
84
  - lib/leafy/health.rb
85
+ - lib/leafy/health/health_check.rb
85
86
  - lib/leafy/health/registry.rb
86
87
  - lib/leafy/health/version.rb
87
88
  - spec/registry_spec.rb
@@ -90,25 +91,27 @@ homepage: https://github.com/lookout/leafy
90
91
  licenses:
91
92
  - MIT
92
93
  metadata: {}
93
- post_install_message:
94
+ post_install_message:
94
95
  rdoc_options: []
95
96
  require_paths:
96
97
  - lib
97
98
  required_ruby_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
- - - ">="
100
+ - - '>='
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
- - - ">="
105
+ - - '>='
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements:
108
109
  - jar io.dropwizard.metrics:metrics-healthchecks, 3.1.0
109
- rubyforge_project:
110
+ - jar io.dropwizard.metrics:metrics-jvm, 3.1.0
111
+ rubyforge_project:
110
112
  rubygems_version: 2.4.5
111
- signing_key:
113
+ signing_key:
112
114
  specification_version: 4
113
115
  summary: provides an API to register healthchecks
114
116
  test_files: []
117
+ has_rdoc: