leafy-health 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +34 -4
  3. data/.travis.yml +19 -0
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +1 -5
  6. data/README.md +10 -116
  7. data/examples/datadog/.gitignore +2 -0
  8. data/examples/datadog/Gemfile +12 -0
  9. data/examples/datadog/Mavenfile +22 -0
  10. data/examples/datadog/README.md +16 -0
  11. data/examples/datadog/lib/java_gauge.rb +20 -0
  12. data/examples/datadog/lib/metrics.rb +18 -0
  13. data/examples/datadog/lib/ruby_gauge.rb +19 -0
  14. data/examples/hellowarld/.gitignore +3 -0
  15. data/examples/hellowarld/Gemfile +15 -0
  16. data/examples/hellowarld/Mavenfile +162 -0
  17. data/examples/hellowarld/README.md +44 -0
  18. data/examples/hellowarld/Rakefile +13 -0
  19. data/examples/hellowarld/WEB-INF/web.xml +31 -0
  20. data/examples/hellowarld/app/hellowarld.rb +55 -0
  21. data/examples/hellowarld/app/views/person.erb +52 -0
  22. data/examples/hellowarld/config.ru +12 -0
  23. data/leafy-complete.gemspec +22 -0
  24. data/leafy-health/.gitignore +4 -0
  25. data/leafy-health/Gemfile +7 -0
  26. data/leafy-health/LICENSE +22 -0
  27. data/leafy-health/README.md +123 -0
  28. data/{Rakefile → leafy-health/Rakefile} +0 -0
  29. data/{leafy-health.gemspec → leafy-health/leafy-health.gemspec} +0 -0
  30. data/{lib → leafy-health/lib}/leafy-health.rb +0 -0
  31. data/{lib → leafy-health/lib}/leafy-health_jars.rb +0 -0
  32. data/{lib → leafy-health/lib}/leafy/health.rb +0 -0
  33. data/{lib → leafy-health/lib}/leafy/health/health_check.rb +0 -0
  34. data/{lib → leafy-health/lib}/leafy/health/registry.rb +0 -0
  35. data/{lib → leafy-health/lib}/leafy/health/version.rb +1 -1
  36. data/{spec → leafy-health/spec}/registry_spec.rb +0 -0
  37. data/{spec → leafy-health/spec}/setup.rb +0 -0
  38. data/leafy-logger/.gitignore +5 -0
  39. data/leafy-logger/Gemfile +9 -0
  40. data/leafy-logger/LICENSE +22 -0
  41. data/leafy-logger/README.md +174 -0
  42. data/leafy-logger/Rakefile +14 -0
  43. data/leafy-logger/leafy-logger.gemspec +32 -0
  44. data/leafy-logger/lib/leafy-logger.rb +1 -0
  45. data/leafy-logger/lib/leafy-logger_jars.rb +33 -0
  46. data/leafy-logger/lib/leafy/logger.rb +1 -0
  47. data/leafy-logger/lib/leafy/logger/appender_factories.rb +89 -0
  48. data/leafy-logger/lib/leafy/logger/factory.rb +141 -0
  49. data/leafy-logger/lib/leafy/logger/version.rb +6 -0
  50. data/leafy-logger/spec/appender_factories_spec.rb +147 -0
  51. data/leafy-logger/spec/factory_spec.rb +176 -0
  52. data/leafy-logger/spec/logging.yml +16 -0
  53. data/leafy-logger/spec/setup.rb +2 -0
  54. data/leafy-metrics/.gitignore +5 -0
  55. data/leafy-metrics/Gemfile +7 -0
  56. data/leafy-metrics/LICENSE +22 -0
  57. data/leafy-metrics/README.md +221 -0
  58. data/leafy-metrics/Rakefile +14 -0
  59. data/leafy-metrics/leafy-metrics.gemspec +29 -0
  60. data/leafy-metrics/lib/leafy-metrics.rb +2 -0
  61. data/leafy-metrics/lib/leafy-metrics_jars.rb +5 -0
  62. data/leafy-metrics/lib/leafy/metrics.rb +2 -0
  63. data/leafy-metrics/lib/leafy/metrics/console_reporter.rb +32 -0
  64. data/leafy-metrics/lib/leafy/metrics/csv_reporter.rb +26 -0
  65. data/leafy-metrics/lib/leafy/metrics/graphite/graphite.rb +28 -0
  66. data/leafy-metrics/lib/leafy/metrics/graphite/graphite_reporter.rb +43 -0
  67. data/leafy-metrics/lib/leafy/metrics/registry.rb +108 -0
  68. data/leafy-metrics/lib/leafy/metrics/reporter.rb +51 -0
  69. data/leafy-metrics/lib/leafy/metrics/version.rb +6 -0
  70. data/leafy-metrics/spec/console_reporter_spec.rb +72 -0
  71. data/leafy-metrics/spec/csv_reporter_spec.rb +75 -0
  72. data/leafy-metrics/spec/graphite_reporter_spec.rb +72 -0
  73. data/leafy-metrics/spec/graphite_spec.rb +23 -0
  74. data/leafy-metrics/spec/registry_spec.rb +106 -0
  75. data/leafy-metrics/spec/setup.rb +10 -0
  76. data/leafy-rack/.gitignore +4 -0
  77. data/leafy-rack/Gemfile +10 -0
  78. data/leafy-rack/LICENSE +22 -0
  79. data/leafy-rack/README.md +155 -0
  80. data/leafy-rack/Rakefile +14 -0
  81. data/leafy-rack/leafy-rack.gemspec +29 -0
  82. data/leafy-rack/lib/leafy-rack.rb +1 -0
  83. data/leafy-rack/lib/leafy-rack_jars.rb +10 -0
  84. data/leafy-rack/lib/leafy/instrumented/basic_instrumented.rb +38 -0
  85. data/leafy-rack/lib/leafy/instrumented/instrumented.rb +27 -0
  86. data/leafy-rack/lib/leafy/json/health_writer.rb +15 -0
  87. data/leafy-rack/lib/leafy/json/json_writer.rb +33 -0
  88. data/leafy-rack/lib/leafy/json/metrics_writer.rb +22 -0
  89. data/leafy-rack/lib/leafy/rack.rb +1 -0
  90. data/leafy-rack/lib/leafy/rack/admin.rb +73 -0
  91. data/leafy-rack/lib/leafy/rack/health.rb +43 -0
  92. data/leafy-rack/lib/leafy/rack/instrumented.rb +20 -0
  93. data/leafy-rack/lib/leafy/rack/metrics.rb +35 -0
  94. data/leafy-rack/lib/leafy/rack/ping.rb +29 -0
  95. data/leafy-rack/lib/leafy/rack/thread_dump.rb +56 -0
  96. data/leafy-rack/lib/leafy/rack/version.rb +6 -0
  97. data/leafy-rack/spec/admin_rack_spec.rb +141 -0
  98. data/leafy-rack/spec/basic_instrumented_spec.rb +31 -0
  99. data/leafy-rack/spec/health_rack_spec.rb +136 -0
  100. data/leafy-rack/spec/health_writer_spec.rb +47 -0
  101. data/leafy-rack/spec/instrumented_rack_spec.rb +37 -0
  102. data/leafy-rack/spec/instrumented_spec.rb +36 -0
  103. data/leafy-rack/spec/metrics_rack_spec.rb +110 -0
  104. data/leafy-rack/spec/metrics_writer_spec.rb +55 -0
  105. data/leafy-rack/spec/ping_rack_spec.rb +63 -0
  106. data/leafy-rack/spec/setup.rb +3 -0
  107. data/leafy-rack/spec/thread_dump_spec.rb +59 -0
  108. metadata +106 -12
@@ -0,0 +1,31 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/instrumented/basic_instrumented'
4
+
5
+ describe Leafy::Instrumented::BasicInstrumented do
6
+
7
+ subject { Leafy::Instrumented::BasicInstrumented.new( registry, "name" ) }
8
+
9
+ let( :registry ) { Leafy::Metrics::Registry.new }
10
+
11
+ let( :app ) do
12
+ Proc.new() do
13
+ sleep 0.1
14
+ [ 200, nil, registry.metrics.counters.values.first.count ]
15
+ end
16
+ end
17
+
18
+ it 'collects metrics for a call' do
19
+ _, _, count = subject.call do
20
+ app.call
21
+ end
22
+ expect( count ).to eq 1
23
+ expect( registry.metrics.timers.keys ).to eq [ 'name.requests' ]
24
+ expect( registry.metrics.timers.values.first.mean_rate ).to be > 0.9
25
+ expect( registry.metrics.counters.keys ).to eq [ 'name.active_requests' ]
26
+ expect( registry.metrics.counters.values.collect { |a| a.count } ).to eq [ 0 ]
27
+ expect( registry.metrics.meters.keys ).to eq [ 'name.responseCodes.other' ]
28
+ expect( registry.metrics.meters.values.collect { |a| a.count } ).to eq [ 1 ]
29
+ expect( registry.metrics.meters.values.first.mean_rate ).to be > 5.0
30
+ end
31
+ end
@@ -0,0 +1,136 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/rack/health'
4
+ require 'yaml'
5
+ require 'json'
6
+
7
+ describe Leafy::Rack::Health do
8
+
9
+ subject { Leafy::Rack::Health }
10
+
11
+ let( :registry ) { Leafy::Health::Registry.new }
12
+
13
+ let( :expected_headers ) do
14
+ { 'Content-Type' => 'application/json',
15
+ 'Cache-Control' => 'must-revalidate,no-cache,no-store' }
16
+ end
17
+
18
+ let( :result ){ [ 200, nil, [] ] }
19
+ let( :app ) do
20
+ Proc.new() { result }
21
+ end
22
+
23
+ describe 'healthy' do
24
+
25
+ let( :health ) do
26
+ m = registry
27
+ m.register( 'two' ) do |ctx|
28
+ ctx.healthy 'ok'
29
+ end
30
+ m.health
31
+ end
32
+ let( :report ) do
33
+ { 'two' => { 'healthy' => true, 'message' => 'ok' } }
34
+ end
35
+
36
+ it 'has response' do
37
+ status, headers, body = subject.response( health, {} )
38
+ expect( status ).to eq 200
39
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
40
+ body = JSON.parse( body.join )
41
+ expect( body.to_yaml ).to eq report.to_yaml
42
+ end
43
+
44
+ it 'has pretty response' do
45
+ status, headers, body = subject.response( health, { 'QUERY_STRING' => 'pretty' } )
46
+ expect( status ).to eq 200
47
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
48
+ expect( body.join.count( "\n" ) ).to eq 5
49
+ body = JSON.parse( body.join )
50
+ expect( body.to_yaml ).to eq report.to_yaml
51
+ end
52
+ end
53
+
54
+ describe 'unhealthy' do
55
+ let( :health ) do
56
+ m = registry
57
+ m.register( 'one' ) do |ctx|
58
+ 'error'
59
+ end
60
+ m.health
61
+ end
62
+
63
+ let( :report ) do
64
+ { 'one' => { 'healthy' => false, 'message' => 'error' } }
65
+ end
66
+
67
+ it 'has response' do
68
+ status, headers, body = subject.response( health, {} )
69
+ expect( status ).to eq 503
70
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
71
+ body = JSON.parse( body.join )
72
+ expect( body.to_yaml ).to eq report.to_yaml
73
+ end
74
+
75
+ it 'has pretty response' do
76
+ status, headers, body = subject.response( health, { 'QUERY_STRING' => 'pretty' } )
77
+ expect( status ).to eq 503
78
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
79
+ expect( body.join.count( "\n" ) ).to eq 5
80
+ body = JSON.parse( body.join )
81
+ expect( body.to_yaml ).to eq report.to_yaml
82
+ end
83
+ end
84
+
85
+ describe 'default path' do
86
+ subject { Leafy::Rack::Health.new( app, registry ) }
87
+
88
+ it 'passes request if not matches the given path' do
89
+ env = { 'PATH_INFO'=> '/something' }
90
+ expect( subject.call( env ) ).to eq result
91
+ end
92
+
93
+ it 'reports health-checks on health path' do
94
+ env = { 'PATH_INFO'=> '/health' }
95
+ status, headers, body = subject.call( env )
96
+ expect( status ).to eq 200
97
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
98
+ expect( body.join ).to eq '{}'
99
+ end
100
+
101
+ it 'reports "pretty" health-checks on health path' do
102
+ env = { 'PATH_INFO'=> '/health', 'QUERY_STRING' => 'pretty' }
103
+ status, headers, body = subject.call( env )
104
+ expect( status ).to eq 200
105
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
106
+ expect( body.join.gsub( /\s/m, '' ) ).to eq '{}'
107
+ end
108
+ end
109
+
110
+ describe 'custom path' do
111
+ subject { Leafy::Rack::Health.new( app, registry, '/custom' ) }
112
+
113
+ it 'passes request if not matches the given path' do
114
+ env = { 'PATH_INFO'=> '/something' }
115
+ expect( subject.call( env ) ).to eq result
116
+ env = { 'PATH_INFO'=> '/health' }
117
+ expect( subject.call( env ) ).to eq result
118
+ end
119
+
120
+ it 'reports health-checks on health path' do
121
+ env = { 'PATH_INFO'=> '/custom' }
122
+ status, headers, body = subject.call( env )
123
+ expect( status ).to eq 200
124
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
125
+ expect( body.join ).to eq '{}'
126
+ end
127
+
128
+ it 'reports "pretty" health-checks on health path' do
129
+ env = { 'PATH_INFO'=> '/custom', 'QUERY_STRING' => 'pretty' }
130
+ status, headers, body = subject.call( env )
131
+ expect( status ).to eq 200
132
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
133
+ expect( body.join.gsub( /\s/m, '' ) ).to eq '{}'
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/health'
4
+ require 'leafy/json/health_writer'
5
+ require 'yaml'
6
+ require 'json'
7
+
8
+ describe Leafy::Json::HealthWriter do
9
+
10
+ subject { Leafy::Json::HealthWriter.new }
11
+
12
+ let( :health ) do
13
+ m = Leafy::Health::Registry.new
14
+ m.register( 'one' ) do
15
+ 'error'
16
+ end
17
+ m.register( 'two' ) do |ctx|
18
+ ctx.healthy 'ok'
19
+ end
20
+ m.register( 'three' ) do |ctx|
21
+ ctx.unhealthy 'no ok'
22
+ end
23
+ m.health
24
+ end
25
+
26
+ let( :expected ) do
27
+ {
28
+ "one"=> {"healthy"=>false, "message"=>"error"},
29
+ "three"=>{"healthy"=>false, "message"=>"no ok"},
30
+ "two"=>{"healthy"=>true, "message"=>"ok"}
31
+ }
32
+ end
33
+
34
+ it 'serializes health-check data to json' do
35
+ data = subject.to_json( health.run_health_checks )
36
+ expect( data.count( "\n" ) ).to eq 0
37
+ data = JSON.parse( data )
38
+ expect( data.to_yaml ).to eq expected.to_yaml
39
+ end
40
+
41
+ it 'serializes health-check data to json (pretty print)' do
42
+ data = subject.to_json( health.run_health_checks, true )
43
+ expect( data.count( "\n" ) ).to eq 13
44
+ data = JSON.parse( data )
45
+ expect( data.to_yaml ).to eq expected.to_yaml
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/rack/instrumented'
4
+
5
+ describe Leafy::Rack::Instrumented do
6
+
7
+ subject { Leafy::Rack::Instrumented.new( app, instrumented ) }
8
+
9
+ let( :instrumented ) { Leafy::Instrumented::Instrumented.new( registry, "name" ) }
10
+
11
+ let( :registry ) { Leafy::Metrics::Registry.new }
12
+
13
+ let( :status ) { (Random.rand * 500 + 100).to_i }
14
+
15
+ let( :random ) { Random.rand.to_s }
16
+
17
+ let( :app ) do
18
+ Proc.new do
19
+ [ status, {}, [ random ] ]
20
+ end
21
+ end
22
+
23
+ it "collects metrics for a call and pass result on" do
24
+ result, _, body = subject.call( {} )
25
+ expect( result ).to eq status
26
+ expect( body.join ).to eq random
27
+
28
+ expect( registry.metrics.timers.keys ).to eq [ 'name.requests' ]
29
+ expect( registry.metrics.timers.values.first.mean_rate ).to be > 0.09
30
+
31
+ expect( registry.metrics.counters.keys ).to eq [ 'name.active_requests' ]
32
+ expect( registry.metrics.counters.values.collect { |a| a.count } ).to eq [ 0 ]
33
+
34
+ expect( registry.metrics.meters.values.select{ |a| a.count == 0 }.size ).to eq 7
35
+ expect( registry.metrics.meters.values.select{ |a| a.count == 1 }.size ).to eq 1
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/instrumented/instrumented'
4
+
5
+ describe Leafy::Instrumented::Instrumented do
6
+
7
+ subject { Leafy::Instrumented::Instrumented.new( registry, "name" ) }
8
+
9
+ let( :registry ) { Leafy::Metrics::Registry.new }
10
+
11
+ [ 400, 201, 204, 404, 200, 123, 205, 500 ].each_with_index do |status, index|
12
+ it "collects metrics for a call for status #{status}" do
13
+ result, _, _ = subject.call do
14
+ sleep 0.01
15
+ [ status, nil, nil ]
16
+ end
17
+
18
+ expect( result ).to eq status
19
+
20
+ expect( registry.metrics.timers.keys ).to eq [ 'name.requests' ]
21
+ expect( registry.metrics.timers.values.first.mean_rate ).to be > 0.09
22
+
23
+ expect( registry.metrics.counters.keys ).to eq [ 'name.active_requests' ]
24
+ expect( registry.metrics.counters.values.collect { |a| a.count } ).to eq [ 0 ]
25
+
26
+ expect( registry.metrics.meters.keys.sort ).to eq [ 'name.responseCodes.badRequest', 'name.responseCodes.created', 'name.responseCodes.noContent', 'name.responseCodes.notFound', 'name.responseCodes.ok', 'name.responseCodes.other', 'name.responseCodes.resetContent', 'name.responseCodes.serverError' ]
27
+
28
+ stati = registry.metrics.meters.values.collect { |a| a.count }
29
+ expect( stati[ index ] ).to eq 1
30
+ stati.delete 1
31
+ expect( stati ).to eq [0,0,0,0,0,0,0]
32
+
33
+ expect( registry.metrics.meters.values.to_a[ index ].mean_rate ).to be > 50
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,110 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/rack/metrics'
4
+ require 'yaml'
5
+ require 'json'
6
+
7
+ describe Leafy::Rack::Metrics do
8
+
9
+ subject { Leafy::Rack::Metrics }
10
+
11
+ let( :registry ) { Leafy::Metrics::Registry.new }
12
+
13
+ let( :expected_headers ) do
14
+ { 'Content-Type' => 'application/json',
15
+ 'Cache-Control' => 'must-revalidate,no-cache,no-store' }
16
+ end
17
+ let( :report ) do
18
+ { 'version' => '3.0.0',
19
+ 'gauges' => {},
20
+ 'counters' => {},
21
+ 'histograms' => {},
22
+ 'meters' => {},
23
+ 'timers' => {}
24
+ }
25
+ end
26
+
27
+ let( :result ){ [ 200, nil, [] ] }
28
+ let( :app ) do
29
+ Proc.new() { result }
30
+ end
31
+
32
+ it 'has response' do
33
+ status, headers, body = subject.response( registry.metrics, {} )
34
+ expect( status ).to eq 200
35
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
36
+ expect( body.join.count( "\n" ) ).to eq 0
37
+ body = JSON.parse( body.join )
38
+ expect( body.to_yaml ).to eq report.to_yaml
39
+ end
40
+
41
+ it 'has pretty response' do
42
+ status, headers, body = subject.response( registry.metrics,
43
+ { 'QUERY_STRING' => 'pretty' } )
44
+ expect( status ).to eq 200
45
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
46
+ expect( body.join.count( "\n" ) ).to eq 7
47
+ body = JSON.parse( body.join )
48
+ expect( body.to_yaml ).to eq report.to_yaml
49
+ end
50
+
51
+ describe 'default path' do
52
+ subject { Leafy::Rack::Metrics.new( app, registry ) }
53
+
54
+ it 'passes request if not matches the given path' do
55
+ env = { 'PATH_INFO'=> '/something' }
56
+ expect( subject.call( env ) ).to eq result
57
+ end
58
+
59
+ it 'reports metricss on metrics path' do
60
+ env = { 'PATH_INFO'=> '/metrics' }
61
+ status, headers, body = subject.call( env )
62
+ expect( status ).to eq 200
63
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
64
+ expect( body.join.count( "\n" ) ).to eq 0
65
+ body = JSON.parse(body.join)
66
+ expect( body.to_yaml ).to eq report.to_yaml
67
+ end
68
+
69
+ it 'reports "pretty" health-checks on health path' do
70
+ env = { 'PATH_INFO'=> '/metrics', 'QUERY_STRING' => 'pretty' }
71
+ status, headers, body = subject.call( env )
72
+ expect( status ).to eq 200
73
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
74
+ expect( body.join.count( "\n" ) ).to eq 7
75
+ body = JSON.parse(body.join)
76
+ expect( body.to_yaml ).to eq report.to_yaml
77
+ end
78
+ end
79
+
80
+ describe 'custom path' do
81
+ subject { Leafy::Rack::Metrics.new( app, registry, '/custom' ) }
82
+
83
+ it 'passes request if not matches the given path' do
84
+ env = { 'PATH_INFO'=> '/something' }
85
+ expect( subject.call( env ) ).to eq result
86
+ env = { 'PATH_INFO'=> '/metrics' }
87
+ expect( subject.call( env ) ).to eq result
88
+ end
89
+
90
+ it 'reports metricss on metrics path' do
91
+ env = { 'PATH_INFO'=> '/custom' }
92
+ status, headers, body = subject.call( env )
93
+ expect( status ).to eq 200
94
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
95
+ expect( body.join.count( "\n" ) ).to eq 0
96
+ body = JSON.parse(body.join)
97
+ expect( body.to_yaml ).to eq report.to_yaml
98
+ end
99
+
100
+ it 'reports "pretty" health-checks on health path' do
101
+ env = { 'PATH_INFO'=> '/custom', 'QUERY_STRING' => 'pretty' }
102
+ status, headers, body = subject.call( env )
103
+ expect( status ).to eq 200
104
+ expect( headers.to_yaml).to eq expected_headers.to_yaml
105
+ expect( body.join.count( "\n" ) ).to eq 7
106
+ body = JSON.parse(body.join)
107
+ expect( body.to_yaml ).to eq report.to_yaml
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,55 @@
1
+ require_relative 'setup'
2
+
3
+ require 'leafy/metrics'
4
+ require 'leafy/json/metrics_writer'
5
+ require 'yaml'
6
+ require 'json'
7
+
8
+ describe Leafy::Json::MetricsWriter do
9
+
10
+ subject { Leafy::Json::MetricsWriter.new }
11
+
12
+ let( :metrics ) do
13
+ m = Leafy::Metrics::Registry.new
14
+ m.register_meter( 'one' ).mark
15
+ m.register_meter( 'two' ).mark
16
+ c = m.register_counter( 'three' )
17
+ c.inc
18
+ c.inc
19
+ m.metrics
20
+ end
21
+
22
+ let( :expected ) do
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
+ "one"=> {"count"=>1,
30
+ "m15_rate"=>0.0,
31
+ "m1_rate"=>0.0,
32
+ "m5_rate"=>0.0,
33
+ "units"=>"events/second"},
34
+ "three"=>{"count"=>2}
35
+ }
36
+ end
37
+
38
+ it 'serializes metrics data to json' do
39
+ data = subject.to_json( metrics.metrics )
40
+ expect( data.count( "\n" ) ).to eq 0
41
+ data = JSON.parse( data )
42
+ expect( data['one'].delete('mean_rate') ).to be >0
43
+ expect( data['two'].delete('mean_rate') ).to be >0
44
+ expect( data.to_yaml ).to eq expected.to_yaml
45
+ end
46
+
47
+ it 'serializes metrics data to json (pretty print)' do
48
+ data = subject.to_json( metrics.metrics, true )
49
+ expect( data.count( "\n" ) ).to eq 20
50
+ data = JSON.parse( data )
51
+ expect( data['one'].delete('mean_rate') ).to be >0
52
+ expect( data['two'].delete('mean_rate') ).to be >0
53
+ expect( data.to_yaml ).to eq expected.to_yaml
54
+ end
55
+ end