hey_doctor 1.1.2 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/app/services/hey_doctor/check_application_health_service.rb +27 -8
- data/app/services/hey_doctor/check_database_health_service.rb +6 -6
- data/app/services/hey_doctor/check_redis_health_service.rb +4 -4
- data/app/services/hey_doctor/check_sidekiq_health_service.rb +43 -0
- data/lib/hey_doctor/version.rb +1 -1
- data/lib/hey_doctor.rb +6 -0
- data/spec/dummy/log/development.log +433 -0
- data/spec/dummy/log/test.log +1087 -0
- data/spec/lib/hey_doctor/hey_doctor_spec.rb +30 -10
- data/spec/services/hey_doctor/check_application_health_service_spec.rb +4 -4
- data/spec/services/hey_doctor/check_database_health_service_spec.rb +6 -6
- data/spec/services/hey_doctor/check_redis_health_service_spec.rb +4 -4
- data/spec/services/hey_doctor/check_sidekiq_health_service_spec.rb +71 -0
- data/spec/spec_helper.rb +2 -1
- metadata +74 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d854aed46a009b3d8fab4116a9ce9277fb76c7d3d1a9117dc28fa6c82a54e1f6
|
4
|
+
data.tar.gz: 0dd3285bbaaf52996df32277f7261aa35fceced3ffe749b4091de0b7db4d932f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288322908e582f60fbce12bcd4cac0f277b4ca23c8b549316538bc6abc16d7af33a6e2b6a7f48f43284a89066d776b82d5bd2622a36d304cdf2efe920d504a1b
|
7
|
+
data.tar.gz: 2c1b20cf9f589c57c494229ebab8e012e11de2e05f0d19a2d4710c2179adc46641c55227f7b56ee58a49e8d4ae7b6af4fa63240d52b995e3c4d029ee5088f9d3
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ Redis.current ||= Redis.new(url: ENV['REDIS_URL'])
|
|
39
39
|
|
40
40
|
It is very important to use the env `REDIS_URL`, because it will be used to check whether or not to render the redis response.
|
41
41
|
|
42
|
-
* Add a env var `RAILS_PORT` with the current application port.
|
42
|
+
* Add a env var `RAILS_PORT` with the current application port, it will also work with the env `PORT` for backward compatibility with GAE applications.
|
43
43
|
|
44
44
|
* Add this line to your application's Gemfile:
|
45
45
|
|
@@ -81,6 +81,8 @@ end
|
|
81
81
|
## Developing
|
82
82
|
|
83
83
|
```bash
|
84
|
+
docker network create dev-net # only the fist time you run this project
|
85
|
+
|
84
86
|
docker-compose build && docker-compose up
|
85
87
|
|
86
88
|
docker-compose exec web bash
|
@@ -97,11 +99,22 @@ Minimum coverage is set to 95%.
|
|
97
99
|
Change the tag in `lib/hey_doctor/version.rb` each release using [SEMVER](https://semver.org/lang/pt-BR/).
|
98
100
|
|
99
101
|
```bash
|
102
|
+
# After merging the PR checkout to master branch and update it.
|
103
|
+
git checkout master
|
104
|
+
git pull
|
105
|
+
|
106
|
+
# build gem in pkg/hey_doctor-TAG.gem (Also changes Gemfile.lock)
|
100
107
|
bundle exec rake build
|
101
|
-
|
108
|
+
|
109
|
+
# Add the changed files
|
110
|
+
git add Gemfile.lock lib/hey_doctor/version.rb
|
111
|
+
git commit -m "v0.0.0"
|
112
|
+
|
113
|
+
# Create a new git tag
|
114
|
+
git tag -a v0.0.0 -m "Description here."
|
102
115
|
|
103
116
|
bundle exec rake release
|
104
|
-
# Ask for rubygems credentials and makes the release
|
117
|
+
# Ask for rubygems credentials and makes the release, push the commit and the tag
|
105
118
|
```
|
106
119
|
## Contributing
|
107
120
|
|
@@ -3,15 +3,18 @@
|
|
3
3
|
class HeyDoctor::CheckApplicationHealthService
|
4
4
|
class << self
|
5
5
|
SUCCESS = {
|
6
|
-
|
7
|
-
|
6
|
+
success: true,
|
7
|
+
message: 'Application is running'
|
8
8
|
}.freeze
|
9
9
|
|
10
10
|
ERROR = {
|
11
|
-
|
12
|
-
|
11
|
+
success: false,
|
12
|
+
message: 'Application down, call the firefighters'
|
13
13
|
}.freeze
|
14
14
|
|
15
|
+
START_COUNTER = 1
|
16
|
+
DEFAULT_PORT = ENV['RAILS_PORT'] || ENV['PORT']
|
17
|
+
|
15
18
|
def call
|
16
19
|
return SUCCESS if responding?
|
17
20
|
|
@@ -21,15 +24,31 @@ class HeyDoctor::CheckApplicationHealthService
|
|
21
24
|
private
|
22
25
|
|
23
26
|
def responding?
|
24
|
-
app_http_code ==
|
27
|
+
app_http_code('localhost', DEFAULT_PORT, START_COUNTER) == 200
|
25
28
|
rescue StandardError
|
26
29
|
false
|
27
30
|
end
|
28
31
|
|
29
|
-
def app_http_code
|
30
|
-
|
32
|
+
def app_http_code(location, port, retry_counter)
|
33
|
+
ssl = port.to_i == 443
|
34
|
+
|
35
|
+
response = Net::HTTP.start(location, port, use_ssl: ssl) do |http|
|
31
36
|
http.head('/_ah/app_health')
|
32
|
-
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return response.code.to_i if retry_counter > 3
|
40
|
+
|
41
|
+
if response.is_a?(Net::HTTPRedirection)
|
42
|
+
location = response['location']&.match(/https:\/\/(\w+.\.\w+)\//)
|
43
|
+
|
44
|
+
unless location.nil?
|
45
|
+
retry_counter += 1
|
46
|
+
|
47
|
+
return app_http_code(location[1], 443, retry_counter)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
response.code.to_i
|
33
52
|
end
|
34
53
|
end
|
35
54
|
end
|
@@ -3,18 +3,18 @@
|
|
3
3
|
class HeyDoctor::CheckDatabaseHealthService
|
4
4
|
class << self
|
5
5
|
SUCCESS = {
|
6
|
-
|
7
|
-
|
6
|
+
success: true,
|
7
|
+
message: 'Database is connected'
|
8
8
|
}.freeze
|
9
9
|
|
10
10
|
MIGRATION_PENDING = {
|
11
|
-
|
12
|
-
|
11
|
+
success: true,
|
12
|
+
message: 'Pending migrations detected'
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
ERROR = {
|
16
|
-
|
17
|
-
|
16
|
+
success: false,
|
17
|
+
message: 'Error connecting to database'
|
18
18
|
}.freeze
|
19
19
|
|
20
20
|
def call
|
@@ -3,13 +3,13 @@
|
|
3
3
|
class HeyDoctor::CheckRedisHealthService
|
4
4
|
class << self
|
5
5
|
SUCCESS = {
|
6
|
-
|
7
|
-
|
6
|
+
success: true,
|
7
|
+
message: 'Redis is connected'
|
8
8
|
}.freeze
|
9
9
|
|
10
10
|
ERROR = {
|
11
|
-
|
12
|
-
|
11
|
+
success: false,
|
12
|
+
message: 'Error connecting to redis'
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
def call
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class HeyDoctor::CheckSidekiqHealthService
|
4
|
+
class << self
|
5
|
+
SUCCESS = {
|
6
|
+
success: true,
|
7
|
+
message: 'Sidekiq is connected'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
ERROR = {
|
11
|
+
success: false,
|
12
|
+
message: 'Error connecting to sidekiq'
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
NO_EXECUTOR = {
|
16
|
+
success: false,
|
17
|
+
message: 'None sidekiq host was found, add it to the ENV SIDEKIQ_HOSTS' \
|
18
|
+
' listing your machine(s) ip or dns using ; for each host'
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def call
|
22
|
+
return NO_EXECUTOR if hosts.blank?
|
23
|
+
|
24
|
+
hosts.map { |host| response(host).merge({ host: host }) }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def hosts
|
30
|
+
@hosts ||= ENV['SIDEKIQ_HOSTS']&.split(';')
|
31
|
+
end
|
32
|
+
|
33
|
+
def response(host)
|
34
|
+
connected?(host) ? SUCCESS : ERROR
|
35
|
+
end
|
36
|
+
|
37
|
+
def connected?(host)
|
38
|
+
system("ping -c1 #{host}")
|
39
|
+
rescue StandardError
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/hey_doctor/version.rb
CHANGED
data/lib/hey_doctor.rb
CHANGED
@@ -21,6 +21,12 @@ module HeyDoctor::Rack
|
|
21
21
|
response.merge!({ redis: ::HeyDoctor::CheckRedisHealthService.call })
|
22
22
|
end
|
23
23
|
|
24
|
+
unless ENV['SIDEKIQ_HOSTS'].blank?
|
25
|
+
response.merge!(
|
26
|
+
{ sidekiq: ::HeyDoctor::CheckSidekiqHealthService.call }
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
24
30
|
response.to_json
|
25
31
|
end
|
26
32
|
end
|