leafy-rack 0.4.0-java → 0.5.0-java

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: d1239867bb5be43b57a52dcce8f281d146b9edf1
4
- data.tar.gz: 51137ff0563f9a8e922f4af160253f9b34a9c66c
3
+ metadata.gz: 9327f7232dde3bad14695b18b3859ad0410378fe
4
+ data.tar.gz: 7b922a92a4ff45b0a6b43d70042c2f5bc315307d
5
5
  SHA512:
6
- metadata.gz: 90e49272d516440d2208bfd84d922d94fbfe0eb948c0e76ba228e104a1e21e2314f802e68ee9e26a4df0121eee008c02a5389ce1eadd4bcce207a547f90f13e1
7
- data.tar.gz: 669522fc78cea7d8bee811485e82b15b8ca288f65d3ea8791dd9b3cf6cb198473e221780e147bf06cb719a94f95adb0324272031f626c73eaaab06a6c874d7bf
6
+ metadata.gz: ef7e3b693a75420b6a9fa18c02b287dc9c4d660bb6b9cc3d9f361b1b12d30b48ff7bf826451faf019faa93122e90c3c3fee0c225934b1293822229ef55ef2924
7
+ data.tar.gz: d2721c20256b0fe0f48b8a72eb05fb017dcee70519e31db9a8e0e636e941762d0e1b20322c5c1c924a2aab8086c078009493e7f0a281c0a4f5da534e5a4fc22e
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  gem 'leafy-metrics', :path => '../leafy-metrics'
6
6
  gem 'leafy-health', :path => '../leafy-health'
7
+ gem 'leafy-logger', :path => '../leafy-logger'
7
8
 
8
9
  gemspec
9
10
 
data/README.md CHANGED
@@ -96,6 +96,40 @@ or with custom path
96
96
  health = Leafy::Health::Registry.new
97
97
  use Leafy::Rack::Health, health, '/admin/health'
98
98
 
99
+ the json response looks like
100
+
101
+ {
102
+ "deadlock": {
103
+ "healthy": true,
104
+ "message": null
105
+ },
106
+ "elasticsearch": {
107
+ "healthy": false,
108
+ "message": 'error'
109
+ }
110
+ }
111
+
112
+ if you want to add host info to your health report you can do so by adding the respective data to the middleware
113
+
114
+ Leafy::Rack::Health.hostinfo[ 'version' ] = '1.0'
115
+ Leafy::Rack::Health.hostinfo[ 'env' ] = 'staging'
116
+
117
+ then the json response has slightly different structure
118
+
119
+ {
120
+ "host": {
121
+ "version": "",
122
+ "hostname": "localhost",
123
+ "env": "boot",
124
+ },
125
+ "checks": {
126
+ "deadlock": {
127
+ "healthy": true,
128
+ "message": null
129
+ }
130
+ }
131
+ }
132
+
99
133
  ### ping middleware
100
134
 
101
135
  under the path **/ping**
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
23
23
  s.add_runtime_dependency 'leafy-metrics', "~> #{Leafy::Rack::VERSION}"
24
24
  s.add_runtime_dependency 'leafy-health', "~> #{Leafy::Rack::VERSION}"
25
+ s.add_runtime_dependency 'leafy-logger', "~> #{Leafy::Rack::VERSION}"
25
26
  s.add_development_dependency 'rspec', '~> 3.1'
26
27
  s.add_development_dependency 'yard', '~> 0.8.7'
27
28
  s.add_development_dependency 'rake', '~> 10.2'
@@ -6,9 +6,18 @@ module Leafy
6
6
  module Rack
7
7
  class Health
8
8
 
9
+ def self.hostinfo
10
+ @info ||= {}
11
+ end
12
+
9
13
  def self.response( health, env )
10
- data = health.run_health_checks
11
- is_healthy = data.values.all? { |r| r.healthy? }
14
+ checks = health.run_health_checks
15
+ if @info
16
+ data = { 'host' => @info, 'checks' => checks.to_hash }
17
+ else
18
+ data = checks
19
+ end
20
+ is_healthy = checks.values.all? { |r| r.healthy? }
12
21
  json = if env[ 'QUERY_STRING' ] == 'pretty'
13
22
  JSON.pretty_generate( data.to_hash )
14
23
  else
@@ -0,0 +1,20 @@
1
+ require 'leafy/logger/factory'
2
+
3
+ module Leafy
4
+ module Rack
5
+ # Sets our Leafy logger as the rack logger to be used by other middleware / frameworks down
6
+ # the line. If you want your middleware to use this logger, we require that this runs first.
7
+ class Logger
8
+
9
+ def initialize(app, logger_name)
10
+ @app = app
11
+ @logger = Leafy::Logger::Factory.get_logger(logger_name)
12
+ end
13
+
14
+ def call(env)
15
+ env['rack.logger'] = @logger
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,6 +1,6 @@
1
1
  module Leafy
2
2
  module Rack
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
6
6
 
@@ -26,7 +26,7 @@ describe Leafy::Instrumented::CollectedInstrumented do
26
26
  expected[ index ] = 1
27
27
  expect( stati ).to eq expected
28
28
 
29
- expect( registry.metrics.meters.values.to_a[ index ].mean_rate ).to be > 50
29
+ expect( registry.metrics.meters.values.to_a[ index ].mean_rate ).to be > 30
30
30
  end
31
31
  end
32
32
  end
@@ -32,6 +32,11 @@ describe Leafy::Rack::Health do
32
32
  let( :report ) do
33
33
  { 'two' => { 'healthy' => true, 'message' => 'ok' } }
34
34
  end
35
+ let( :report_with_info ) do
36
+ { 'host' => { 'version' => '1.2.3' },
37
+ 'checks' => report }
38
+ end
39
+ after { subject.instance_variable_set( :@info, nil ) }
35
40
 
36
41
  it 'has response' do
37
42
  status, headers, body = subject.response( health, {} )
@@ -41,6 +46,15 @@ describe Leafy::Rack::Health do
41
46
  expect( body.to_yaml ).to eq report.to_yaml
42
47
  end
43
48
 
49
+ it 'has response with hostinfo' do
50
+ subject.hostinfo[ 'version' ] = '1.2.3'
51
+ status, headers, body = subject.response( health, {} )
52
+ expect( status ).to eq 200
53
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
54
+ body = JSON.parse( body.join )
55
+ expect( body.to_yaml ).to eq report_with_info.to_yaml
56
+ end
57
+
44
58
  it 'has pretty response' do
45
59
  status, headers, body = subject.response( health, { 'QUERY_STRING' => 'pretty' } )
46
60
  expect( status ).to eq 200
@@ -49,6 +63,16 @@ describe Leafy::Rack::Health do
49
63
  body = JSON.parse( body.join )
50
64
  expect( body.to_yaml ).to eq report.to_yaml
51
65
  end
66
+
67
+ it 'has pretty response with hostinfo' do
68
+ subject.hostinfo[ 'version' ] = '1.2.3'
69
+ status, headers, body = subject.response( health, { 'QUERY_STRING' => 'pretty' } )
70
+ expect( status ).to eq 200
71
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
72
+ expect( body.join.count( "\n" ) ).to eq 10
73
+ body = JSON.parse( body.join )
74
+ expect( body.to_yaml ).to eq report_with_info.to_yaml
75
+ end
52
76
  end
53
77
 
54
78
  describe 'unhealthy' do
@@ -0,0 +1,20 @@
1
+ require_relative 'setup'
2
+ require 'leafy/rack/logger'
3
+ require 'logger'
4
+
5
+ describe Leafy::Rack::Logger do
6
+ let(:logger) { instance_double(::Logger) }
7
+ let(:logger_name) { 'some logger' }
8
+ let(:app) { double(call: nil) }
9
+ subject(:middleware) { described_class.new(app, logger_name) }
10
+
11
+ before { allow(Leafy::Logger::Factory).to receive(:get_logger).and_return(logger) }
12
+
13
+ describe '#call' do
14
+ let(:env) { { } }
15
+ it 'should set the logger' do
16
+ middleware.call(env)
17
+ expect(env['rack.logger']).to eq logger
18
+ end
19
+ end
20
+ end
@@ -21,17 +21,17 @@ describe Leafy::Json::MetricsWriter do
21
21
 
22
22
  let( :expected ) do
23
23
  {
24
- "two"=> {"count"=>1,
25
- "m15_rate"=>0.0,
26
- "m1_rate"=>0.0,
27
- "m5_rate"=>0.0,
28
- "units"=>"events/second"},
29
24
  "one"=> {"count"=>1,
30
25
  "m15_rate"=>0.0,
31
26
  "m1_rate"=>0.0,
32
27
  "m5_rate"=>0.0,
33
28
  "units"=>"events/second"},
34
- "three"=>{"count"=>2}
29
+ "three"=>{"count"=>2},
30
+ "two"=> {"count"=>1,
31
+ "m15_rate"=>0.0,
32
+ "m1_rate"=>0.0,
33
+ "m5_rate"=>0.0,
34
+ "units"=>"events/second"}
35
35
  }
36
36
  end
37
37
 
@@ -41,7 +41,7 @@ describe Leafy::Json::MetricsWriter do
41
41
  data = JSON.parse( data )
42
42
  expect( data['one'].delete('mean_rate') ).to be >0
43
43
  expect( data['two'].delete('mean_rate') ).to be >0
44
- expect( data.to_yaml ).to eq expected.to_yaml
44
+ expect( Hash[data.sort_by{|k,v| k }].to_yaml ).to eq expected.to_yaml
45
45
  end
46
46
 
47
47
  it 'serializes metrics data to json (pretty print)' do
@@ -50,6 +50,6 @@ describe Leafy::Json::MetricsWriter do
50
50
  data = JSON.parse( data )
51
51
  expect( data['one'].delete('mean_rate') ).to be >0
52
52
  expect( data['two'].delete('mean_rate') ).to be >0
53
- expect( data.to_yaml ).to eq expected.to_yaml
53
+ expect( Hash[data.sort_by{|k,v| k }].to_yaml ).to eq expected.to_yaml
54
54
  end
55
55
  end
metadata CHANGED
@@ -1,99 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leafy-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: java
6
6
  authors:
7
7
  - christian meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: jar-dependencies
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.8
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
22
  - - ~>
17
23
  - !ruby/object:Gem::Version
18
24
  version: 0.1.8
19
- name: jar-dependencies
20
25
  prerelease: false
21
26
  type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: leafy-metrics
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
31
  - - ~>
25
32
  - !ruby/object:Gem::Version
26
- version: 0.1.8
27
- - !ruby/object:Gem::Dependency
33
+ version: 0.5.0
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
36
  - - ~>
31
37
  - !ruby/object:Gem::Version
32
- version: 0.4.0
33
- name: leafy-metrics
38
+ version: 0.5.0
34
39
  prerelease: false
35
40
  type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: leafy-health
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
45
  - - ~>
39
46
  - !ruby/object:Gem::Version
40
- version: 0.4.0
41
- - !ruby/object:Gem::Dependency
47
+ version: 0.5.0
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
50
  - - ~>
45
51
  - !ruby/object:Gem::Version
46
- version: 0.4.0
47
- name: leafy-health
52
+ version: 0.5.0
48
53
  prerelease: false
49
54
  type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: leafy-logger
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
- version: 0.4.0
55
- - !ruby/object:Gem::Dependency
61
+ version: 0.5.0
56
62
  requirement: !ruby/object:Gem::Requirement
57
63
  requirements:
58
64
  - - ~>
59
65
  - !ruby/object:Gem::Version
60
- version: '3.1'
61
- name: rspec
66
+ version: 0.5.0
62
67
  prerelease: false
63
- type: :development
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
64
71
  version_requirements: !ruby/object:Gem::Requirement
65
72
  requirements:
66
73
  - - ~>
67
74
  - !ruby/object:Gem::Version
68
75
  version: '3.1'
69
- - !ruby/object:Gem::Dependency
70
76
  requirement: !ruby/object:Gem::Requirement
71
77
  requirements:
72
78
  - - ~>
73
79
  - !ruby/object:Gem::Version
74
- version: 0.8.7
75
- name: yard
80
+ version: '3.1'
76
81
  prerelease: false
77
82
  type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
87
  - - ~>
81
88
  - !ruby/object:Gem::Version
82
89
  version: 0.8.7
83
- - !ruby/object:Gem::Dependency
84
90
  requirement: !ruby/object:Gem::Requirement
85
91
  requirements:
86
92
  - - ~>
87
93
  - !ruby/object:Gem::Version
88
- version: '10.2'
89
- name: rake
94
+ version: 0.8.7
90
95
  prerelease: false
91
96
  type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
100
  requirements:
94
101
  - - ~>
95
102
  - !ruby/object:Gem::Version
96
103
  version: '10.2'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '10.2'
109
+ prerelease: false
110
+ type: :development
97
111
  description: rack middleware to expose leafy metrics/health data as well a ping rack and a thread-dump rack
98
112
  email:
99
113
  - christian.meier@lookout.com
@@ -119,6 +133,7 @@ files:
119
133
  - lib/leafy/rack/admin.rb
120
134
  - lib/leafy/rack/health.rb
121
135
  - lib/leafy/rack/instrumented.rb
136
+ - lib/leafy/rack/logger.rb
122
137
  - lib/leafy/rack/metrics.rb
123
138
  - lib/leafy/rack/ping.rb
124
139
  - lib/leafy/rack/thread_dump.rb
@@ -130,6 +145,7 @@ files:
130
145
  - spec/health_writer_spec.rb
131
146
  - spec/instrumented_rack_spec.rb
132
147
  - spec/instrumented_spec.rb
148
+ - spec/logger_rack_spec.rb
133
149
  - spec/metrics_rack_spec.rb
134
150
  - spec/metrics_writer_spec.rb
135
151
  - spec/ping_rack_spec.rb