easymon 1.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/easymon/checks/split_active_record_check.rb +12 -12
- data/lib/easymon/version.rb +1 -1
- data/test/dummy/app/assets/config/manifest.js +0 -0
- data/test/dummy/config/database.yml +2 -2
- data/test/dummy/config/storage.yml +0 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/checks/split_active_record_check_test.rb +19 -19
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb55744be4fa12e4c7af34ae59091721967aaf08d1bd07e4bc0cca4bd2937c4a
|
4
|
+
data.tar.gz: ed1822f256bea98b6982f634487c676fad7e292ca093c10315ce72990ffb6778
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd39994e506c00177688ae9ecb7ff660326cc44eec4374cdeb42873c3128bec45da18dfb54969b9a6494fb0d79ef1d87be4d223c4ef162a70bfc5d4db4345e9a
|
7
|
+
data.tar.gz: a6515ddbd1f7a0bce037815d8804c2c7689dfc943c1ad9c7f037d711ff41700efcc6367e261b2bd3a80b43590e30ef2523ec2bd639537aac7eada9fa5f000bbd
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@ module Easymon
|
|
2
2
|
class SplitActiveRecordCheck
|
3
3
|
attr_accessor :block
|
4
4
|
attr_accessor :results
|
5
|
-
|
5
|
+
|
6
6
|
# Here we pass a block so we get a fresh instance of ActiveRecord::Base or
|
7
7
|
# whatever other class we might be using to make database connections
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# For example, given the following other class:
|
10
10
|
# module Easymon
|
11
11
|
# class Base < ActiveRecord::Base
|
@@ -18,12 +18,12 @@ module Easymon
|
|
18
18
|
# end
|
19
19
|
#
|
20
20
|
# def database_configuration
|
21
|
-
# env = "#{Rails.env}
|
21
|
+
# env = "#{Rails.env}_replica"
|
22
22
|
# config = YAML.load_file(Rails.root.join('config/database.yml'))[env]
|
23
23
|
# end
|
24
24
|
# end
|
25
25
|
# end
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# We would check both it and ActiveRecord::Base like so:
|
28
28
|
# check = Easymon::SplitActiveRecordCheck.new {
|
29
29
|
# [ActiveRecord::Base.connection, Easymon::Base.connection]
|
@@ -31,20 +31,20 @@ module Easymon
|
|
31
31
|
# Easymon::Repository.add("split-database", check)
|
32
32
|
def initialize(&block)
|
33
33
|
self.block = block
|
34
|
-
end
|
35
|
-
|
34
|
+
end
|
35
|
+
|
36
36
|
# Assumes only 2 connections
|
37
37
|
def check
|
38
38
|
connections = Array(@block.call)
|
39
39
|
|
40
40
|
results = connections.map{|connection| database_up?(connection) }
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
[(results.all? && results.count > 0), "#{
|
41
|
+
|
42
|
+
primary_status = results.first ? "Primary: Up" : "Primary: Down"
|
43
|
+
replica_status = results.last ? "Replica: Up" : "Replica: Down"
|
44
|
+
|
45
|
+
[(results.all? && results.count > 0), "#{primary_status} - #{replica_status}"]
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
private
|
49
49
|
def database_up?(connection)
|
50
50
|
connection.active?
|
data/lib/easymon/version.rb
CHANGED
File without changes
|
File without changes
|
data/test/test_helper.rb
CHANGED
@@ -3,50 +3,50 @@ require 'test_helper'
|
|
3
3
|
class SplitActiveRecordCheckTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
test "#run sets success conditions on successful run" do
|
6
|
-
|
6
|
+
primary = ActiveRecord::Base.connection
|
7
7
|
Easymon::Base.establish_connection
|
8
|
-
|
8
|
+
replica = Easymon::Base.connection
|
9
9
|
|
10
|
-
check = Easymon::SplitActiveRecordCheck.new { [
|
10
|
+
check = Easymon::SplitActiveRecordCheck.new { [primary, replica] }
|
11
11
|
|
12
12
|
results = check.check
|
13
13
|
|
14
|
-
assert_equal("
|
14
|
+
assert_equal("Primary: Up - Replica: Up", results[1])
|
15
15
|
assert_equal(true, results[0])
|
16
16
|
end
|
17
17
|
|
18
|
-
test "#run sets failed conditions when
|
19
|
-
|
18
|
+
test "#run sets failed conditions when replica is down" do
|
19
|
+
primary = ActiveRecord::Base.connection
|
20
20
|
Easymon::Base.establish_connection
|
21
|
-
|
21
|
+
replica = Easymon::Base.connection
|
22
22
|
|
23
|
-
|
23
|
+
replica.stubs(:active?).raises("boom")
|
24
24
|
|
25
|
-
check = Easymon::SplitActiveRecordCheck.new { [
|
25
|
+
check = Easymon::SplitActiveRecordCheck.new { [primary, replica] }
|
26
26
|
results = check.check
|
27
27
|
|
28
|
-
assert_equal("
|
28
|
+
assert_equal("Primary: Up - Replica: Down", results[1])
|
29
29
|
assert_equal(false, results[0])
|
30
30
|
end
|
31
31
|
|
32
|
-
test "#run sets failed conditions when
|
33
|
-
|
32
|
+
test "#run sets failed conditions when primary is down" do
|
33
|
+
primary = ActiveRecord::Base.connection
|
34
34
|
Easymon::Base.establish_connection
|
35
|
-
|
35
|
+
replica = Easymon::Base.connection
|
36
36
|
|
37
|
-
|
37
|
+
primary.stubs(:active?).raises("boom")
|
38
38
|
|
39
|
-
check = Easymon::SplitActiveRecordCheck.new { [
|
39
|
+
check = Easymon::SplitActiveRecordCheck.new { [primary, replica] }
|
40
40
|
results = check.check
|
41
41
|
|
42
|
-
assert_equal("
|
42
|
+
assert_equal("Primary: Down - Replica: Up", results[1])
|
43
43
|
assert_equal(false, results[0])
|
44
44
|
end
|
45
45
|
|
46
46
|
test "given nil as a config" do
|
47
47
|
check = Easymon::SplitActiveRecordCheck.new { }
|
48
48
|
results = check.check
|
49
|
-
assert_equal("
|
49
|
+
assert_equal("Primary: Down - Replica: Down", results[1])
|
50
50
|
assert_equal(false, results[0])
|
51
51
|
end
|
52
52
|
end
|
@@ -63,8 +63,8 @@ module Easymon
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def database_configuration
|
66
|
-
env = "#{Rails.env}
|
67
|
-
|
66
|
+
env = "#{Rails.env}_replica"
|
67
|
+
YAML.load_file(Rails.root.join('config/database.yml'))[env]
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easymon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Anderson
|
@@ -70,28 +70,28 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
73
|
+
version: '1.2'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
80
|
+
version: '1.2'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: mocha
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '1.
|
87
|
+
version: '1.11'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: '1.
|
94
|
+
version: '1.11'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: dalli
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- test/controllers/easymon/checks_controller_test.rb
|
143
143
|
- test/dummy/README.rdoc
|
144
144
|
- test/dummy/Rakefile
|
145
|
+
- test/dummy/app/assets/config/manifest.js
|
145
146
|
- test/dummy/app/assets/javascripts/application.js
|
146
147
|
- test/dummy/app/assets/javascripts/easymon.js
|
147
148
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -173,6 +174,7 @@ files:
|
|
173
174
|
- test/dummy/config/memcached.yml
|
174
175
|
- test/dummy/config/redis.yml
|
175
176
|
- test/dummy/config/routes.rb
|
177
|
+
- test/dummy/config/storage.yml
|
176
178
|
- test/dummy/log/development.log
|
177
179
|
- test/dummy/log/test.log
|
178
180
|
- test/dummy/public/404.html
|
@@ -237,6 +239,7 @@ test_files:
|
|
237
239
|
- test/dummy/app/views/easymon/index.html.erb
|
238
240
|
- test/dummy/app/views/easymon/show.html.erb
|
239
241
|
- test/dummy/app/views/layouts/application.html.erb
|
242
|
+
- test/dummy/app/assets/config/manifest.js
|
240
243
|
- test/dummy/app/assets/javascripts/easymon.js
|
241
244
|
- test/dummy/app/assets/javascripts/application.js
|
242
245
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -250,6 +253,7 @@ test_files:
|
|
250
253
|
- test/dummy/config/environments/test.rb
|
251
254
|
- test/dummy/config/environment.rb
|
252
255
|
- test/dummy/config/redis.yml
|
256
|
+
- test/dummy/config/storage.yml
|
253
257
|
- test/dummy/config/application.rb
|
254
258
|
- test/dummy/config/memcached.yml
|
255
259
|
- test/dummy/config/database.yml
|