rack-ecg 0.0.3 → 0.0.4

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,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e69b8b06f6e9447931c2dd5f6a709153fc05054
4
- data.tar.gz: 7fd824b68af2e6db167af65b7518004c1c7aabce
3
+ metadata.gz: b3d3e3118a76ef6c60141ec590ea0feb00781a65
4
+ data.tar.gz: eb8a0b817ab97ce981828fa8c465b60806fcf978
5
5
  SHA512:
6
- metadata.gz: 80b858e5dbf7874a6db6d70361c7f8c5726b515113e3bece707c9c857ed70d0d14448ee640899433f7bc4206458cb418b23b03b66d72e32b18c2b5a347c2bcc8
7
- data.tar.gz: 6fa5476c8cba27af405f0c648be87843d79c89f166328ca0b8b15368f3d8cb1b8c3fda15ddc0c850e8d5b66711635c1ca02193001e5cd514fe43074599f8582d
6
+ metadata.gz: 76a8c2d9eaf627ee8c4277fe564a0712ae05347237652fb26b8950ecfe51e5aeecbb084a72516d45a9e347ef66bc6e8db657e12eb9444376581fafdfbbb1c8a0
7
+ data.tar.gz: 40baa754d837d5ddf996a43604d6e2ed5693a74bf488f01f1b45f7234e60bd53f2e79b073583d66f3f9031d7d1edf729dbffc6126489affc6fd5c1fee7ad03df
data/README.md CHANGED
@@ -91,11 +91,13 @@ HTTP responses can be returned. There are a number of built in checks that
91
91
  - `:migration_version` - this assumes you are using ActiveRecord migrations. It
92
92
  queries the `schema_versions` table and tells you what version the database is
93
93
  at.
94
+ - `:active_record` - this checks if an ActiveRecord connection is active.
95
+ - `:redis` - this checks if a Redis connection is active.
94
96
 
95
- So using `git_revision` and `migration_version` would look like:
97
+ So using `git_revision`, `migration_version`, `active_record`, and `redis` would look like:
96
98
 
97
99
  ```ruby
98
- use Rack::ECG, checks: [:git_revision, :migration_version]
100
+ use Rack::ECG, checks: [:git_revision, :migration_version, :active_record, :redis]
99
101
  ```
100
102
 
101
103
  ```
@@ -112,6 +114,14 @@ $ curl http://localhost:9292/_ecg
112
114
  "migration_version": {
113
115
  "status": "ok",
114
116
  "value": "20150319050250"
117
+ },
118
+ "active_record": {
119
+ "status": "ok",
120
+ "value": "true"
121
+ },
122
+ "redis": {
123
+ "status": "ok",
124
+ "value": "true"
115
125
  }
116
126
  }
117
127
  ```
@@ -3,6 +3,8 @@ require "rack/ecg/check/error"
3
3
  require "rack/ecg/check/git_revision"
4
4
  require "rack/ecg/check/http"
5
5
  require "rack/ecg/check/migration_version"
6
+ require "rack/ecg/check/active_record_connection"
7
+ require "rack/ecg/check/redis_connection"
6
8
 
7
9
  module Rack
8
10
  class ECG
@@ -0,0 +1,28 @@
1
+ module Rack
2
+ class ECG
3
+ module Check
4
+ class ActiveRecordConnection
5
+ def result
6
+ value = ""
7
+ status = "ok"
8
+ begin
9
+ if defined?(ActiveRecord)
10
+ value = ::ActiveRecord::Base.connection.active?
11
+ status = value ? "ok" : "error"
12
+ else
13
+ status = "error"
14
+ value = "ActiveRecord not found"
15
+ end
16
+ rescue => e
17
+ status = "error"
18
+ value = e.message
19
+ end
20
+
21
+ Result.new(:active_record, status, value.to_s)
22
+ end
23
+
24
+ CheckRegistry.instance.register(:active_record, ActiveRecordConnection)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Rack
2
+ class ECG
3
+ module Check
4
+ class RedisConnection
5
+ def result
6
+ value = ""
7
+ status = "ok"
8
+ begin
9
+ if defined?(::Redis)
10
+ value = ::Redis.current.connected?
11
+ status = value ? "ok" : "error"
12
+ else
13
+ status = "error"
14
+ value = "Redis not found"
15
+ end
16
+ rescue => e
17
+ status = "error"
18
+ value = e.message
19
+ end
20
+
21
+ Result.new(:redis, status, value.to_s)
22
+ end
23
+
24
+ CheckRegistry.instance.register(:redis, RedisConnection)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class ECG
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -129,7 +129,7 @@ RSpec.describe "when used as middleware" do
129
129
  let(:options) {
130
130
  { checks: [:migration_version] }
131
131
  }
132
- context "when availabile" do
132
+ context "when available" do
133
133
  it "is reported" do
134
134
  class ActiveRecord
135
135
  class Base
@@ -158,5 +158,67 @@ RSpec.describe "when used as middleware" do
158
158
  end
159
159
  end
160
160
  end
161
+
162
+ context "active_record" do
163
+ let(:options) {
164
+ { checks: [:active_record] }
165
+ }
166
+ context "when available" do
167
+ it "is reported" do
168
+ class ActiveRecord
169
+ class Base
170
+ def self.connection
171
+ end
172
+ end
173
+ end
174
+ active = true
175
+ connection = double("connection")
176
+ expect(ActiveRecord::Base).to receive(:connection).and_return(connection)
177
+ expect(connection).to receive(:active?).and_return(active)
178
+ get "/_ecg"
179
+ expect(json_body["active_record"]["status"]).to eq("ok")
180
+ expect(json_body["active_record"]["value"]).to eq(active.to_s)
181
+ end
182
+ end
183
+
184
+ context "when not available" do
185
+ it "is reported" do
186
+ Object.send(:remove_const, :ActiveRecord) if defined?(ActiveRecord)
187
+ get "/_ecg"
188
+ expect(json_body["active_record"]["status"]).to eq("error")
189
+ expect(json_body["active_record"]["value"]).to eq("ActiveRecord not found")
190
+ end
191
+ end
192
+ end
193
+
194
+ context "redis" do
195
+ let(:options) {
196
+ { checks: [:redis] }
197
+ }
198
+ context "when available" do
199
+ it "is reported" do
200
+ class Redis
201
+ def self.current
202
+ end
203
+ end
204
+ connected = true
205
+ instance = double("current")
206
+ expect(Redis).to receive(:current).and_return(instance)
207
+ expect(instance).to receive(:connected?).and_return(connected)
208
+ get "/_ecg"
209
+ expect(json_body["redis"]["status"]).to eq("ok")
210
+ expect(json_body["redis"]["value"]).to eq(connected.to_s)
211
+ end
212
+ end
213
+
214
+ context "when not available" do
215
+ it "is reported" do
216
+ Object.send(:remove_const, :Redis) if defined?(Redis)
217
+ get "/_ecg"
218
+ expect(json_body["redis"]["status"]).to eq("error")
219
+ expect(json_body["redis"]["value"]).to eq("Redis not found")
220
+ end
221
+ end
222
+ end
161
223
  end
162
224
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-ecg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Envato
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-14 00:00:00.000000000 Z
12
+ date: 2017-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -120,10 +120,12 @@ files:
120
120
  - lib/rack-ecg.rb
121
121
  - lib/rack/ecg.rb
122
122
  - lib/rack/ecg/check.rb
123
+ - lib/rack/ecg/check/active_record_connection.rb
123
124
  - lib/rack/ecg/check/error.rb
124
125
  - lib/rack/ecg/check/git_revision.rb
125
126
  - lib/rack/ecg/check/http.rb
126
127
  - lib/rack/ecg/check/migration_version.rb
128
+ - lib/rack/ecg/check/redis_connection.rb
127
129
  - lib/rack/ecg/check_registry.rb
128
130
  - lib/rack/ecg/version.rb
129
131
  - rack-ecg.gemspec
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
151
  version: '0'
150
152
  requirements: []
151
153
  rubyforge_project:
152
- rubygems_version: 2.4.5.2
154
+ rubygems_version: 2.5.2
153
155
  signing_key:
154
156
  specification_version: 4
155
157
  summary: Rack middleware serving a health check page