rack-ecg 0.0.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/test.yml +22 -0
- data/.rubocop.yml +21 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +84 -0
- data/Gemfile +3 -1
- data/README.md +170 -52
- data/Rakefile +12 -2
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +18 -0
- data/examples/basic.ru +5 -3
- data/examples/checks.ru +5 -3
- data/examples/git_revision_check_replacement.ru +28 -0
- data/examples/hook.ru +17 -0
- data/examples/mounted_path.ru +5 -3
- data/examples/parameters.ru +13 -0
- data/examples/stand_alone.ru +4 -2
- data/lib/rack/ecg/check/active_record_connection.rb +33 -0
- data/lib/rack/ecg/check/error.rb +15 -6
- data/lib/rack/ecg/check/git_revision.rb +10 -2
- data/lib/rack/ecg/check/http.rb +15 -6
- data/lib/rack/ecg/check/migration_version.rb +8 -4
- data/lib/rack/ecg/check/redis_connection.rb +44 -0
- data/lib/rack/ecg/check/sequel_connection.rb +55 -0
- data/lib/rack/ecg/check/static.rb +52 -0
- data/lib/rack/ecg/check.rb +31 -1
- data/lib/rack/ecg/check_factory.rb +29 -0
- data/lib/rack/ecg/check_registry.rb +26 -3
- data/lib/rack/ecg/version.rb +4 -1
- data/lib/rack/ecg.rb +32 -31
- data/lib/rack-ecg.rb +3 -1
- data/rack-ecg.gemspec +33 -14
- metadata +113 -29
- data/.travis.yml +0 -28
- data/gemfiles/rack_v1.gemfile +0 -4
- data/spec/rack_middleware_spec.rb +0 -162
- data/spec/spec_helper.rb +0 -23
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
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Envato
|
8
8
|
- Julian Doherty
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -31,108 +31,195 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 2.3.7
|
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:
|
41
|
+
version: 2.3.7
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.14.1
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.14.1
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rack-test
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.1.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.0
|
42
70
|
- !ruby/object:Gem::Dependency
|
43
71
|
name: rake
|
44
72
|
requirement: !ruby/object:Gem::Requirement
|
45
73
|
requirements:
|
46
74
|
- - "~>"
|
47
75
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
76
|
+
version: '13.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '13.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: redcarpet
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.5.0
|
49
91
|
type: :development
|
50
92
|
prerelease: false
|
51
93
|
version_requirements: !ruby/object:Gem::Requirement
|
52
94
|
requirements:
|
53
95
|
- - "~>"
|
54
96
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
97
|
+
version: 3.5.0
|
56
98
|
- !ruby/object:Gem::Dependency
|
57
99
|
name: rspec
|
58
100
|
requirement: !ruby/object:Gem::Requirement
|
59
101
|
requirements:
|
60
102
|
- - "~>"
|
61
103
|
- !ruby/object:Gem::Version
|
62
|
-
version: 3.
|
104
|
+
version: 3.11.0
|
63
105
|
type: :development
|
64
106
|
prerelease: false
|
65
107
|
version_requirements: !ruby/object:Gem::Requirement
|
66
108
|
requirements:
|
67
109
|
- - "~>"
|
68
110
|
- !ruby/object:Gem::Version
|
69
|
-
version: 3.
|
111
|
+
version: 3.11.0
|
70
112
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
113
|
+
name: rubocop-rake
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop-rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: rubocop-shopify
|
72
142
|
requirement: !ruby/object:Gem::Requirement
|
73
143
|
requirements:
|
74
144
|
- - "~>"
|
75
145
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
146
|
+
version: 2.4.0
|
77
147
|
type: :development
|
78
148
|
prerelease: false
|
79
149
|
version_requirements: !ruby/object:Gem::Requirement
|
80
150
|
requirements:
|
81
151
|
- - "~>"
|
82
152
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
153
|
+
version: 2.4.0
|
84
154
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
155
|
+
name: yard
|
86
156
|
requirement: !ruby/object:Gem::Requirement
|
87
157
|
requirements:
|
88
158
|
- - "~>"
|
89
159
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0.
|
160
|
+
version: 0.9.24
|
91
161
|
type: :development
|
92
162
|
prerelease: false
|
93
163
|
version_requirements: !ruby/object:Gem::Requirement
|
94
164
|
requirements:
|
95
165
|
- - "~>"
|
96
166
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.
|
98
|
-
description:
|
99
|
-
|
100
|
-
|
167
|
+
version: 0.9.24
|
168
|
+
description: |2
|
169
|
+
rack-ecg allows you to serve a page that shows you facts about your deployed
|
170
|
+
app to allow you to check that everything is running as it should: git
|
171
|
+
revision, database migrations, and more
|
101
172
|
email:
|
102
173
|
- julian@envato.com
|
103
174
|
executables: []
|
104
175
|
extensions: []
|
105
176
|
extra_rdoc_files: []
|
106
177
|
files:
|
178
|
+
- ".github/dependabot.yml"
|
179
|
+
- ".github/workflows/test.yml"
|
107
180
|
- ".gitignore"
|
108
181
|
- ".rspec"
|
109
|
-
- ".
|
182
|
+
- ".rubocop.yml"
|
183
|
+
- ".ruby-version"
|
184
|
+
- ".yardopts"
|
185
|
+
- CHANGELOG.md
|
110
186
|
- CODE_OF_CONDUCT.md
|
111
187
|
- Gemfile
|
112
188
|
- LICENSE.txt
|
113
189
|
- README.md
|
114
190
|
- Rakefile
|
191
|
+
- bin/console
|
192
|
+
- bin/setup
|
193
|
+
- docker-compose.yml
|
115
194
|
- examples/basic.ru
|
116
195
|
- examples/checks.ru
|
196
|
+
- examples/git_revision_check_replacement.ru
|
197
|
+
- examples/hook.ru
|
117
198
|
- examples/mounted_path.ru
|
199
|
+
- examples/parameters.ru
|
118
200
|
- examples/stand_alone.ru
|
119
|
-
- gemfiles/rack_v1.gemfile
|
120
201
|
- lib/rack-ecg.rb
|
121
202
|
- lib/rack/ecg.rb
|
122
203
|
- lib/rack/ecg/check.rb
|
204
|
+
- lib/rack/ecg/check/active_record_connection.rb
|
123
205
|
- lib/rack/ecg/check/error.rb
|
124
206
|
- lib/rack/ecg/check/git_revision.rb
|
125
207
|
- lib/rack/ecg/check/http.rb
|
126
208
|
- lib/rack/ecg/check/migration_version.rb
|
209
|
+
- lib/rack/ecg/check/redis_connection.rb
|
210
|
+
- lib/rack/ecg/check/sequel_connection.rb
|
211
|
+
- lib/rack/ecg/check/static.rb
|
212
|
+
- lib/rack/ecg/check_factory.rb
|
127
213
|
- lib/rack/ecg/check_registry.rb
|
128
214
|
- lib/rack/ecg/version.rb
|
129
215
|
- rack-ecg.gemspec
|
130
|
-
- spec/rack_middleware_spec.rb
|
131
|
-
- spec/spec_helper.rb
|
132
216
|
homepage: https://github.com/envato/rack-ecg
|
133
217
|
licenses:
|
134
218
|
- MIT
|
135
|
-
metadata:
|
219
|
+
metadata:
|
220
|
+
homepage_uri: https://github.com/envato/rack-ecg
|
221
|
+
source_code_uri: https://github.com/envato/rack-ecg
|
222
|
+
changelog_uri: https://github.com/envato/rack-ecg/blob/main/CHANGELOG.md
|
136
223
|
post_install_message:
|
137
224
|
rdoc_options: []
|
138
225
|
require_paths:
|
@@ -141,18 +228,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
228
|
requirements:
|
142
229
|
- - ">="
|
143
230
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
231
|
+
version: 2.6.0
|
145
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
233
|
requirements:
|
147
234
|
- - ">="
|
148
235
|
- !ruby/object:Gem::Version
|
149
236
|
version: '0'
|
150
237
|
requirements: []
|
151
|
-
|
152
|
-
rubygems_version: 2.4.5.2
|
238
|
+
rubygems_version: 3.0.3.1
|
153
239
|
signing_key:
|
154
240
|
specification_version: 4
|
155
241
|
summary: Rack middleware serving a health check page
|
156
|
-
test_files:
|
157
|
-
- spec/rack_middleware_spec.rb
|
158
|
-
- spec/spec_helper.rb
|
242
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
rvm:
|
6
|
-
- 1.9.3
|
7
|
-
- 2.0
|
8
|
-
- 2.1
|
9
|
-
- 2.2.5
|
10
|
-
- 2.3.1
|
11
|
-
- ruby-head
|
12
|
-
- jruby
|
13
|
-
|
14
|
-
gemfile:
|
15
|
-
- Gemfile
|
16
|
-
- gemfiles/rack_v1.gemfile
|
17
|
-
|
18
|
-
matrix:
|
19
|
-
allow_failures:
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby
|
22
|
-
exclude:
|
23
|
-
- rvm: 1.9.3
|
24
|
-
gemfile: Gemfile
|
25
|
-
- rvm: 2.0
|
26
|
-
gemfile: Gemfile
|
27
|
-
- rvm: 2.1
|
28
|
-
gemfile: Gemfile
|
data/gemfiles/rack_v1.gemfile
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
require "open3"
|
2
|
-
require "stringio"
|
3
|
-
|
4
|
-
RSpec.describe "when used as middleware" do
|
5
|
-
let(:app) {
|
6
|
-
opts = options
|
7
|
-
Rack::Builder.new do
|
8
|
-
use Rack::ECG, opts
|
9
|
-
run lambda {|env|
|
10
|
-
if env["PATH_INFO"] == "/hello/world"
|
11
|
-
[200, {}, ["Hello, World"]]
|
12
|
-
else
|
13
|
-
[404, {}, ["Goodbye, World"]]
|
14
|
-
end
|
15
|
-
}
|
16
|
-
end
|
17
|
-
}
|
18
|
-
let(:options) {
|
19
|
-
{} # empty default
|
20
|
-
}
|
21
|
-
|
22
|
-
context "main app" do
|
23
|
-
it "responds OK for normal requests" do
|
24
|
-
get "/hello/world"
|
25
|
-
expect(last_response).to be_ok
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't include an X-Rack-ECG-Version custom header" do
|
29
|
-
get "/hello/world"
|
30
|
-
expect(last_response.header["X-Rack-ECG-Version"]).to be_nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "ecg app" do
|
35
|
-
it "responds " do
|
36
|
-
get "/_ecg"
|
37
|
-
expect(last_response).to be_ok
|
38
|
-
end
|
39
|
-
|
40
|
-
it "includes an X-Rack-ECG-Version custom header" do
|
41
|
-
get "/_ecg"
|
42
|
-
expect(last_response.header["X-Rack-ECG-Version"]).to eq(Rack::ECG::VERSION)
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when `at` config option is set" do
|
46
|
-
let(:options) {
|
47
|
-
{at: "/health_check"}
|
48
|
-
}
|
49
|
-
|
50
|
-
it "responds from that path" do
|
51
|
-
get "/health_check"
|
52
|
-
expect(last_response.header["X-Rack-ECG-Version"]).to eq(Rack::ECG::VERSION)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when all checks pass" do
|
57
|
-
it "has a success error code" do
|
58
|
-
get "_ecg"
|
59
|
-
expect(last_response.status).to eq(200)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when a checks errors" do
|
64
|
-
let(:options) {
|
65
|
-
{ checks: [:error] }
|
66
|
-
}
|
67
|
-
it "has a success error code" do
|
68
|
-
get "_ecg"
|
69
|
-
expect(last_response.status).to eq(500)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when hook config option is set" do
|
74
|
-
let(:hook_proc) { instance_double(Proc) }
|
75
|
-
let(:options) {
|
76
|
-
{ hook: hook_proc, checks: :error }
|
77
|
-
}
|
78
|
-
|
79
|
-
it "executes the hook proc with success status and check results as params" do
|
80
|
-
expect(hook_proc).to receive(:call) do |success, check_results|
|
81
|
-
expect(success).to be_falsey
|
82
|
-
expect(check_results).to have_key(:error)
|
83
|
-
end
|
84
|
-
get "_ecg"
|
85
|
-
expect(last_response.status).to eq(500)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "git revision" do
|
90
|
-
let(:options) {
|
91
|
-
{ checks: [:git_revision] }
|
92
|
-
}
|
93
|
-
context "when available" do
|
94
|
-
let(:sha) { "cafe1234" }
|
95
|
-
it "is reported" do
|
96
|
-
expect(Open3).to receive(:popen3).
|
97
|
-
with("git rev-parse HEAD").
|
98
|
-
and_return([
|
99
|
-
nil, # stdin
|
100
|
-
StringIO.new(sha + "\n"), # stdout
|
101
|
-
StringIO.new(), # stderr
|
102
|
-
double(value: double(Process::Status, success?: true)) # wait thread & process status
|
103
|
-
])
|
104
|
-
get "/_ecg"
|
105
|
-
expect(json_body["git_revision"]["status"]).to eq("ok")
|
106
|
-
expect(json_body["git_revision"]["value"]).to eq(sha)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when not available" do
|
111
|
-
let(:error_message) { "git had a sad" }
|
112
|
-
it "is reported" do
|
113
|
-
expect(Open3).to receive(:popen3).
|
114
|
-
with("git rev-parse HEAD").
|
115
|
-
and_return([
|
116
|
-
nil, # stdin
|
117
|
-
StringIO.new(), # stdout
|
118
|
-
StringIO.new(error_message + "\n"), # stderr
|
119
|
-
double(value: double(Process::Status, success?: false)) # wait thread & process status
|
120
|
-
])
|
121
|
-
get "/_ecg"
|
122
|
-
expect(json_body["git_revision"]["status"]).to eq("error")
|
123
|
-
expect(json_body["git_revision"]["value"]).to eq("git had a sad")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "migration version" do
|
129
|
-
let(:options) {
|
130
|
-
{ checks: [:migration_version] }
|
131
|
-
}
|
132
|
-
context "when availabile" do
|
133
|
-
it "is reported" do
|
134
|
-
class ActiveRecord
|
135
|
-
class Base
|
136
|
-
def self.connection
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
version = "123456"
|
141
|
-
connection = double("connection")
|
142
|
-
expect(ActiveRecord::Base).to receive(:connection).and_return(connection)
|
143
|
-
expect(connection).to receive(:select_value).
|
144
|
-
with("select max(version) from schema_migrations").
|
145
|
-
and_return(version)
|
146
|
-
get "/_ecg"
|
147
|
-
expect(json_body["migration_version"]["status"]).to eq("ok")
|
148
|
-
expect(json_body["migration_version"]["value"]).to eq(version)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when not available" do
|
153
|
-
it "is reported" do
|
154
|
-
Object.send(:remove_const, :ActiveRecord) if defined?(ActiveRecord)
|
155
|
-
get "/_ecg"
|
156
|
-
expect(json_body["migration_version"]["status"]).to eq("error")
|
157
|
-
expect(json_body["migration_version"]["value"]).to eq("ActiveRecord not found")
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'rack/test'
|
3
|
-
require 'rack/ecg'
|
4
|
-
|
5
|
-
RSpec.configure do |config|
|
6
|
-
config.expect_with :rspec do |expectations|
|
7
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
-
end
|
9
|
-
|
10
|
-
config.mock_with :rspec do |mocks|
|
11
|
-
mocks.verify_partial_doubles = true
|
12
|
-
end
|
13
|
-
|
14
|
-
config.disable_monkey_patching!
|
15
|
-
|
16
|
-
config.warnings = true
|
17
|
-
|
18
|
-
config.include Rack::Test::Methods
|
19
|
-
|
20
|
-
def json_body
|
21
|
-
@json_body ||= JSON.parse(last_response.body)
|
22
|
-
end
|
23
|
-
end
|