heartcheck 1.1.1 → 1.2.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: 9a0385acab4ad534fe832cce7bf5c71f57b47198
4
- data.tar.gz: fa2682576abb2682ac60a4b340f1d8b6973f2f51
3
+ metadata.gz: b17fc88fd50dfea485ff96d9f9d314375ff664b0
4
+ data.tar.gz: 46db26bfe137aa053541db83898851eb2c185c54
5
5
  SHA512:
6
- metadata.gz: 7a4f9319a3f089204cca1b0366bce4a56b5393bca77ee03210c20f66cf2c5b311fc053f05261453bc0df26ca8471bf556e2c858efa455b7993fc8470ad5928d9
7
- data.tar.gz: 9f4099e88f9ea59a7be59290dc4e421beeff4a96e342a4dea35b20368fc6d21b2d5dedc5a5149fb451b60ab966891fb5fd4a0e8350cf85df7390fabfbedcbd5c
6
+ metadata.gz: d2324c1926ddd007de9a191ad376292103f0d60c7a96b36c9e9bc745640ff21e595466cb9f3438faf8b7d4a6126bc8ca2a02d7cc426de8346ef0a4e44b1f05de
7
+ data.tar.gz: 77074aa4e162a259b22f840637562ba392af6a4a4b6c54dd567cadf5fc1dfab6252f2e01780a48740b09294a91ba593596a7288d2005c1f923725b9738a76ea6
data/.travis.yml CHANGED
@@ -16,3 +16,5 @@ matrix:
16
16
  gemfile: Gemfile-old-ruby
17
17
  - rvm: "2.2.2"
18
18
  - rvm: "2.3.0"
19
+ - rvm: "2.3.3"
20
+ - rvm: "2.4.1"
data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
1
  = Heart Check - Changelog
2
2
 
3
+ == Version 1.2.0 :: 2017-03-30
4
+
5
+ * Adds a caching plug
6
+
3
7
  == Version 1.0.0 :: 2015-02-02
4
8
 
5
9
  * Inital release.
data/LICENSE.txt CHANGED
@@ -1,20 +1,19 @@
1
- Copyright 2015 Locaweb
1
+ Copyright (c) 2015-2016 Locaweb
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
10
9
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
13
12
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md CHANGED
@@ -1,90 +1,89 @@
1
- Heartcheck
2
- ==============
3
-
1
+ # Heartcheck
2
+
3
+ Heartcheck is a monitoring tool for Rack applications. It provides a DSL to
4
+ declare service checks and an URI that returns the status for each service.
5
+ With this gem you can monitor if your app has access to the database, a cache
6
+ service, an API, etc.
7
+
4
8
  [![Build Status](https://travis-ci.org/locaweb/heartcheck.svg)](https://travis-ci.org/locaweb/heartcheck)
5
- [![Code Climate](https://codeclimate.com/github/locaweb/heartcheck/badges/gpa.svg)](https://codeclimate.com/github/locaweb/heartcheck)
6
-
7
- Check your applications' heart.
8
-
9
- About
10
- -----
11
-
12
- ### Endpoint JSON
13
- https://github.com/locaweb/heartcheck/wiki/Endpoint-Json
14
-
15
- ## How to setup
16
-
17
- 1. Include the gem in your Gemfile:
18
-
19
- ```
20
- gem 'heartcheck'
21
- ```
22
-
23
- 2. Install the gem:
24
-
25
- ```
26
- bundle install
27
- ```
28
-
29
- 3. Generate some required files according to the framework you are using:
30
-
31
- ```
32
- heartcheck rails
33
- heartcheck padrino
34
- heartcheck sinatra
35
- ```
36
-
37
- 4. After that, follow the instructions, edit the generated files and restart your server.
38
-
39
- 5. Done! Now you are able to access `[host]/monitoring` and check the monitoring JSON!
40
-
41
- ## Routes
42
- * `[host]/monitoring`
43
- * To check if the app and its integrations are avaiable;
44
- * Directed for verifying the app SLA;
45
- * `[host]/monitoring/info`
46
- * To view some informations that you can configure;
47
- * Directed for availability check from load balanced and get info about the installed app;
48
- * `[host]/monitoring/functional`
49
- * To check if the app is healty (no async job failed and other checks that aren't related to app availability);
50
- * Directed for verifying consistency problems within the app;
51
- * `[host]/monitoring/dev`
52
- * Directed for the development team;
53
- * It's run the essential and functional checks;
54
- * `[host]/monitoring/health_check`
55
- * To check if the app is up and running
56
-
57
- ## How to use
58
-
59
- You can see how to use in [template](https://github.com/locaweb/heartcheck/blob/master/lib/heartcheck/generators/templates/config.rb) that is generated when install:
9
+ [![Code Climate](https://codeclimate.com/github/locaweb/heartcheck/badges/gpa.svg)](https://codeclimate.com/github/locaweb/heartcheck)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'heartcheck'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install heartcheck
26
+
27
+ ## Usage
28
+
29
+ First generate the config file for the framework you are using:
30
+
31
+ $ heartcheck rails
32
+ $ heartcheck padrino
33
+ $ heartcheck sinatra
34
+
35
+ Then edit the generated file by adding your checks on it and restart your
36
+ server. Now you should be able to make a HTTP request for `/monitoring` and
37
+ get a JSON response that contains the status for each monitored service.
38
+
39
+ ## HTTP Routes
40
+
41
+ #### Basic health check
42
+
43
+ To get the status for all services, make a HTTP request for the following URI:
60
44
 
45
+ /monitoring
46
+
47
+ It will return a JSON response and a status for each service.
48
+
49
+ #### Functional status
50
+
51
+ Functional services are services essential for your application. You can get
52
+ their status using the following route:
53
+
54
+ /monitoring/functional
55
+
56
+ #### Info route
57
+
58
+ This route returns custom information about your app. You can configure it to
59
+ return whatever information you want:
60
+
61
+ /monitoring/info
62
+
63
+ #### Dev status
64
+
65
+ Returns some debugging information:
66
+
67
+ /monitoring/dev
68
+
69
+ #### Very basic health check
70
+
71
+ Returns a simple `ok` if the app is running. It does not execute any configured
72
+ checks:
73
+
74
+ /monitoring/health_check
61
75
 
62
76
  ## Plugins
77
+
63
78
  * [ActiveRecord](https://github.com/locaweb/heartcheck-activerecord)
64
79
  * [Cache](https://github.com/locaweb/heartcheck-cache)
65
80
  * [Cas](https://github.com/locaweb/heartcheck-cas)
66
81
  * [Redis](https://github.com/locaweb/heartcheck-redis)
67
82
  * [Resque](https://github.com/locaweb/heartcheck-resque)
68
83
  * [Sidekiq](https://github.com/locaweb/heartcheck-sidekiq)
69
- * [Webservice](https://github.com/locaweb/heartcheck-webservice)
70
-
71
- ## Git tags
72
-
73
- Don't forget to tag your work! After a merge request being accepted, run:
74
-
75
- 1 - (git tag -a "x.x.x" -m "") to create the new tag.
76
- 2 - (git push origin "x.x.x") to push the new tag to remote.
77
-
78
- Follow the RubyGems conventions at http://docs.rubygems.org/read/chapter/7 to know how to increment the version number. Covered in more detail in http://semver.org/
79
-
80
- ## Merge requests acceptance
81
-
82
- Don't forget to write tests to all your code. It's very important to maintain the codebase's sanity. Any merge request that doesn't have enough test coverage will be asked a revision
83
-
84
- ## Contributing
85
-
86
- 1. Fork it
87
- 2. Create your feature branch (`git checkout -b my-new-feature`)
88
- 3. Commit your changes (`git commit -am 'Added some feature'`)
89
- 4. Push to the branch (`git push origin my-new-feature`)
90
- 5. Create new Pull Request
84
+ * [Webservice](https://github.com/locaweb/heartcheck-webservice)
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at
89
+ https://github.com/locaweb/heartcheck.
data/heartcheck.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = Heartcheck::VERSION
8
8
  spec.authors = ['Locaweb']
9
9
  spec.email = ['desenvolvedores@locaweb.com.br']
10
- spec.homepage = 'http://developer.locaweb.com.br'
10
+ spec.homepage = 'http://github.com/locaweb/heartcheck/'
11
11
  spec.summary = 'A simple way to check if your app is runnig like as expected.'
12
12
  spec.description = 'A simple way to check your app heart.'
13
13
  spec.license = 'MIT'
data/lib/heartcheck.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Heartcheck
2
2
  require 'logger'
3
3
  require 'heartcheck/app'
4
+ require 'heartcheck/caching_app'
4
5
  require 'heartcheck/checks'
5
6
  require 'heartcheck/executors'
6
7
  require 'heartcheck/errors'
@@ -102,11 +103,10 @@ module Heartcheck
102
103
  @executor ||= Heartcheck::Executors::Base.new
103
104
  end
104
105
 
105
-
106
106
  # change current executor to a threaded implementation
107
107
  # requires 'concurrent-ruby'
108
108
  #
109
- # @return [Hearcheck::Executors::Threaded]
109
+ # @return [Heartcheck::Executors::Threaded]
110
110
  def use_threaded_executor!
111
111
  require "concurrent"
112
112
  require "heartcheck/executors/threaded"
@@ -0,0 +1,48 @@
1
+ require 'heartcheck/caching_app/cache'
2
+
3
+ # A rack middleware to wrap around {Heartcheck::App} in a cache
4
+ # Mount an instance of this class passing an app or `use` this in Rack.
5
+ # This accepts an optional ttl for the cache that defaults to 300 seconds.
6
+ module Heartcheck
7
+ class CachingApp
8
+ # Creates an instance of the middleware
9
+ #
10
+ # @param app [Heartcheck:App] the Rack app to wrap around
11
+ # @param ttl [Integer] the time to cache the results in seconds
12
+ # @param cache [Heartcheck::CachingApp::Cache] the cache instance to use
13
+ # The cache will be created on first use if not supplied
14
+ #
15
+ # @return [#call] rack compatible middleware
16
+ def initialize(app, ttl = 300, cache = nil)
17
+ @app = app
18
+ @ttl = ttl
19
+ @cache = cache
20
+ end
21
+
22
+ # Invokes the middleware
23
+ #
24
+ # @param env [Hash] the rack request/environment
25
+ # @return [Array] a rack compatible response
26
+ def call(env)
27
+ req = Rack::Request.new(env)
28
+ controller = Heartcheck::App::ROUTE_TO_CONTROLLER[req.path_info]
29
+
30
+ if controller && (result = cache.result(controller))
31
+ [200, { 'Content-type' => 'application/json' }, [result]]
32
+ else
33
+ @app.call(env)
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def cache
40
+ @cache ||= start_cache(@ttl)
41
+ end
42
+
43
+ def start_cache(ttl)
44
+ Heartcheck::CachingApp::Cache.new(Heartcheck::App::ROUTE_TO_CONTROLLER
45
+ .values.uniq, ttl).tap(&:start)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,65 @@
1
+ require 'concurrent'
2
+
3
+ module Heartcheck
4
+ class CachingApp
5
+ # This cache performs the given controllers in background threads.
6
+ # The public interface always queries the results from the cache.
7
+ #
8
+ # @param executor [Array<Class>] the collection controllers classes to cache
9
+ # @param ttl [Integer] the cache ttl in seconds
10
+ #
11
+ # @return [Heartcheck::CachingApp::Cache]
12
+ class Cache
13
+ attr_accessor :concurrent_opts
14
+
15
+ def initialize(controllers, ttl)
16
+ @results = Concurrent::Map.new
17
+ @controllers = controllers
18
+ @ttl = ttl
19
+ @concurrent_opts = {}
20
+ end
21
+
22
+ # Fetches the current result for the given controller
23
+ #
24
+ # @param controller [Class] the controller to fetch the current result of
25
+ #
26
+ # @return [String] the result of the index action
27
+ def result(controller)
28
+ @results[controller]
29
+ end
30
+
31
+ def start
32
+ schedule(@ttl, &perform_all_controllers)
33
+ end
34
+
35
+ protected
36
+
37
+ def perform_controller(controller)
38
+ proc do
39
+ Logger.info("Start [#{controller}] for caching at #{Time.now}")
40
+ @results[controller] = controller.new.index
41
+ Logger.info("End [#{controller}]\n")
42
+ end
43
+ end
44
+
45
+ def perform_all_controllers
46
+ proc do
47
+ Logger.info("performing all #{@controllers.length} checks")
48
+
49
+ tasks = @controllers.map do |controller|
50
+ schedule(0, &perform_controller(controller))
51
+ end
52
+
53
+ # wait for all tasks to complete before scheduling next run
54
+ tasks.map(&:value)
55
+
56
+ schedule(@ttl, &perform_all_controllers)
57
+ end
58
+ end
59
+
60
+ def schedule(ttl, &block)
61
+ Concurrent::ScheduledTask.execute(ttl, concurrent_opts, &block)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -119,6 +119,14 @@ module Heartcheck
119
119
  end
120
120
  end
121
121
 
122
+ # Returns a human-readable representation of the check
123
+ #
124
+ # @return [String]
125
+ def inspect
126
+ "#<#{self.class.name} name: #{name}, functional: #{functional?}, dev: #{dev?}>"
127
+ end
128
+
129
+
122
130
  def informations
123
131
  info
124
132
  rescue => e
@@ -25,15 +25,29 @@ module Heartcheck
25
25
  when 'rails'
26
26
  instructions(
27
27
  'config/routes.rb',
28
- 'mount Heartcheck::App.new, at: "/monitoring"'
28
+ [
29
+ 'mount Heartcheck::App.new, at: "/monitoring"',
30
+ '',
31
+ '# to mount a caching instance:',
32
+ '# mount Heartcheck::CachingApp.new(HeartCheck::App.new, 300),',
33
+ '# at: "/cached-monitoring" # 300 is the optional cache TTL'
34
+ ].join("\n")
29
35
  )
30
36
  when 'padrino', 'sinatra'
31
37
  instructions(
32
- 'config.ru', %(require "heartcheck"
33
- map "/monitoring" do
34
- use Heartcheck::App
35
- end)
36
- )
38
+ 'config.ru', [
39
+ 'require "heartcheck"',
40
+ '',
41
+ 'map "/monitoring" do',
42
+ ' use Heartcheck::App',
43
+ 'end',
44
+ '',
45
+ '# or a cached instance:',
46
+ '# map "/cached/monitoring" do',
47
+ '# use Heartcheck::CachingApp, 300 # 300 is the optional ttl',
48
+ '# use Heartcheck::App',
49
+ '# end',
50
+ ].join("\n"))
37
51
  end
38
52
  end
39
53
 
@@ -1,3 +1,3 @@
1
1
  module Heartcheck
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heartcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Locaweb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -194,6 +194,8 @@ files:
194
194
  - heartcheck.gemspec
195
195
  - lib/heartcheck.rb
196
196
  - lib/heartcheck/app.rb
197
+ - lib/heartcheck/caching_app.rb
198
+ - lib/heartcheck/caching_app/cache.rb
197
199
  - lib/heartcheck/checks.rb
198
200
  - lib/heartcheck/checks/base.rb
199
201
  - lib/heartcheck/checks/firewall.rb
@@ -218,7 +220,7 @@ files:
218
220
  - lib/heartcheck/services.rb
219
221
  - lib/heartcheck/services/firewall.rb
220
222
  - lib/heartcheck/version.rb
221
- homepage: http://developer.locaweb.com.br
223
+ homepage: http://github.com/locaweb/heartcheck/
222
224
  licenses:
223
225
  - MIT
224
226
  metadata: {}
@@ -238,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
240
  version: '0'
239
241
  requirements: []
240
242
  rubyforge_project:
241
- rubygems_version: 2.4.5.1
243
+ rubygems_version: 2.5.1
242
244
  signing_key:
243
245
  specification_version: 4
244
246
  summary: A simple way to check if your app is runnig like as expected.