ring 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +31 -0
- data/app/controllers/ring/application_controller.rb +7 -0
- data/app/controllers/ring/ping_controller.rb +46 -0
- data/config/routes.rb +5 -0
- data/lib/ring.rb +16 -0
- data/lib/ring/engine.rb +7 -0
- data/lib/ring/version.rb +5 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fcab09a1f05cbf0146dceaf01263e00664faff5d6c12e95944e4015f7e1e38ff
|
4
|
+
data.tar.gz: 6050b229822b33f9518be0937bf126a2b1b551f268f2acb66a2e153abb024ca2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e64cb1c418da9fb4bce3150f832b2f128090edff75780be9dc0358e3c0df7796998028c779b4a06c0154466eb6f0701509d3cf9c65cbe75e58cb192086164c74
|
7
|
+
data.tar.gz: f8cd9f89dc97e4115917b5f15221c3f91947b28d9a5f4ca336855e168cb8eba025834282569f80964bb9b3c2a31819b229fe06386f4c25d54c60130a991e890c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Trae Robrock
|
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:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Ring
|
2
|
+
*R*ails + P*ing* = Ring
|
3
|
+
|
4
|
+
This is a simple Rails engine that provides a health check endpoint you can use for load balancer
|
5
|
+
health check, external health checks, or anything else.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ring'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install ring
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
By default this will return a status `:ok`, but you can configure it to exercise other services you
|
26
|
+
might have to include those in the health. For example, it might be good to run `User.first` to
|
27
|
+
ensure your database connection is healthy. You can do that by creating an initializer with content
|
28
|
+
similar to:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Ring.configure do |config|
|
32
|
+
config.add_check :database, -> { User.first }
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
This will now include the health of the database in the status code and the output of the endpoint.
|
37
|
+
|
38
|
+
## License
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'Ring'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
require 'bundler/gem_tasks'
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
|
25
|
+
Rake::TestTask.new(:test) do |t|
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
task default: :test
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ring
|
4
|
+
class PingController < ApplicationController
|
5
|
+
def show
|
6
|
+
respond_to do |format|
|
7
|
+
format.html { render plain: hash_to_text(status_content), status: status_code }
|
8
|
+
format.json { render json: status_content, status: status_code }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def hash_to_text(hash)
|
15
|
+
hash.map { |data| data.join(':') }.join("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def status_content
|
19
|
+
return @status_content if defined?(@status_content) && @status_content
|
20
|
+
|
21
|
+
@status_content = {
|
22
|
+
status: readable_status_code(status_code)
|
23
|
+
}
|
24
|
+
all_checks.each do |(name, check)|
|
25
|
+
@status_content[name] = readable_status_code(status_code_name(check))
|
26
|
+
end
|
27
|
+
@status_content
|
28
|
+
end
|
29
|
+
|
30
|
+
def status_code
|
31
|
+
@status_code ||= status_code_name(all_checks.all?(&:last))
|
32
|
+
end
|
33
|
+
|
34
|
+
def status_code_name(value)
|
35
|
+
value ? :ok : :service_unavailable
|
36
|
+
end
|
37
|
+
|
38
|
+
def readable_status_code(status_code)
|
39
|
+
status_code.to_s.humanize.upcase
|
40
|
+
end
|
41
|
+
|
42
|
+
def all_checks
|
43
|
+
@all_checks ||= Ring.checks.map { |name, check| [name, check.call] }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/config/routes.rb
ADDED
data/lib/ring.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ring/engine'
|
4
|
+
|
5
|
+
module Ring
|
6
|
+
mattr_reader :checks
|
7
|
+
@@checks = {} # rubocop:disable Style/ClassVars
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
yield self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.add_check(name, check)
|
14
|
+
@@checks[name] = check
|
15
|
+
end
|
16
|
+
end
|
data/lib/ring/engine.rb
ADDED
data/lib/ring/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ring
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trae Robrock
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
33
|
+
description: A simple rails engine to provide a health check endpoint.
|
34
|
+
email:
|
35
|
+
- trobrock@gmail.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- MIT-LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- app/controllers/ring/application_controller.rb
|
44
|
+
- app/controllers/ring/ping_controller.rb
|
45
|
+
- config/routes.rb
|
46
|
+
- lib/ring.rb
|
47
|
+
- lib/ring/engine.rb
|
48
|
+
- lib/ring/version.rb
|
49
|
+
homepage: https://github.com/trobrock/ring
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.1.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: A simple rails engine to provide a health check endpoint.
|
72
|
+
test_files: []
|