rx-healthcheck 0.1.2 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/rx/check/file_system_check.rb +8 -5
- data/lib/rx/check/generic_check.rb +6 -3
- data/lib/rx/check/http_check.rb +4 -3
- data/lib/rx/check/result.rb +2 -2
- data/lib/rx/concurrent/future.rb +4 -0
- data/lib/rx/concurrent/thread_pool.rb +18 -1
- data/lib/rx/middleware.rb +8 -4
- data/lib/rx/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a5089cc2aca4dab181a11a5aa9a3135862d7de57976ded482366a9e147ac7a8
|
4
|
+
data.tar.gz: 4ec642b3e93f6b0f983cb7dff58b4bed8ede3e64dd7655bd1cac7f76583c7dfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 439bc089d1ce63f1c63f687cdf0b8b473bbcb2f6bbf3c04a847905d176cdb667e6f6c3b6e754121af685b87fc2b00f318ca3e4c6fc2de17fd80cd4cd88693ff2
|
7
|
+
data.tar.gz: 37c97bcd6967d3d336e669d78b6474978771c0d7dbc79daca8276dd66484c2485398f1cc6bd888c5f46f63e4855c33c9b4bb70a7b7e042937b588259e7b61a0f
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,17 +3,20 @@ module Rx
|
|
3
3
|
class FileSystemCheck
|
4
4
|
FILENAME = "rx".freeze
|
5
5
|
|
6
|
-
attr_reader :name
|
6
|
+
attr_reader :name, :timeout
|
7
7
|
|
8
|
-
def initialize(name = "fs")
|
8
|
+
def initialize(name = "fs", timeout = 0)
|
9
9
|
@name = name
|
10
|
+
@timeout = 0
|
10
11
|
end
|
11
12
|
|
12
13
|
def check
|
13
14
|
Result.from(name) do
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
Timeout::timeout(timeout) do
|
16
|
+
!!Tempfile.open(FILENAME) do |f|
|
17
|
+
f.write("ok")
|
18
|
+
f.flush
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -1,16 +1,19 @@
|
|
1
|
+
require "timeout"
|
2
|
+
|
1
3
|
module Rx
|
2
4
|
module Check
|
3
5
|
class GenericCheck
|
4
|
-
attr_reader :name
|
6
|
+
attr_reader :name, :timeout
|
5
7
|
|
6
|
-
def initialize(callable, name = "generic")
|
8
|
+
def initialize(callable, name = "generic", timeout = 0)
|
7
9
|
@callable = callable
|
8
10
|
@name = name
|
11
|
+
@timeout = timeout
|
9
12
|
end
|
10
13
|
|
11
14
|
def check
|
12
15
|
Result.from(name) do
|
13
|
-
callable.call
|
16
|
+
Timeout::timeout(timeout) { callable.call }
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
data/lib/rx/check/http_check.rb
CHANGED
@@ -3,17 +3,18 @@ require "uri"
|
|
3
3
|
module Rx
|
4
4
|
module Check
|
5
5
|
class HttpCheck
|
6
|
-
attr_reader :name
|
6
|
+
attr_reader :name, :timeout
|
7
7
|
|
8
|
-
def initialize(url, name = "http")
|
8
|
+
def initialize(url, name = "http", timeout: 1)
|
9
9
|
@url = URI(url)
|
10
10
|
@name = name
|
11
|
+
@timeout = timeout
|
11
12
|
end
|
12
13
|
|
13
14
|
def check
|
14
15
|
Result.from(name) do
|
15
16
|
http = Net::HTTP.new(url.host, url.port)
|
16
|
-
http.read_timeout =
|
17
|
+
http.read_timeout = timeout
|
17
18
|
http.use_ssl = url.scheme == "https"
|
18
19
|
|
19
20
|
response = http.request(Net::HTTP::Get.new(path))
|
data/lib/rx/check/result.rb
CHANGED
@@ -2,7 +2,7 @@ module Rx
|
|
2
2
|
module Check
|
3
3
|
class Result
|
4
4
|
def self.from(check_name)
|
5
|
-
start_at =
|
5
|
+
start_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
6
6
|
err = nil
|
7
7
|
result = false
|
8
8
|
|
@@ -12,7 +12,7 @@ module Rx
|
|
12
12
|
err = ex
|
13
13
|
end
|
14
14
|
|
15
|
-
end_at =
|
15
|
+
end_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
16
16
|
|
17
17
|
Result.new(check_name, result, ((end_at - start_at) * 1000).round(2), err)
|
18
18
|
end
|
data/lib/rx/concurrent/future.rb
CHANGED
@@ -6,6 +6,7 @@ module Rx
|
|
6
6
|
def initialize(size = Etc.nprocessors)
|
7
7
|
@pool = []
|
8
8
|
@size = size
|
9
|
+
@pid = Process.pid
|
9
10
|
end
|
10
11
|
|
11
12
|
def shutdown
|
@@ -25,17 +26,33 @@ module Rx
|
|
25
26
|
self
|
26
27
|
end
|
27
28
|
|
29
|
+
def restart
|
30
|
+
shutdown
|
31
|
+
start
|
32
|
+
end
|
33
|
+
|
28
34
|
def started?
|
29
35
|
pool.map(&:alive?).any?
|
30
36
|
end
|
31
37
|
|
32
38
|
def submit(&block)
|
39
|
+
restart_on_fork if forked?
|
40
|
+
|
33
41
|
return unless started?
|
34
42
|
queue << block
|
35
43
|
end
|
36
44
|
|
37
45
|
private
|
38
|
-
attr_reader :pool, :queue, :size
|
46
|
+
attr_reader :pid, :pool, :queue, :size
|
47
|
+
|
48
|
+
def forked?
|
49
|
+
Process.pid != pid
|
50
|
+
end
|
51
|
+
|
52
|
+
def restart_on_fork
|
53
|
+
restart
|
54
|
+
@pid = Process.pid
|
55
|
+
end
|
39
56
|
|
40
57
|
def worker
|
41
58
|
-> {
|
data/lib/rx/middleware.rb
CHANGED
@@ -23,11 +23,11 @@ module Rx
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def call(env)
|
26
|
-
unless health_check_request?(env)
|
26
|
+
unless health_check_request?(path(env))
|
27
27
|
return app.call(env)
|
28
28
|
end
|
29
29
|
|
30
|
-
case env
|
30
|
+
case path(env)
|
31
31
|
when "/liveness"
|
32
32
|
ok = check_to_component(liveness_checks).map { |x| x[:status] == 200 }.all?
|
33
33
|
liveness_response(ok)
|
@@ -57,14 +57,18 @@ module Rx
|
|
57
57
|
Rx::Cache::InMemoryCache.new
|
58
58
|
end
|
59
59
|
|
60
|
-
def health_check_request?(
|
61
|
-
%w[/liveness /readiness /deep].include?(
|
60
|
+
def health_check_request?(path)
|
61
|
+
%w[/liveness /readiness /deep].include?(path)
|
62
62
|
end
|
63
63
|
|
64
64
|
def liveness_response(is_ok)
|
65
65
|
[is_ok ? 200 : 503, {}, []]
|
66
66
|
end
|
67
67
|
|
68
|
+
def path(env)
|
69
|
+
env["PATH_INFO"] || env["REQUEST_PATH"] || env["REQUEST_URI"]
|
70
|
+
end
|
71
|
+
|
68
72
|
def readiness_response(components)
|
69
73
|
status = components.map { |x| x[:status] == 200 }.all? ? 200 : 503
|
70
74
|
|
data/lib/rx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rx-healthcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Pendleton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
|
-
rubygems_version: 3.1.
|
63
|
+
rubygems_version: 3.1.6
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: Standard health checks for Rails and Rack applications
|