leafy-rack 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 -8
  6. data/README.md +10 -148
  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/leafy-health/Rakefile +14 -0
  29. data/leafy-health/leafy-health.gemspec +27 -0
  30. data/leafy-health/lib/leafy-health.rb +2 -0
  31. data/leafy-health/lib/leafy-health_jars.rb +7 -0
  32. data/leafy-health/lib/leafy/health.rb +2 -0
  33. data/leafy-health/lib/leafy/health/health_check.rb +72 -0
  34. data/leafy-health/lib/leafy/health/registry.rb +55 -0
  35. data/leafy-health/lib/leafy/health/version.rb +6 -0
  36. data/leafy-health/spec/registry_spec.rb +164 -0
  37. data/leafy-health/spec/setup.rb +1 -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/{Rakefile → leafy-logger/Rakefile} +0 -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.gemspec → leafy-rack/leafy-rack.gemspec} +2 -2
  82. data/{lib → leafy-rack/lib}/leafy-rack.rb +0 -0
  83. data/{lib → leafy-rack/lib}/leafy-rack_jars.rb +0 -0
  84. data/{lib → leafy-rack/lib}/leafy/instrumented/basic_instrumented.rb +0 -0
  85. data/{lib → leafy-rack/lib}/leafy/instrumented/instrumented.rb +0 -0
  86. data/{lib → leafy-rack/lib}/leafy/json/health_writer.rb +0 -0
  87. data/{lib → leafy-rack/lib}/leafy/json/json_writer.rb +0 -0
  88. data/{lib → leafy-rack/lib}/leafy/json/metrics_writer.rb +0 -0
  89. data/{lib → leafy-rack/lib}/leafy/rack.rb +0 -0
  90. data/{lib → leafy-rack/lib}/leafy/rack/admin.rb +0 -0
  91. data/{lib → leafy-rack/lib}/leafy/rack/health.rb +0 -0
  92. data/{lib → leafy-rack/lib}/leafy/rack/instrumented.rb +0 -0
  93. data/{lib → leafy-rack/lib}/leafy/rack/metrics.rb +0 -0
  94. data/{lib → leafy-rack/lib}/leafy/rack/ping.rb +0 -0
  95. data/{lib → leafy-rack/lib}/leafy/rack/thread_dump.rb +0 -0
  96. data/{lib → leafy-rack/lib}/leafy/rack/version.rb +1 -1
  97. data/{spec → leafy-rack/spec}/admin_rack_spec.rb +0 -0
  98. data/{spec → leafy-rack/spec}/basic_instrumented_spec.rb +0 -0
  99. data/{spec → leafy-rack/spec}/health_rack_spec.rb +0 -0
  100. data/{spec → leafy-rack/spec}/health_writer_spec.rb +0 -0
  101. data/{spec → leafy-rack/spec}/instrumented_rack_spec.rb +0 -0
  102. data/{spec → leafy-rack/spec}/instrumented_spec.rb +0 -0
  103. data/{spec → leafy-rack/spec}/metrics_rack_spec.rb +0 -0
  104. data/{spec → leafy-rack/spec}/metrics_writer_spec.rb +0 -0
  105. data/{spec → leafy-rack/spec}/ping_rack_spec.rb +0 -0
  106. data/{spec → leafy-rack/spec}/setup.rb +0 -0
  107. data/{spec → leafy-rack/spec}/thread_dump_spec.rb +0 -0
  108. metadata +110 -34
@@ -0,0 +1,44 @@
1
+ # show case for leafy gems
2
+
3
+ get all the gems in place
4
+
5
+ gem install jar-dependencies --development
6
+ bundle install
7
+
8
+ ## starting the server
9
+
10
+ ### with jetty
11
+
12
+ rmvn jetty:run
13
+
14
+ the urls:
15
+
16
+ [http://localhost:8080/app](http://localhost:8080/app)
17
+ [http://localhost:8080/admin](http://localhost:8080/admin)
18
+
19
+ ### with tomcat or wildfly
20
+
21
+ rmvn tomcat:run
22
+ rmvn wildfly:run
23
+
24
+ the urls:
25
+
26
+ [http://localhost:8080/hellowarld/app](http://localhost:8080/hellowarld/app)
27
+ [http://localhost:8080/hellowarld/admin](http://localhost:8080/hellowarld/admin)
28
+
29
+ ## configurations
30
+
31
+ * Mavenfile
32
+ * WEB-INF/web.xml
33
+
34
+ ## run some integration test
35
+
36
+ rmvn verify
37
+
38
+ or
39
+
40
+ rake
41
+
42
+ with jruby-9k due to some bundler bug you need to run (not needed with rvm)
43
+
44
+ BUNDLE_DISABLE_SHARED_GEMS=true rake
@@ -0,0 +1,13 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ require 'maven/ruby/maven'
4
+
5
+ task :default do
6
+ mvn = Maven::Ruby::Maven.new
7
+ mvn.property 'jruby.version', JRUBY_VERSION
8
+ if mvn.verify
9
+ puts "\n\ndone ok\n\n"
10
+ else
11
+ raise "\n\nintegration test failed\n\n"
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE web-app PUBLIC
2
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
4
+ <web-app>
5
+ <context-param>
6
+ <param-name>public.root</param-name>
7
+ <param-value>/</param-value>
8
+ </context-param>
9
+ <context-param>
10
+ <param-name>rack.env</param-name>
11
+ <param-value>production</param-value>
12
+ </context-param>
13
+ <!-- needed for wildfly -->
14
+ <context-param>
15
+ <param-name>gem.path</param-name>
16
+ <param-value>WEB-INF/classes</param-value>
17
+ </context-param>
18
+
19
+ <filter>
20
+ <filter-name>RackFilter</filter-name>
21
+ <filter-class>org.jruby.rack.RackFilter</filter-class>
22
+ </filter>
23
+ <filter-mapping>
24
+ <filter-name>RackFilter</filter-name>
25
+ <url-pattern>/*</url-pattern>
26
+ </filter-mapping>
27
+
28
+ <listener>
29
+ <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
30
+ </listener>
31
+ </web-app>
@@ -0,0 +1,55 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'ostruct'
4
+ require 'leafy/metrics'
5
+ require 'leafy/health'
6
+ require 'leafy/instrumented/instrumented'
7
+ require 'leafy/rack/admin'
8
+ require 'leafy/rack/instrumented'
9
+
10
+ data = OpenStruct.new
11
+ data.surname = 'meier'
12
+ data.firstname = 'christian'
13
+
14
+ configure do
15
+ metrics = Leafy::Metrics::Registry.new
16
+ health = Leafy::Health::Registry.new
17
+
18
+ use Leafy::Rack::Admin, metrics, health
19
+ use Leafy::Rack::Metrics, metrics
20
+ use Leafy::Rack::Health, health
21
+ use Leafy::Rack::Ping
22
+ use Leafy::Rack::ThreadDump
23
+ use Leafy::Rack::Instrumented, Leafy::Instrumented::Instrumented.new( metrics, 'webapp' )
24
+
25
+ metrics.register_gauge('app.data_length' ) do
26
+ data.surname.length + data.firstname.length
27
+ end
28
+
29
+ health.register( 'app.health' ) do
30
+ if data.surname.length + data.firstname.length < 4
31
+ "stored names are too short"
32
+ end
33
+ end
34
+
35
+ set :histogram, metrics.register_histogram( 'app.name_length' )
36
+ end
37
+
38
+
39
+ get '/app' do
40
+ p @person = data
41
+ erb :person
42
+ end
43
+
44
+ get '/person' do
45
+ p @person = data
46
+ content_type 'application/json'
47
+ { :surname => data.surname, :firstname => data.firstname }.to_json
48
+ end
49
+
50
+ patch '/person' do
51
+ payload = JSON.parse request.body.read
52
+ data.send :"#{payload.keys.first}=", payload.values.first
53
+ settings.histogram.update( data.surname.length + data.firstname.length )
54
+ status 205
55
+ end
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @person.firstname %> <%= @person.surname %></title>
5
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
6
+ <script>
7
+
8
+ $(document).ready(function(){
9
+
10
+ $("#reload").click(function(){
11
+ $.getJSON("person", function(result) {
12
+ $("title").text(result.firstname + " " + result.surname);
13
+ })
14
+ });
15
+
16
+ $("#firstname").last().click(function(){
17
+ $.ajax({ url:"person",
18
+ contentType:"application/json",
19
+ type:"PATCH",
20
+ data: '{"firstname":"' + $("#first").val() + '"}',
21
+ success:function(result){
22
+ }});
23
+ });
24
+
25
+ $("#surname").last().click(function(){
26
+ $.ajax({ url:"person",
27
+ contentType:"application/json",
28
+ type:"PATCH",
29
+ data: '{"surname":"' + $("#sur").val() + '"}',
30
+ success:function(result){
31
+ }});
32
+ });
33
+
34
+ });
35
+ </script>
36
+ </head>
37
+ <body>
38
+
39
+ <h1>person</h1>
40
+
41
+ <div>
42
+ Firstname <input type="text" size="30" id="first" value="<%=@person.firstname %>" /> <button id="firstname">update</button>
43
+ </div>
44
+
45
+ <div>
46
+ Surname <input type="text" size="30" id="sur" value="<%=@person.surname %>" /> <button id="surname">update</button>
47
+ </div>
48
+
49
+ <button id="reload">update title from server data</button>
50
+
51
+ </body>
52
+ </html>
@@ -0,0 +1,12 @@
1
+ #\ -s webrick
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
4
+ $LOAD_PATH.unshift($servlet_context.getRealPath("/WEB-INF")) if defined?($servlet_context)
5
+
6
+ require 'bundler/setup'
7
+
8
+ require 'app/hellowarld'
9
+
10
+ map '/' do
11
+ run Sinatra::Application
12
+ end
@@ -0,0 +1,22 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'leafy-complete'
5
+ s.version = '0.3.1'
6
+ s.author = 'Christian Meier'
7
+ s.email = [ 'christian.meier@lookout.com' ]
8
+
9
+ s.license = 'MIT'
10
+ s.summary = %q('meta' gem which pulls all the leafy gems)
11
+ s.homepage = 'https://github.com/lookout/leafy'
12
+ s.description = %q(this gem has no code only dependencies to all the other leafy gems. it is meant as convenient way to pull in all leafy gems in one go)
13
+
14
+ s.files = ['leafy-complete.gemspec', 'README.md', 'LICENSE']
15
+
16
+ s.add_runtime_dependency 'leafy-metrics', '~> 0.2.0'
17
+ s.add_runtime_dependency 'leafy-health', '~> 0.2.0'
18
+ s.add_runtime_dependency 'leafy-rack', '~> 0.2.0'
19
+ s.add_runtime_dependency 'leafy-logger', '~> 0.2.0'
20
+ end
21
+
22
+ # vim: syntax=Ruby
@@ -0,0 +1,4 @@
1
+ .yardoc
2
+ doc
3
+ pkg
4
+ *.lock
@@ -0,0 +1,7 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ # vim: syntax=Ruby
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Lookout
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,123 @@
1
+ # Leafy-Health
2
+
3
+ ## installation
4
+
5
+ via rubygems
6
+ ```
7
+ gem install leafy-health
8
+ ```
9
+ or add to your Gemfile
10
+ ```
11
+ gem 'leafy-health'
12
+ ```
13
+
14
+ installing the gem also takes care of the jar dependencies with jruby-1.7.16+
15
+
16
+ ## usage
17
+
18
+ an instance of the registry ```Leafy::Health::Registry``` can register and unresgister health-checks under a given name. any object with a #call method will do or block on the register method.
19
+
20
+ registry = Leafy::Health::Registry.new
21
+
22
+ you can ask the registry which names have already health-checks registered:
23
+
24
+ registry.names
25
+
26
+ ### simple health check
27
+
28
+ simple in the sense that either call returns ```nil``` which means healthy or a message which is the unhealthy state. the message can be any ```String```.
29
+
30
+ registry.register( 'simple.block') do
31
+ if app.crashed
32
+ 'application crashed'
33
+ end
34
+ end
35
+
36
+ or with a health-check object
37
+
38
+ class AppCheck < Leafy::Health::HealthCheck
39
+ def call
40
+ if app.crashed
41
+ 'application crashed'
42
+ end
43
+ end
44
+ end
45
+ registry.register( 'simple.class', AppCheck.new )
46
+
47
+ ### health checks with message on healthy state
48
+
49
+ here the call method gets an argument which allows to create both
50
+ healthy and unhealthy states with message.
51
+
52
+ registry.register( 'app.block') do
53
+ if app.crashed
54
+ unhealthy( 'application crashed' )
55
+ else
56
+ healthy( 'application ok' )
57
+ end
58
+ end
59
+
60
+ or with a health-check object
61
+
62
+ class AppCheck < Leafy::Health::HealthCheck
63
+ def call
64
+ if app.crashed
65
+ unhealthy( 'application crashed' )
66
+ else
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' )
91
+ end
92
+ end
93
+ end
94
+ registry.register( 'app.class', AppCheck.new )
95
+
96
+ ### unregister health checks
97
+
98
+ registry.unregister( 'app.class' )
99
+
100
+ ### builtin ThreadDeadlockHeathCheck
101
+
102
+ registry.register( 'app.deadlock', Leafy::Health::ThreadDeadlockHeathCheck.new )
103
+
104
+ ### note
105
+
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**
107
+
108
+ Leafy::Json::HealthWriter.to_json( registry.health )
109
+
110
+ ## developement
111
+
112
+ get all the gems and jars in place
113
+
114
+ gem install jar-dependencies --development
115
+ bundle install
116
+
117
+ for running all specs
118
+
119
+ rake
120
+
121
+ or
122
+
123
+ rspec spec/reporter_spec.rb
@@ -0,0 +1,14 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new
5
+
6
+ require "yard"
7
+ YARD::Rake::YardocTask.new do |t|
8
+ t.files = ['lib/**/*.rb']
9
+ t.options += ["--title", "Leafy Health API"]
10
+ end
11
+
12
+ task :default => [ :spec ]
13
+
14
+ # vim: syntax=Ruby
@@ -0,0 +1,27 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ require File.expand_path( '../lib/leafy/health/version', __FILE__ )
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'leafy-health'
7
+ s.version = Leafy::Health::VERSION
8
+ s.author = 'christian meier'
9
+ s.email = [ 'christian.meier@lookout.com' ]
10
+
11
+ s.license = 'MIT'
12
+ s.summary = %q(provides an API to register healthchecks)
13
+ s.homepage = 'https://github.com/lookout/leafy'
14
+ s.description = %q(provides an API to register healthchecks which uses dropwizrd-metrics-healthchecks)
15
+
16
+ s.files = `git ls-files`.split($/)
17
+
18
+ s.requirements << 'jar io.dropwizard.metrics:metrics-healthchecks, 3.1.0'
19
+ s.requirements << 'jar io.dropwizard.metrics:metrics-jvm, 3.1.0'
20
+
21
+ s.add_runtime_dependency 'jar-dependencies', '~> 0.1.8'
22
+ s.add_development_dependency 'rspec', '~> 3.1.0'
23
+ s.add_development_dependency 'yard', '~> 0.8.7'
24
+ s.add_development_dependency 'rake', '~> 10.2'
25
+ end
26
+
27
+ # vim: syntax=Ruby
@@ -0,0 +1,2 @@
1
+ require 'leafy-health_jars'
2
+ require 'leafy/health/registry'