rack-ecg 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rack/ecg/check_registry"
2
3
  require "rack/ecg/check/error"
3
4
  require "rack/ecg/check/git_revision"
@@ -10,14 +11,33 @@ require "rack/ecg/check/sequel_connection"
10
11
  module Rack
11
12
  class ECG
12
13
  module Check
14
+ # Possible recognised check statuses.
13
15
  module Status
14
- OK = "ok".freeze
15
- ERROR = "error".freeze
16
+ # Indicates the check was successful.
17
+ OK = "ok"
18
+ # Indicates the check errored.
19
+ ERROR = "error"
16
20
  end
17
21
 
18
22
  class Result < Struct.new(:name, :status, :value)
23
+ # Format the result as a JSON compatible hash.
24
+ #
25
+ # @return [Hash<Object, Hash<Symbol, Object>>] Result in a hash format.
26
+ # @example A HTTP success response
27
+ # puts result.as_json
28
+ # # {:http=>{:status=>"ok", :value=>"online"}}
29
+ def as_json
30
+ { name => { status: status, value: value } }
31
+ end
32
+
33
+ # Return the result as a JSON object.
34
+ #
35
+ # @return [String] Result in a JSON object string.
36
+ # @example A HTTP success response
37
+ # puts result.to_json
38
+ # # {"http": {"status": "ok", "value": "online"}}
19
39
  def to_json
20
- {name => {:status => status, :value => value}}
40
+ JSON.dump(as_json)
21
41
  end
22
42
  end
23
43
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
5
+ # @!method initialize
6
+ # Checks whether ActiveRecord is currently connected to the default
7
+ # database.
4
8
  class ActiveRecordConnection
5
9
  def result
6
10
  value = ""
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
4
- # if rack-ecg is serving a request - http is obviously working so far...
5
- # this is basically a "hello-world"
5
+ # @!method initialize
6
+ # Always returns a basic error for testing purposes.
6
7
  class Error
7
8
  def result
8
9
  Result.new(:error, Status::ERROR, "PC LOAD LETTER")
@@ -10,7 +11,6 @@ module Rack
10
11
  end
11
12
 
12
13
  CheckRegistry.instance.register(:error, Error)
13
-
14
14
  end
15
15
  end
16
16
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
5
+ # @!method initialize
6
+ # Returns the SHA1 of the current commit, as reported by the git
7
+ # executable.
4
8
  class GitRevision
5
9
  def result
6
10
  _stdin, stdout, stderr, wait_thread = Open3.popen3("git rev-parse HEAD")
@@ -17,7 +21,6 @@ module Rack
17
21
  end
18
22
 
19
23
  CheckRegistry.instance.register(:git_revision, GitRevision)
20
-
21
24
  end
22
25
  end
23
26
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
4
- # if rack-ecg is serving a request - http is obviously working so far...
5
- # this is basically a "hello-world"
5
+ # @!method initialize
6
+ # Always returns a success.
6
7
  class Http
7
8
  def result
8
9
  Result.new(:http, Status::OK, "online")
@@ -10,7 +11,6 @@ module Rack
10
11
  end
11
12
 
12
13
  CheckRegistry.instance.register(:http, Http)
13
-
14
14
  end
15
15
  end
16
16
  end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
5
+ # @!method initialize
6
+ # Returns the latest applied ActiveRecord migration in the default
7
+ # database.
4
8
  class MigrationVersion
5
9
  def result
6
10
  value = ""
@@ -23,7 +27,6 @@ module Rack
23
27
  end
24
28
 
25
29
  CheckRegistry.instance.register(:migration_version, MigrationVersion)
26
-
27
30
  end
28
31
  end
29
32
  end
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
5
+ # @!method initialize
6
+ # Checks whether the global Redis client is currently connected to the
7
+ # database.
8
+ #
9
+ # Does not take any options.
4
10
  class RedisConnection
5
11
  def result
6
12
  value = ""
@@ -1,8 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
4
  module Check
4
5
  class SequelConnection
5
6
  attr_reader :connection_parameters, :name
7
+
8
+ # Checks whether Sequel can connect to the database identified by the
9
+ # ++connection++ option.
10
+ #
11
+ # @option parameters connection [String,Hash] Sequel connection parameters to check
12
+ # @option parameters name [String,nil] Name to distinguish multiple Sequel checks
6
13
  def initialize(parameters = {})
7
14
  @connection_parameters = parameters[:connection]
8
15
  @name = parameters[:name]
@@ -16,10 +23,10 @@ module Rack
16
23
  status = Status::ERROR
17
24
  value = "Sequel Connection parameters not found"
18
25
  elsif defined?(::Sequel)
19
- ::Sequel.connect(connection_parameters) { |db|
26
+ ::Sequel.connect(connection_parameters) do |db|
20
27
  value = db.test_connection
21
28
  status = Status::OK
22
- }
29
+ end
23
30
  else
24
31
  status = Status::ERROR
25
32
  value = "Sequel not found"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rack/ecg/check"
2
3
 
3
4
  module Rack
@@ -1,27 +1,40 @@
1
+ # frozen_string_literal: true
1
2
  require "singleton"
2
3
 
3
4
  module Rack
4
5
  class ECG
5
6
  class CheckRegistry
7
+ # Raised when a check didn't exist during lookup
6
8
  CheckNotRegistered = Class.new(StandardError)
7
9
  include Singleton
8
10
 
9
- def initialize()
11
+ # Constructs the singleton instance of the registry
12
+ def initialize
10
13
  @registry = {}
11
14
  end
12
15
 
16
+ # Register a check class by name
17
+ #
18
+ # @param [Symbol] name Desired check name
19
+ # @param [Class] check_class Class implementing check functionality
13
20
  def register(name, check_class)
14
21
  @registry[name] = check_class
15
22
  end
16
23
 
24
+ # Fetches the registered check class by name
25
+ #
26
+ # @param [Symbol] name Registered check name
27
+ # @raise [CheckNotRegistered] if the named check has not been registered
17
28
  def lookup(name)
18
- @registry.fetch(name) { raise CheckNotRegistered.new("Check '#{name}' is not registered") }
29
+ @registry.fetch(name) { raise CheckNotRegistered, "Check '#{name}' is not registered" }
19
30
  end
20
31
 
32
+ # (see #lookup)
21
33
  def self.lookup(name)
22
34
  instance.lookup(name)
23
35
  end
24
36
 
37
+ # (see #register)
25
38
  def self.register(name, check_class)
26
39
  instance.register(name, check_class)
27
40
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module Rack
2
3
  class ECG
3
- VERSION = "0.0.5"
4
+ # Library version.
5
+ VERSION = "0.1.0"
4
6
  end
5
7
  end
@@ -1,28 +1,45 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rack/ecg/version'
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "lib/rack/ecg/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rack-ecg"
8
8
  spec.version = Rack::ECG::VERSION
9
9
  spec.authors = ["Envato", "Julian Doherty"]
10
10
  spec.email = ["julian@envato.com"]
11
- spec.summary = %q{Rack middleware serving a health check page}
12
- spec.description = %q{rack-ecg allows you to serve a page that shows you facts about your deployed app to allow you to check that everything is running as it should: git revision, database migrations, and more}
11
+ spec.summary = 'Rack middleware serving a health check page'
12
+ spec.description = <<-EOF
13
+ rack-ecg allows you to serve a page that shows you facts about your deployed
14
+ app to allow you to check that everything is running as it should: git
15
+ revision, database migrations, and more
16
+ EOF
13
17
  spec.homepage = "https://github.com/envato/rack-ecg"
14
18
  spec.license = "MIT"
15
19
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = "https://github.com/envato/rack-ecg/blob/main/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
19
31
  spec.require_paths = ["lib"]
20
32
 
21
- spec.add_runtime_dependency "rack"
33
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
34
+
35
+ spec.add_runtime_dependency("rack")
22
36
 
23
- spec.add_development_dependency "bundler", "~> 1.7"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.2.0"
26
- spec.add_development_dependency "rack-test", "~> 0.6.3"
27
- spec.add_development_dependency "pry", "~> 0.10.1"
37
+ spec.add_development_dependency("rake", "~> 13.0")
38
+ spec.add_development_dependency("bundler", "~> 2.2.1")
39
+ spec.add_development_dependency("rspec", "~> 3.10.0")
40
+ spec.add_development_dependency("rack-test", "~> 1.1.0")
41
+ spec.add_development_dependency("pry", "~> 0.13.0")
42
+ spec.add_development_dependency("rubocop-shopify", "~> 1.0.0")
43
+ spec.add_development_dependency("yard", "~> 0.9.24")
44
+ spec.add_development_dependency("redcarpet", "~> 3.5.0")
28
45
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-ecg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envato
8
8
  - Julian Doherty
9
- autorequire:
10
- bindir: bin
9
+ autorequire:
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2017-05-12 00:00:00.000000000 Z
12
+ date: 2020-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -26,98 +26,147 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: bundler
29
+ name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.7'
34
+ version: '13.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.7'
41
+ version: '13.0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rake
43
+ name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '10.0'
48
+ version: 2.2.1
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '10.0'
55
+ version: 2.2.1
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 3.2.0
62
+ version: 3.10.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 3.2.0
69
+ version: 3.10.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rack-test
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 0.6.3
76
+ version: 1.1.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 0.6.3
83
+ version: 1.1.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: pry
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 0.10.1
90
+ version: 0.13.0
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.13.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop-shopify
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 1.0.0
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 1.0.0
112
+ - !ruby/object:Gem::Dependency
113
+ name: yard
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: 0.9.24
91
119
  type: :development
92
120
  prerelease: false
93
121
  version_requirements: !ruby/object:Gem::Requirement
94
122
  requirements:
95
123
  - - "~>"
96
124
  - !ruby/object:Gem::Version
97
- version: 0.10.1
98
- description: 'rack-ecg allows you to serve a page that shows you facts about your
99
- deployed app to allow you to check that everything is running as it should: git
100
- revision, database migrations, and more'
125
+ version: 0.9.24
126
+ - !ruby/object:Gem::Dependency
127
+ name: redcarpet
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 3.5.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 3.5.0
140
+ description: |2
141
+ rack-ecg allows you to serve a page that shows you facts about your deployed
142
+ app to allow you to check that everything is running as it should: git
143
+ revision, database migrations, and more
101
144
  email:
102
145
  - julian@envato.com
103
146
  executables: []
104
147
  extensions: []
105
148
  extra_rdoc_files: []
106
149
  files:
150
+ - ".github/workflows/main.yml"
107
151
  - ".gitignore"
108
152
  - ".rspec"
109
- - ".travis.yml"
153
+ - ".rubocop.yml"
154
+ - ".ruby-version"
155
+ - ".yardopts"
156
+ - CHANGELOG.md
110
157
  - CODE_OF_CONDUCT.md
111
158
  - Gemfile
112
159
  - LICENSE.txt
113
160
  - README.md
114
161
  - Rakefile
162
+ - bin/console
163
+ - bin/setup
115
164
  - examples/basic.ru
116
165
  - examples/checks.ru
166
+ - examples/hook.ru
117
167
  - examples/mounted_path.ru
118
168
  - examples/parameters.ru
119
169
  - examples/stand_alone.ru
120
- - gemfiles/rack_v1.gemfile
121
170
  - lib/rack-ecg.rb
122
171
  - lib/rack/ecg.rb
123
172
  - lib/rack/ecg/check.rb
@@ -132,15 +181,14 @@ files:
132
181
  - lib/rack/ecg/check_registry.rb
133
182
  - lib/rack/ecg/version.rb
134
183
  - rack-ecg.gemspec
135
- - spec/check_factory_spec.rb
136
- - spec/check_registry_spec.rb
137
- - spec/rack_middleware_spec.rb
138
- - spec/spec_helper.rb
139
184
  homepage: https://github.com/envato/rack-ecg
140
185
  licenses:
141
186
  - MIT
142
- metadata: {}
143
- post_install_message:
187
+ metadata:
188
+ homepage_uri: https://github.com/envato/rack-ecg
189
+ source_code_uri: https://github.com/envato/rack-ecg
190
+ changelog_uri: https://github.com/envato/rack-ecg/blob/main/CHANGELOG.md
191
+ post_install_message:
144
192
  rdoc_options: []
145
193
  require_paths:
146
194
  - lib
@@ -148,20 +196,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
196
  requirements:
149
197
  - - ">="
150
198
  - !ruby/object:Gem::Version
151
- version: '0'
199
+ version: 2.5.0
152
200
  required_rubygems_version: !ruby/object:Gem::Requirement
153
201
  requirements:
154
202
  - - ">="
155
203
  - !ruby/object:Gem::Version
156
204
  version: '0'
157
205
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.6.10
160
- signing_key:
206
+ rubygems_version: 3.2.2
207
+ signing_key:
161
208
  specification_version: 4
162
209
  summary: Rack middleware serving a health check page
163
- test_files:
164
- - spec/check_factory_spec.rb
165
- - spec/check_registry_spec.rb
166
- - spec/rack_middleware_spec.rb
167
- - spec/spec_helper.rb
210
+ test_files: []