mini_check 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,4 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 20ef9ea5afbc7e220b1e81163a628c15267ae813
4
- data.tar.gz: 5d4cdbf4c58aaa06595f0d3a7e239a3a8fee0de2
5
2
  SHA512:
6
- metadata.gz: e5c6612eb00859f651ac8c40caeda10379651e323dd88ab6ebbca6e15223ab9dc72c45aeae31995990284ecc39951b964c60d370377ac10c623aa3c8148d5f59
7
- data.tar.gz: 35521fa95e56d56b3ba71fd8dde9ac053a660369cba356c2909a6b7ab89fdd370b7215f68361f3e01d11f97bb2fd4f81a1f619f4965fa299f54165113b7c6a3d
3
+ metadata.gz: 83267501018ff124cfca7c5ba8c3744e0fe7ba9c5aea728ac4e0f45290726d71c35b2eec8d9943f60d8d25e5463e511f7081f3fe4fbb6cf08afbe4ed6b45af4b
4
+ data.tar.gz: a9eaa048760beafe2a288d36e02198457d696d47d9efc9f5f36c995b17fd840905529296fcbc9d4272f0867d4a0765836c415a1ab342712d30db272f4aa4f57d
@@ -4,7 +4,9 @@ rvm:
4
4
  - jruby-19mode
5
5
  - 2.0.0
6
6
  - 2.1.0
7
+ - 2.2.0
8
+ - 2.3.0
7
9
  cache: bundler
8
- addons:
9
- code_climate:
10
- repo_token: f85fa0b767dbe803b9dba53e89c729db785240245aac0e17f88462581596bc93
10
+ before_install:
11
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
12
+ - gem install bundler -v '< 2'
@@ -1,3 +1,22 @@
1
+ ## 0.4.1, release 2019-01-27
2
+
3
+ * Fixed broken build due Rake upgrade.
4
+ * Removed Code Climate as current implementation is being deprecated.
5
+ * Removed warning messages when running the tests.
6
+ * No code changes were made.
7
+
8
+ ## 0.4.0
9
+
10
+ * Times on checks and slight refactor
11
+
12
+ ## 0.3.0
13
+
14
+ * Extend gem to support mounting a new endpoint to provide versioning info.
15
+
16
+ ## 0.2.0
17
+
18
+ * Added support for middleware mounting.
19
+
1
20
  ## 0.1.1, release 2014-03-22
2
21
 
3
22
  * Supporting Travis CI and Code Climate
data/Gemfile CHANGED
@@ -4,8 +4,8 @@ gemspec
4
4
 
5
5
  group :test, :development do
6
6
  gem 'rake'
7
- gem 'rspec', '~> 2.14.0'
7
+ gem 'rspec', '~> 3.0'
8
8
  gem 'pry'
9
9
  gem 'rack-test'
10
- gem 'codeclimate-test-reporter', require: false
10
+ gem 'rack', '~> 1.0'
11
11
  end
data/README.md CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  MiniCheck provides a simple Rack application for adding simple health checks to your app.
4
4
  The JSON output is similar to the one provided by the [Metrics](http://metrics.codahale.com/) Java library.
5
- It was started at [Workshare ltd.](http://www.workshare.com) as an easy way of providing monitoring to our Rack based applciations.
5
+ It was started at [Workshare ltd.](http://www.workshare.com) as an easy way of providing monitoring to our Rack based applications.
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/mini_check.png)](http://badge.fury.io/rb/mini_check)
8
- [![Build Status](https://secure.travis-ci.org/workshare/mini-check.png)](http://travis-ci.org/workshare/mini-check)
9
- [![Code Climate](https://codeclimate.com/github/workshare/mini-check.png)](https://codeclimate.com/github/workshare/mini-check)
8
+ [![Build Status](https://secure.travis-ci.org/workshare/mini-check.png)](http://travis-ci.org/workshare/mini-check)
10
9
 
11
10
  ## Quick Start
12
11
 
@@ -31,10 +30,12 @@ If you now visit `http://localhost:XXXX/healthcheck` you should get something li
31
30
  ```json
32
31
  {
33
32
  "health.db_connection": {
34
- "healthy": true
33
+ "healthy": true,
34
+ "time": 0.111403303
35
35
  },
36
36
  "health.redis_client": {
37
- "healthy": true
37
+ "healthy": true,
38
+ "time": 4.41e-05
38
39
  }
39
40
  }
40
41
  ```
@@ -56,11 +57,13 @@ The registered lambdas should do any of the following things:
56
57
  "/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/adapters/mysql2.rb:77:in `block in _execute'",
57
58
  "/home/manuel/sd/my_app/vendor/bundle/ruby/1.9.1/gems/sequel-4.7.0/lib/sequel/database/logging.rb:37:in `log_yield'",
58
59
  "..."
59
- ]
60
+ ],
61
+ "time": 4.61e-05
60
62
  }
61
63
  },
62
64
  "health.redis_client": {
63
- "healthy": true
65
+ "healthy": true,
66
+ "time": 1.23e-04
64
67
  }
65
68
  }
66
69
  ```
@@ -96,7 +99,7 @@ If you now visit `http://localhost:XXXX/admin/version` you should get something
96
99
 
97
100
  ## Maintaining
98
101
 
99
- Here is a good tutorial on this:
102
+ Here is a good tutorial on this:
100
103
  [Developing a RubyGem using Bundler](https://github.com/radar/guides/blob/master/gem-development.md).
101
104
 
102
105
  ## License
@@ -1,8 +1,11 @@
1
+ require 'benchmark'
2
+
1
3
  module MiniCheck
2
4
  class Check
3
5
  attr_accessor :name
4
6
  attr_accessor :healthy
5
7
  attr_accessor :action
8
+ attr_accessor :time
6
9
  attr_accessor :exception
7
10
 
8
11
  def initialize args = {}, &block
@@ -17,24 +20,31 @@ module MiniCheck
17
20
  end
18
21
 
19
22
  def run
20
- begin
21
- self.healthy = action.call
22
- self.exception = nil
23
- rescue Exception => e
24
- self.healthy = false
25
- self.exception = e
26
- end
23
+ self.time = Benchmark.measure do
24
+ begin
25
+ do_run
26
+ self.exception = nil
27
+ rescue Exception => e
28
+ self.healthy = false
29
+ self.exception = e
30
+ end
31
+ end.real
27
32
  end
28
33
 
29
34
  def to_hash
30
35
  {}.tap do |h|
31
36
  h[:healthy] = healthy?
37
+ h[:time] = time
32
38
  h[:error] = error_hash if exception
33
39
  end
34
40
  end
35
41
 
36
42
  private
37
43
 
44
+ def do_run
45
+ self.healthy = action.call
46
+ end
47
+
38
48
  def error_hash
39
49
  {
40
50
  message: exception.message,
@@ -3,6 +3,11 @@ module MiniCheck
3
3
  attr_accessor :checks
4
4
  attr_accessor :path
5
5
 
6
+ CONTENT_TYPE_HEADER = 'Content-Type'.freeze
7
+ JSON_MIME_TYPE = 'application/json'.freeze
8
+ REQUEST_METHOD = 'REQUEST_METHOD'.freeze
9
+ PATH_INFO = 'PATH_INFO'.freeze
10
+
6
11
  def initialize args = {}
7
12
  set_attributes args
8
13
  end
@@ -12,10 +17,10 @@ module MiniCheck
12
17
  end
13
18
 
14
19
  def call env
15
- case "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
20
+ case "#{env[REQUEST_METHOD]} #{env[PATH_INFO]}"
16
21
  when "GET #{path}"
17
22
  checks.run
18
- [status, headers, [body]]
23
+ [status, default_headers, [body]]
19
24
  else
20
25
  host_app.call(env)
21
26
  end
@@ -26,23 +31,23 @@ module MiniCheck
26
31
  end
27
32
 
28
33
  def new(app)
29
- copy = self.dup
30
- copy.host_app = app
31
- copy
34
+ dup.tap do |copy|
35
+ copy.host_app = app
36
+ end
32
37
  end
33
38
 
34
39
  private
35
40
 
41
+ def default_headers
42
+ { CONTENT_TYPE_HEADER => JSON_MIME_TYPE }
43
+ end
44
+
36
45
  def set_attributes args = {}
37
46
  args.each do |k,v|
38
47
  send("#{k}=", v)
39
48
  end
40
49
  end
41
50
 
42
- def headers
43
- {'Content-Type' => 'application/json'}
44
- end
45
-
46
51
  def body
47
52
  checks.to_hash.to_json
48
53
  end
@@ -56,7 +61,7 @@ module MiniCheck
56
61
  attr_accessor :host_app
57
62
 
58
63
  def host_app
59
- @host_app ||= lambda{|env| [404, {}, []]}
64
+ @host_app ||= lambda { |env| [404, {}, []] }
60
65
  end
61
66
  end
62
67
  end
@@ -1,3 +1,3 @@
1
1
  module MiniCheck
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -4,16 +4,23 @@ module MiniCheck
4
4
  class VersionRackApp
5
5
  attr_accessor :path, :build_file
6
6
 
7
+ REQUEST_METHOD = 'REQUEST_METHOD'.freeze
8
+ PATH_INFO = 'PATH_INFO'.freeze
9
+ APP_KEY = 'Application Name'.freeze
10
+ CONTENT_TYPE_HEADER = 'Content-Type'.freeze
11
+ JSON_MIME_TYPE = 'application/json'.freeze
12
+ TEXT_MIME_TYPE = 'text/plain'.freeze
13
+
7
14
  def initialize args = {}
8
15
  set_attributes args
9
16
  end
10
-
17
+
11
18
  def metadata
12
19
  @metadata ||= Hash.new
13
20
  end
14
-
21
+
15
22
  def call env
16
- case "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
23
+ case "#{env[REQUEST_METHOD]} #{env[PATH_INFO]}"
17
24
  when "GET #{path}.json"
18
25
  JsonResponse.render(output_hash)
19
26
  when "GET #{path}"
@@ -33,7 +40,7 @@ module MiniCheck
33
40
  private
34
41
 
35
42
  def name= name
36
- metadata["Application Name"] = name
43
+ metadata[APP_KEY] = name
37
44
  end
38
45
 
39
46
  def set_attributes args = {}
@@ -41,47 +48,76 @@ module MiniCheck
41
48
  send("#{k}=", v)
42
49
  end
43
50
  end
44
-
51
+
45
52
  def output_hash
46
53
  metadata.merge(file_hash)
47
54
  end
48
-
55
+
49
56
  def file_hash
50
- if (content = YAML.load_file(build_file)).instance_of?(Hash)
57
+ if (content = file_content(build_file)).instance_of?(Hash)
51
58
  content
52
59
  else
53
- content = IO.read(build_file).split("\n")
60
+ content = raw_file_content(build_file).split("\n")
54
61
  Hash[content.map{ |pair| pair.split("=") }]
55
62
  end
56
63
  rescue => ex
57
64
  { error: ex.message }
58
65
  end
59
-
60
-
66
+
67
+ def self.file_content(build_file)
68
+ @file_content ||= YAML.load_file(build_file)
69
+ end
70
+
71
+ def self.raw_file_content(build_file)
72
+ @raw_file_content ||= IO.read(build_file)
73
+ end
74
+
75
+ def file_content(build_file)
76
+ self.class.file_content(build_file)
77
+ end
78
+
79
+ def raw_file_content(build_file)
80
+ self.class.raw_file_content(build_file)
81
+ end
82
+
61
83
  protected
62
84
 
63
85
  attr_accessor :host_app
64
86
 
65
87
  def host_app
66
- @host_app ||= lambda{|env| [404, {}, []]}
88
+ @host_app ||= lambda { |env| [404, {}, []] }
67
89
  end
68
-
69
-
90
+
91
+
70
92
  class JsonResponse
71
- def self.render hash
72
- [200, {'Content-Type' => 'application/json'}, [hash.to_json]]
93
+ class << self
94
+ def render hash
95
+ [200, default_headers, [hash.to_json]]
96
+ end
97
+
98
+ private
99
+
100
+ def default_headers
101
+ { CONTENT_TYPE_HEADER => JSON_MIME_TYPE }
102
+ end
73
103
  end
74
104
  end
75
-
105
+
76
106
  class PlainTextResponse
77
- def self.render hash
78
- [200, {'Content-Type' => 'text/plain'}, [parse(hash)]]
79
- end
80
-
81
- private
82
-
83
- def self.parse hash
84
- hash.map{ |key,value| "#{key}=#{value}" }.join("\n")
107
+ class << self
108
+ def render hash
109
+ [200, default_headers, [parse(hash)]]
110
+ end
111
+
112
+ private
113
+
114
+ def parse hash
115
+ hash.map{ |key,value| "#{key}=#{value}" }.join("\n")
116
+ end
117
+
118
+ def default_headers
119
+ { CONTENT_TYPE_HEADER => TEXT_MIME_TYPE }
120
+ end
85
121
  end
86
122
  end
87
123
  end
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.3'
22
- spec.add_runtime_dependency 'json'
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_runtime_dependency 'json', '~> 1'
23
23
  end
@@ -13,15 +13,11 @@ require 'rspec'
13
13
  require 'pry'
14
14
 
15
15
  RSpec.configure do |config|
16
- config.color_enabled = true
17
16
  config.tty = true
18
- config.formatter = :documentation # :documentation, :progress, :html, :textmate
17
+ config.formatter = :documentation
19
18
  end
20
19
 
21
20
  $LOAD_PATH.unshift File.expand_path('lib')
22
21
  require 'mini_check'
23
22
 
24
23
  $LOAD_PATH.unshift File.expand_path('spec/support')
25
-
26
- require 'codeclimate-test-reporter'
27
- CodeClimate::TestReporter.start
@@ -1,10 +1,10 @@
1
1
  require_relative '../helper'
2
2
 
3
3
  shared_examples_for 'check' do
4
- it{ should respond_to(:to_hash) }
5
- it{ should respond_to(:name) }
6
- it{ should respond_to(:healthy?) }
7
- it{ should respond_to(:run) }
4
+ it{ is_expected.to respond_to(:to_hash) }
5
+ it{ is_expected.to respond_to(:name) }
6
+ it{ is_expected.to respond_to(:healthy?) }
7
+ it{ is_expected.to respond_to(:run) }
8
8
  end
9
9
 
10
10
  describe MiniCheck::Check do
@@ -17,7 +17,7 @@ describe MiniCheck::Check do
17
17
 
18
18
  describe 'initialize' do
19
19
  it 'allows passing attributes as a hash' do
20
- check = MiniCheck::Check.new name: name, action: action
20
+ check = MiniCheck::Check.new name: name, action: action
21
21
  expect(check.name).to eq(name)
22
22
  expect(check.action).to eq(action)
23
23
  end
@@ -32,7 +32,7 @@ describe MiniCheck::Check do
32
32
 
33
33
  describe 'run' do
34
34
  it 'calls the action' do
35
- action.should receive(:call)
35
+ expect(action).to receive(:call)
36
36
  subject.run
37
37
  end
38
38
 
@@ -92,6 +92,10 @@ describe MiniCheck::Check do
92
92
  end
93
93
 
94
94
  describe 'to_hash' do
95
+ before do
96
+ allow_any_instance_of(Benchmark::Tms).to receive(:real).and_return(1.0)
97
+ end
98
+
95
99
  context 'when the run was successful' do
96
100
  before :each do
97
101
  allow(action).to receive(:call).and_return(Object.new)
@@ -99,7 +103,7 @@ describe MiniCheck::Check do
99
103
 
100
104
  it 'returns the basic healthy hash' do
101
105
  subject.run
102
- expect(subject.to_hash).to eq(healthy: true)
106
+ expect(subject.to_hash).to eq(healthy: true, time: 1.0)
103
107
  end
104
108
  end
105
109
 
@@ -110,13 +114,13 @@ describe MiniCheck::Check do
110
114
 
111
115
  it 'returns the basic healthy hash' do
112
116
  subject.run
113
- expect(subject.to_hash).to eq(healthy: false)
117
+ expect(subject.to_hash).to eq(healthy: false, time: 1.0)
114
118
  end
115
119
  end
116
120
 
117
121
  context 'when the action raises an exception' do
118
122
  before :each do
119
- exception.stub(backtrace: ['a'])
123
+ allow(exception).to receive(:backtrace).and_return ['a']
120
124
  allow(action).to receive(:call).and_raise(exception)
121
125
  end
122
126
 
@@ -124,11 +128,12 @@ describe MiniCheck::Check do
124
128
  subject.run
125
129
  expect(subject.to_hash).to eq(
126
130
  {
127
- :healthy => false,
128
- :error => {
129
- :message => exception.message,
130
- :stack => exception.backtrace,
131
- }
131
+ healthy: false,
132
+ error: {
133
+ message: exception.message,
134
+ stack: exception.backtrace
135
+ },
136
+ time: 1.0
132
137
  }
133
138
  )
134
139
  end
@@ -1,10 +1,10 @@
1
1
  require_relative '../helper'
2
2
 
3
3
  shared_examples_for 'checks collection' do
4
- it{ should respond_to(:to_hash) }
5
- it{ should respond_to(:healthy?) }
6
- it{ should respond_to(:<<) }
7
- it{ should respond_to(:run) }
4
+ it{ is_expected.to respond_to(:to_hash) }
5
+ it{ is_expected.to respond_to(:healthy?) }
6
+ it{ is_expected.to respond_to(:<<) }
7
+ it{ is_expected.to respond_to(:run) }
8
8
  end
9
9
 
10
10
  describe MiniCheck::ChecksCollection do
@@ -18,7 +18,7 @@ describe MiniCheck::ChecksCollection do
18
18
  @name_counter ||= 0
19
19
  stubs[:name] = "name_#{@name_counter += 1}"
20
20
  stubs.merge! args
21
-
21
+
22
22
  double(stubs[:name], stubs)
23
23
  end
24
24
 
@@ -28,7 +28,7 @@ describe MiniCheck::RackApp do
28
28
  describe :call do
29
29
  it 'returns status, headers, body' do
30
30
  get '/'
31
- expect(status).to be_a(Fixnum)
31
+ expect(status).to be_a(Integer)
32
32
  expect(headers).to be_a(Hash)
33
33
  expect(body).to be_a(String)
34
34
  end
@@ -28,7 +28,7 @@ describe MiniCheck::VersionRackApp do
28
28
  describe :call do
29
29
  it 'returns status, headers, body' do
30
30
  get '/'
31
- expect(status).to be_a(Fixnum)
31
+ expect(status).to be_a(Integer)
32
32
  expect(headers).to be_a(Hash)
33
33
  expect(body).to be_a(String)
34
34
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Morales
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2019-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1'
41
41
  description: MiniCheck provides a simple Rack application for adding simple health
42
42
  checks to your app.
43
43
  email:
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.2.2
90
+ rubygems_version: 2.4.5.1
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: MiniCheck provides a simple Rack application for adding simple health checks
@@ -100,4 +100,3 @@ test_files:
100
100
  - spec/mini_check/version_rack_app_spec.rb
101
101
  - spec/mini_check_spec.rb
102
102
  - spec/support/build.yml
103
- has_rdoc: