okcomputer 1.10.0 → 1.11.0
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 +4 -4
- data/README.markdown +14 -0
- data/config/locales/okcomputer.en.yml +2 -2
- data/lib/ok_computer/built_in_checks/optional_check.rb +19 -0
- data/lib/ok_computer/check.rb +17 -3
- data/lib/ok_computer/configuration.rb +7 -0
- data/lib/ok_computer/version.rb +1 -1
- data/lib/okcomputer.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2e3f9c41d2f33dae8b0c4150153002bd0ac548
|
4
|
+
data.tar.gz: 04f39dab21da2e5e854afd1690a35857fe1f0aaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cc80015fab9fdfb41e2b7f10ce0c864ee288282f0c48f7e7477a13c19dae3161fdfe5dfe78b87a9e50f80e9e05da9e2b6a44c2e3132a486c9bb7244b42578b2
|
7
|
+
data.tar.gz: 3cb175228a439530547d779bc9efb4ed5b8f3909bcf25f52a7220bdc32e429cc2c49b7e91a0a9e73b3641474b75baae502c50714a264eaabf19aeac52feea488
|
data/README.markdown
CHANGED
@@ -126,6 +126,20 @@ end
|
|
126
126
|
OkComputer::Registry.register "check_for_odds", MyCustomCheck.new
|
127
127
|
```
|
128
128
|
|
129
|
+
### Registering Optional Checks
|
130
|
+
|
131
|
+
Register an optional check like so:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
# ...
|
135
|
+
OkComputer::Registry.register "some_optional_check", OkComputer::ResqueBackedUpCheck.new("critical", 100)
|
136
|
+
# ...
|
137
|
+
|
138
|
+
OkComputer.make_optional %w(some_optional_check another_optional_check)
|
139
|
+
```
|
140
|
+
|
141
|
+
This check will run and report its status, but will not affect the HTTP status code returned.
|
142
|
+
|
129
143
|
### Customizing plain-text output
|
130
144
|
|
131
145
|
The plain-text output flows through Rails' internationalization framework.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module OkComputer
|
4
|
+
# This check wraps another check and forces it to be successful so as to
|
5
|
+
# avoid triggering alerts.
|
6
|
+
class OptionalCheck < SimpleDelegator
|
7
|
+
# Public: Always successful
|
8
|
+
def success?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
# Public: The text output of performing the check
|
13
|
+
#
|
14
|
+
# Returns a String
|
15
|
+
def to_text
|
16
|
+
"#{__getobj__.to_text} (OPTIONAL)"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/ok_computer/check.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "benchmark"
|
2
|
+
|
1
3
|
module OkComputer
|
2
4
|
class Check
|
3
5
|
# to be set by Registry upon registration
|
@@ -6,11 +8,15 @@ module OkComputer
|
|
6
8
|
attr_accessor :failure_occurred
|
7
9
|
# nil by default, set by #check to control the output
|
8
10
|
attr_accessor :message
|
11
|
+
# Float::NAN by default, set by #run to the elapsed time to run #check
|
12
|
+
attr_accessor :time
|
9
13
|
|
10
14
|
# Public: Run the check
|
11
15
|
def run
|
12
16
|
clear
|
13
|
-
|
17
|
+
with_benchmarking do
|
18
|
+
check
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
# Private: Perform the appropriate check
|
@@ -27,7 +33,7 @@ module OkComputer
|
|
27
33
|
# Returns a String
|
28
34
|
def to_text
|
29
35
|
passfail = success? ? "passed" : "failed"
|
30
|
-
I18n.t("okcomputer.check.#{passfail}", registrant_name: registrant_name, message: message)
|
36
|
+
I18n.t("okcomputer.check.#{passfail}", registrant_name: registrant_name, message: message, time: "#{time ? sprintf('%0.000f', time) : '?'}s")
|
31
37
|
end
|
32
38
|
|
33
39
|
# Public: The JSON output of performing the check
|
@@ -36,7 +42,7 @@ module OkComputer
|
|
36
42
|
def to_json(*args)
|
37
43
|
# NOTE swallowing the arguments that Rails passes by default since we don't care. This may prove to be a bad idea
|
38
44
|
# Rails passes stuff like this: {:prefixes=>["ok_computer", "application"], :template=>"show", :layout=>#<Proc>}]
|
39
|
-
{registrant_name => {:message => message, :success => success
|
45
|
+
{registrant_name => {:message => message, :success => success?, :time => time}}.to_json
|
40
46
|
end
|
41
47
|
|
42
48
|
# Public: Whether the check passed
|
@@ -62,6 +68,14 @@ module OkComputer
|
|
62
68
|
def clear
|
63
69
|
self.failure_occurred = false
|
64
70
|
self.message = nil
|
71
|
+
self.time = Float::NAN
|
72
|
+
end
|
73
|
+
|
74
|
+
# Private: Benchmark the time it takes to run the block
|
75
|
+
def with_benchmarking
|
76
|
+
self.time = Benchmark.realtime do
|
77
|
+
yield
|
78
|
+
end
|
65
79
|
end
|
66
80
|
|
67
81
|
CheckNotDefined = Class.new(StandardError)
|
@@ -40,6 +40,13 @@ module OkComputer
|
|
40
40
|
username && password
|
41
41
|
end
|
42
42
|
|
43
|
+
# Public: Mark listed checks as optional
|
44
|
+
def self.make_optional(checks)
|
45
|
+
checks.each do |check|
|
46
|
+
OkComputer::Registry.register check, OkComputer::OptionalCheck.new(OkComputer::Registry.fetch(check))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
43
50
|
class << self
|
44
51
|
# Public: The route to automatically mount the OkComputer engine. Setting to false
|
45
52
|
# prevents OkComputer from automatically mounting itself.
|
data/lib/ok_computer/version.rb
CHANGED
data/lib/okcomputer.rb
CHANGED
@@ -19,6 +19,7 @@ require "ok_computer/built_in_checks/elasticsearch_check"
|
|
19
19
|
require "ok_computer/built_in_checks/mongoid_check"
|
20
20
|
require "ok_computer/built_in_checks/neo4j_check"
|
21
21
|
require "ok_computer/built_in_checks/mongoid_replica_set_check"
|
22
|
+
require "ok_computer/built_in_checks/optional_check"
|
22
23
|
require "ok_computer/built_in_checks/rabbitmq_check"
|
23
24
|
require "ok_computer/built_in_checks/redis_check"
|
24
25
|
require "ok_computer/built_in_checks/resque_backed_up_check"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: okcomputer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Byrne
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/ok_computer/built_in_checks/mongoid_check.rb
|
84
84
|
- lib/ok_computer/built_in_checks/mongoid_replica_set_check.rb
|
85
85
|
- lib/ok_computer/built_in_checks/neo4j_check.rb
|
86
|
+
- lib/ok_computer/built_in_checks/optional_check.rb
|
86
87
|
- lib/ok_computer/built_in_checks/rabbitmq_check.rb
|
87
88
|
- lib/ok_computer/built_in_checks/redis_check.rb
|
88
89
|
- lib/ok_computer/built_in_checks/resque_backed_up_check.rb
|