goodguide-pinglish 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 21349b68ac1102b95ac9e8e37ce9a8199af64d56
4
- data.tar.gz: 65b356ff81337fa6e66d58547cec1eb8b1ff3fa5
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzVmMGY0ODBmZTRmZGMwOTI3OTg2MDY5MGU5NDllMzNjZjkwZTk1OQ==
5
+ data.tar.gz: !binary |-
6
+ NzI2YTdjODVlYTk4YmRiYjU1OGZhZjg2OWIwYWRkZGE5ZWU1YmRlNg==
5
7
  SHA512:
6
- metadata.gz: c6923231c568bcc36da5dc6569b57d23118fd64e14238a05b365409c2f82b189e3df45d8ba729b810e92f866cef66d59b83600b5e489b05b2afddfdad26cce05
7
- data.tar.gz: 88ec461eeac036dcfde251f0b62fae7f3ad6a9cb5c17598528b9e20baae72b5d22743815208df81f323b40e7aab81b82f20b79956916f45be7bdd7143cdb0166
8
+ metadata.gz: !binary |-
9
+ M2Q0M2RlYWUyOWI0NDVkMDQxZTQ0NWU4Nzg1M2NkZGMyMTkwZDdiZDE4MmQz
10
+ MjI4ZmZmZmQ3MmViNWVhNjk5MWYzZjdhYzRkNzJkYjk2YzQ2ODczMzhhYjg1
11
+ NzA5YTk3Yjc5YTVjM2E1MTI1ZjlhMWJiNzk5Y2U5ZWNhMmQ2NGY=
12
+ data.tar.gz: !binary |-
13
+ ZGI5MWVhYmE0ZDI0NGRhYThjNTIxMDJkMDQ2NWVkZWZhMGIzZDA2MGM1NGMy
14
+ MjRjZjRlNDI3M2ZiNmQ0MThmZGI3ZTlhMjVmZTZkNGFlYTc4YzA1MDcxY2My
15
+ Yjc5OTFhYzU1NWIxYjk1YjM0YWI5NGY3MzZlMmY2MWY0MDhhY2E=
data/.gitignore CHANGED
@@ -1,3 +1,3 @@
1
- /*.gem
2
1
  /.bundle
3
2
  /Gemfile.lock
3
+ /pkg
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - jruby-20mode
7
+ - rbx-2
8
+ - ruby-head
9
+ - jruby-head
10
+ before_install: gem install bundler
11
+
12
+ bundler_args: --jobs=4 --retry=5
13
+
14
+ deploy:
15
+ provider: rubygems
16
+ api_key:
17
+ secure: "qiQxYOFzzLDzrgovDfF+1QnpGA4cNrCbNJsQJvaQfEyAglbSdSTPHcz0jDp9gYcPrJiz/YytFhoRgsrp2tKduu32mr+fjuQdXuZZ/xAiJ9BQlxvwuB8zds7Nbqgr5XuQkJFy11yZvQLDwaxeuErrmx7KusFUPV8ZksKnZjU+drc="
18
+ gem: goodguide-pinglish
19
+ on:
20
+ repo: GoodGuide/pinglish
21
+ tags: true
22
+
23
+ notifications:
24
+ slack:
25
+ secure: "uFaT+WAFDeXr6BCaNXExQx0Iqh7La4E9rG9NctqP3sP2EQGzFMndTLrnLJcQQm8jPHlczqSkL/Ct9BMUEYOt7C3B3d86rZ0ml21IYFjZD8wt3TEorVOh1XaE2WoEtpn587q7AbSWoVWcl5/66c8dlot8/GGNORkl/gjU9kIgDFY="
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # Pinglish
2
2
 
3
- A simple Rack middleware for checking application health. Pinglish
4
- exposes a `/_ping` resource via HTTP `GET`, returning JSON that
5
- conforms to the spec below.
3
+ A simple Rack app for checking application health. Pinglish responds to `GET` requests, returning JSON that conforms to the spec below.
6
4
 
7
5
  ## The Spec
8
6
 
9
- 0. The application __must__ respond to `GET /_ping` as an HTTP request.
7
+ 0. The application __must__ respond to `GET /` as an HTTP request.
10
8
 
11
9
  0. The request handler __should__ check the health of all services the
12
10
  application depends on, answering questions like, "Can I query
@@ -52,57 +50,48 @@ conforms to the spec below.
52
50
 
53
51
  ```javascript
54
52
  {
55
-
56
53
  // These two keys will always exist.
57
-
58
54
  "now": "1359055102",
59
55
  "status": "failures",
60
56
 
61
57
  // This key may only exist when a named check has failed.
62
-
63
58
  "failures": ["db"],
64
59
 
65
60
  // This key may only exist when a named check exceeds its timeout.
66
-
67
61
  "timeouts": ["really-long-check"],
68
62
 
69
63
  // Keys like this may exist to provide extra information about
70
64
  // healthy services, like the number of objects in an S3 bucket.
71
-
72
65
  "s3": "127"
73
66
  }
74
67
  ```
75
68
 
76
- ## The Middleware
69
+ ## Configuring Checks
77
70
 
78
71
  ```ruby
79
72
  require "pinglish"
80
73
 
81
- use Pinglish do |ping|
82
-
83
- # A single unnamed check is the simplest possible way to use
84
- # Pinglish, and you'll probably never want combine it with other
85
- # named checks. An unnamed check contributes to overall success or
86
- # failure, but never adds additional data to the response.
87
-
74
+ pinglish = Pinglish.new do |ping|
75
+ # A single unnamed check is the simplest possible way to use Pinglish, and
76
+ # you'll probably never want combine it with other named checks. An unnamed
77
+ # check contributes to overall success or failure, but never adds additional
78
+ # data to the response.
88
79
  ping.check do
89
80
  App.healthy?
90
81
  end
91
82
 
92
- # A named check like this can provide useful summary information
93
- # when it succeeds. In this case, a top-level "db" key will appear
94
- # in the response containing the number of items in the database. If
95
- # a check returns nil, no key will be added to the response.
96
-
83
+ # A named check like this can provide useful summary information when it
84
+ # succeeds. In this case, a top-level "db" key will appear in the response
85
+ # containing the number of items in the database. If a check returns nil, no
86
+ # key will be added to the response.
97
87
  ping.check :db do
98
88
  App.db.items.size
99
89
  end
100
90
 
101
- # By default, checks time out after one second. You can override
102
- # this with the :timeout option, but be aware that no combination of
103
- # checks is ever allowed to exceed the overall 29 second limit.
104
-
105
- ping.check :long, :timeout => 5 do
91
+ # By default, checks time out after one second. You can override this with the
92
+ # :timeout option, but be aware that no combination of checks is ever allowed
93
+ # to exceed the overall 29 second limit.
94
+ ping.check :long, timeout: 5 do
106
95
  App.dawdle
107
96
  end
108
97
 
@@ -115,5 +104,46 @@ use Pinglish do |ping|
115
104
  ping.check :false_fails do
116
105
  false
117
106
  end
107
+
108
+ # All checks run, by default. To create a check that is only run when
109
+ # requested, provide `false` for the `:enabled_by_default` option. Checks like
110
+ # this can be requested using the `checks` query parameter (see below).
111
+ ping.check :cpu_intensive_check, enabled_by_default: false do
112
+ App.check_all_the_things
113
+ end
118
114
  end
119
115
  ```
116
+
117
+ ## Usage
118
+
119
+ Use in a Rack app is easy, just mount the app within a `map` block.
120
+
121
+ ```ruby
122
+ # config.ru
123
+ map '/_ping' do
124
+ run Pinglish.new { |ping|
125
+ ping.check do
126
+ App.healthy?
127
+ end
128
+ }
129
+ end
130
+
131
+ run App.new
132
+ ```
133
+
134
+ Now requests to `GET /_ping` will return this response:
135
+
136
+ ```json
137
+ {
138
+ "now": "1359055102",
139
+ "status": "ok"
140
+ }
141
+ ```
142
+
143
+ You can supply an optional `checks` query parameter (comma separated names) to select which checks to run. This can be used to run just a subset, or to select checks which have `enabled_by_default` set to `false`.
144
+
145
+ ```
146
+ GET /_ping?checks=foo,bar,default
147
+ ```
148
+
149
+ (In this case, an unnamed check is referred to as `default`, and is not treated specially -- you must specify `default` if you pass this parameter and want it to run.)
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task default: :test
10
+
11
+ # rubygems releases are done by Travis
12
+ Rake::Task['release:rubygem_push'].clear
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "goodguide-pinglish"
5
- gem.version = "1.0.0"
5
+ gem.version = "1.1.0"
6
6
  gem.authors = ["John Barnette", "Will Farrington"]
7
7
  gem.email = ["jbarnette@github.com", "wfarr@github.com"]
8
8
  gem.description = "A simple Rack middleware for checking app health."
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
 
16
16
  gem.add_dependency "rack"
17
+ gem.add_development_dependency 'rake', '~> 10.4.0'
17
18
  gem.add_development_dependency "minitest", "~> 4.5"
18
19
  gem.add_development_dependency "rack-test", "~> 0.6"
19
20
  end
@@ -1,21 +1,19 @@
1
1
  class Pinglish
2
2
  class Check
3
- attr_reader :group
4
3
  attr_reader :name
5
4
  attr_reader :timeout
5
+ attr_reader :enabled_by_default
6
6
 
7
- def initialize(name, options = nil, &block)
8
- options ||= {}
9
- @group = options[:group]
10
- @name = name
11
- @timeout = options[:timeout] || 1
12
- @block = block
7
+ def initialize(name, options={}, &block)
8
+ @name = name
9
+ @timeout = options.fetch(:timeout, 1)
10
+ @enabled_by_default = !!options.fetch(:enabled_by_default, true)
11
+ @block = block
13
12
  end
14
13
 
15
14
  # Call this check's behavior, returning the result of the block.
16
-
17
15
  def call(*args, &block)
18
- @block.call *args, &block
16
+ @block.call(*args, &block)
19
17
  end
20
18
  end
21
19
  end
data/lib/pinglish.rb CHANGED
@@ -107,7 +107,7 @@ class Pinglish
107
107
  selected = selected.split(',').map(&:to_sym)
108
108
  return @checks.values_at(*selected).compact
109
109
  end
110
- @checks.values
110
+ @checks.values.select(&:enabled_by_default)
111
111
  end
112
112
 
113
113
  # Add a new check with optional `name`. A `:timeout` option can be
@@ -115,7 +115,7 @@ class Pinglish
115
115
  # one second default. A previously added check with the same name
116
116
  # will be replaced.
117
117
 
118
- def check(name = :default, options = nil, &block)
118
+ def check(name=:default, options={}, &block)
119
119
  @checks[name.to_sym] = Check.new(name, options, &block)
120
120
  end
121
121
 
data/test/check_test.rb CHANGED
@@ -20,4 +20,15 @@ class PinglishCheckTest < MiniTest::Unit::TestCase
20
20
  check = Pinglish::Check.new(:db) { :result_of_block }
21
21
  assert_equal :result_of_block, check.call
22
22
  end
23
+
24
+ def test_enabled_by_default
25
+ check = Pinglish::Check.new(:foo)
26
+ assert_equal true, check.enabled_by_default
27
+
28
+ check = Pinglish::Check.new(:foo, enabled_by_default: false)
29
+ assert_equal false, check.enabled_by_default
30
+
31
+ check = Pinglish::Check.new(:foo, enabled_by_default: 'not boolean')
32
+ assert_equal true, check.enabled_by_default
33
+ end
23
34
  end
@@ -259,4 +259,48 @@ class PinglishTest < MiniTest::Unit::TestCase
259
259
  assert pinglish.timeout?(Pinglish::TooLong.new)
260
260
  refute pinglish.timeout?(Exception.new)
261
261
  end
262
+
263
+ def test_enabled_by_default_false
264
+ app = build_app do |ping|
265
+ ping.check(:db) { :ok }
266
+ ping.check(:intense, enabled_by_default: false) { :ok }
267
+ end
268
+
269
+ session = Rack::Test::Session.new(app)
270
+ session.get "/_ping"
271
+
272
+ assert_equal 200, session.last_response.status
273
+ assert_equal "application/json; charset=UTF-8",
274
+ session.last_response.content_type
275
+
276
+ json = JSON.load(session.last_response.body)
277
+ assert json.key?("now")
278
+ assert_equal "ok", json["status"]
279
+ assert_equal false, json.key?("timeouts")
280
+ assert_equal false, json.key?("failures")
281
+ assert_equal 'ok', json['db']
282
+ assert_equal false, json.key?("intense")
283
+ end
284
+
285
+ def test_enabled_by_default_selected
286
+ app = build_app do |ping|
287
+ ping.check(:db) { :ok }
288
+ ping.check(:intense, enabled_by_default: false) { :ok }
289
+ end
290
+
291
+ session = Rack::Test::Session.new(app)
292
+ session.get "/_ping?checks=db,intense"
293
+
294
+ assert_equal 200, session.last_response.status
295
+ assert_equal "application/json; charset=UTF-8",
296
+ session.last_response.content_type
297
+
298
+ json = JSON.load(session.last_response.body)
299
+ assert json.key?("now")
300
+ assert_equal "ok", json["status"]
301
+ assert_equal false, json.key?("timeouts")
302
+ assert_equal false, json.key?("failures")
303
+ assert_equal 'ok', json['db']
304
+ assert_equal 'ok', json["intense"]
305
+ end
262
306
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goodguide-pinglish
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
@@ -9,48 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-25 00:00:00.000000000 Z
12
+ date: 2015-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 10.4.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 10.4.0
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: minitest
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
- - - "~>"
46
+ - - ~>
33
47
  - !ruby/object:Gem::Version
34
48
  version: '4.5'
35
49
  type: :development
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
- - - "~>"
53
+ - - ~>
40
54
  - !ruby/object:Gem::Version
41
55
  version: '4.5'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: rack-test
44
58
  requirement: !ruby/object:Gem::Requirement
45
59
  requirements:
46
- - - "~>"
60
+ - - ~>
47
61
  - !ruby/object:Gem::Version
48
62
  version: '0.6'
49
63
  type: :development
50
64
  prerelease: false
51
65
  version_requirements: !ruby/object:Gem::Requirement
52
66
  requirements:
53
- - - "~>"
67
+ - - ~>
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0.6'
56
70
  description: A simple Rack middleware for checking app health.
@@ -61,10 +75,12 @@ executables: []
61
75
  extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
- - ".gitignore"
78
+ - .gitignore
79
+ - .travis.yml
65
80
  - Gemfile
66
81
  - LICENSE
67
82
  - README.md
83
+ - Rakefile
68
84
  - goodguide-pinglish.gemspec
69
85
  - lib/pinglish.rb
70
86
  - lib/pinglish/check.rb
@@ -83,22 +99,21 @@ require_paths:
83
99
  - lib
84
100
  required_ruby_version: !ruby/object:Gem::Requirement
85
101
  requirements:
86
- - - ">="
102
+ - - ! '>='
87
103
  - !ruby/object:Gem::Version
88
104
  version: '0'
89
105
  required_rubygems_version: !ruby/object:Gem::Requirement
90
106
  requirements:
91
- - - ">="
107
+ - - ! '>='
92
108
  - !ruby/object:Gem::Version
93
109
  version: '0'
94
110
  requirements: []
95
111
  rubyforge_project:
96
- rubygems_version: 2.2.2
112
+ rubygems_version: 2.4.5
97
113
  signing_key:
98
114
  specification_version: 4
99
- summary: "/_ping your way to freedom."
115
+ summary: /_ping your way to freedom.
100
116
  test_files:
101
117
  - test/check_test.rb
102
118
  - test/helper.rb
103
119
  - test/pinglish_test.rb
104
- has_rdoc: