deep_health_check 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codecov.yml +36 -0
- data/.rubocop.yml +2 -1
- data/.travis.yml +4 -1
- data/README.md +18 -1
- data/deep_health_check.gemspec +9 -11
- data/lib/deep_health_check/db_health_check.rb +2 -2
- data/lib/deep_health_check/dependency_health_check.rb +1 -0
- data/lib/deep_health_check/http_dependency_health_check.rb +14 -3
- data/lib/deep_health_check/tcp_dependency_health_check.rb +2 -1
- data/lib/deep_health_check/version.rb +1 -1
- metadata +46 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e806e827a25b48a56d508d9e002831bad2cabd996fa91ced9409bf2cf74edf4
|
4
|
+
data.tar.gz: b72f0abcf77e96dc49a4968ed5094b24b70714fb721ae2c04a20067ea448b503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a85264724ece119c51a703211a4010757d112120ce4ae9b6d0d6bd51f8b9b339b3b510e1b957e98efecc3b3e79c06fe732945c9fa5e4c01bac8d926e862699
|
7
|
+
data.tar.gz: 4af00a8c3c81f2fcbe87f3f4482962eeb386ae60ed3adfab61c2813f7621872737cff08e2fff68eb53b05e2d1caadbbc8a60ae96e517a7b334142721da1e7650
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: Codecov
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Run rspec to generate code coverage
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby 2.6
|
16
|
+
uses: actions/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
version: 2.6.x
|
19
|
+
|
20
|
+
- name: Run test cases
|
21
|
+
run: |
|
22
|
+
gem install bundler
|
23
|
+
bundle install
|
24
|
+
bundle exec rspec
|
25
|
+
env:
|
26
|
+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
|
27
|
+
|
28
|
+
- name: Slack notification Success
|
29
|
+
if: success()
|
30
|
+
env:
|
31
|
+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
32
|
+
uses: cemkiy/action-slacker@master
|
33
|
+
with:
|
34
|
+
channel: '#github-ci-actions'
|
35
|
+
icon_url: 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
|
36
|
+
username: 'GitHub'
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# DeepHealthCheck
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/deep_health_check.svg)](https://badge.fury.io/rb/deep_health_check)
|
4
|
+
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
5
|
+
[![Build Status](https://travis-ci.org/wshihadeh/deep_health_check.svg?branch=master)](https://travis-ci.org/wshihadeh/deep_health_check)
|
6
|
+
[![Depfu](https://badges.depfu.com/badges/b29d275b0743e77163a813ac51251be9/count.svg)](https://depfu.com/github/wshihadeh/deep_health_check?project_id=10389)
|
7
|
+
![Codecov](https://img.shields.io/codecov/c/github/wshihadeh/deep_health_check)
|
8
|
+
|
2
9
|
|
3
10
|
A simple Health status API
|
4
11
|
|
@@ -26,7 +33,17 @@ Health check middleware expose the following endpoints
|
|
26
33
|
- /health
|
27
34
|
- /db_health
|
28
35
|
- /tcp_dependencies_health
|
36
|
+
+ dependencies must follow the below format and can be coonfigured using envioronment varables such as:
|
37
|
+
```sh
|
38
|
+
# TCP_DEPENDENCY_${00..99}=${ip_or_host}:${port}
|
39
|
+
TCP_DEPENDENCY_00=127.0.0.0:8080
|
40
|
+
```
|
29
41
|
- /http_dependencies_health
|
42
|
+
+ dependencies must be valid http url and can be coonfigured using envioronment varables such as:
|
43
|
+
```sh
|
44
|
+
# HTTP_DEPENDENCY_${00..99}=${ip_or_host}:${port}
|
45
|
+
HTTP_DEPENDENCY_00=http://127.0.0.0:8080/health
|
46
|
+
```
|
30
47
|
|
31
48
|
Some of these endpoints provide information about the database and system status. By Default these endpoints are not protected and are accessible publicly. To reduce the security risk introduced by exposing these endpoints, We can protect them using htauth credentials. The following page provide all the necessary steps needed to achieve this task.
|
32
49
|
|
data/deep_health_check.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
6
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
5
|
require 'deep_health_check/version'
|
8
6
|
|
@@ -13,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
13
11
|
spec.email = ['shihadeh.dev@gmail.com']
|
14
12
|
|
15
13
|
spec.summary = 'Provides a health check API endpoint'
|
16
|
-
spec.description = 'Provides a health check API endpoint'
|
14
|
+
spec.description = 'Provides a health check API endpoint for rack apps'
|
17
15
|
spec.homepage = 'https://github.com/wshihadeh/deep_health_check'
|
18
16
|
spec.license = 'MIT'
|
19
17
|
|
@@ -24,13 +22,13 @@ Gem::Specification.new do |spec|
|
|
24
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
23
|
spec.require_paths = ['lib']
|
26
24
|
|
27
|
-
spec.add_dependency '
|
28
|
-
spec.add_dependency '
|
29
|
-
spec.add_dependency 'faraday_middleware'
|
25
|
+
spec.add_dependency 'faraday', '~> 1.0'
|
26
|
+
spec.add_dependency 'net-telnet', '~> 0.2'
|
30
27
|
|
31
28
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
32
|
-
spec.add_development_dependency '
|
33
|
-
spec.add_development_dependency 'rack-test', '~> 1.1.0'
|
34
|
-
spec.add_development_dependency '
|
35
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'codecov', '~> 0'
|
30
|
+
spec.add_development_dependency 'rack-test', '~> 1.1', '>= 1.1.0'
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '1.23.0'
|
36
34
|
end
|
@@ -25,7 +25,7 @@ module DeepHealthCheck
|
|
25
25
|
data[:db_size] = ActiveRecord::Base.connection_pool.size
|
26
26
|
data[:db_conn_size] = ActiveRecord::Base.connection_pool.connections.size
|
27
27
|
data
|
28
|
-
rescue
|
28
|
+
rescue StandardError
|
29
29
|
{}
|
30
30
|
end
|
31
31
|
|
@@ -35,7 +35,7 @@ module DeepHealthCheck
|
|
35
35
|
data[:terminated_count] = Delayed::Job.where.not(failed_at: nil).count
|
36
36
|
data[:faild_dj_count] = Delayed::Job.where(failed_at: nil)
|
37
37
|
.where('attempts > 0').count
|
38
|
-
rescue
|
38
|
+
rescue StandardError
|
39
39
|
{}
|
40
40
|
end
|
41
41
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
-
require 'faraday_middleware'
|
5
4
|
|
6
5
|
module DeepHealthCheck
|
7
6
|
class HTTPDependencyHealthCheck < DependencyHealthCheck
|
7
|
+
CONTENT_TYPE = 'Content-Type'
|
8
|
+
JSON_MIME_TYPE = 'application/json'
|
9
|
+
|
8
10
|
def initialize
|
9
11
|
@type = 'http'
|
10
12
|
@dependencies = process_dependencies fetch_dependencies_from_env
|
@@ -32,14 +34,23 @@ module DeepHealthCheck
|
|
32
34
|
|
33
35
|
def http_status(url)
|
34
36
|
response = faraday.get url
|
35
|
-
|
37
|
+
response_body = extract_response_body response
|
38
|
+
{ status: response.status, details: response_body }
|
36
39
|
rescue RuntimeError, Faraday::Error => e
|
37
40
|
{ status: nil, details: e.inspect }
|
38
41
|
end
|
39
42
|
|
43
|
+
def extract_response_body(response)
|
44
|
+
unless response.headers[CONTENT_TYPE] == JSON_MIME_TYPE
|
45
|
+
return response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
require 'json' unless defined?(::JSON)
|
49
|
+
JSON.parse(response.body)
|
50
|
+
end
|
51
|
+
|
40
52
|
def faraday
|
41
53
|
Faraday.new do |builder|
|
42
|
-
builder.response :json, content_type: /\bjson$/
|
43
54
|
builder.response(:encoding) if defined?(Faraday::Encoding)
|
44
55
|
builder.adapter Faraday.default_adapter
|
45
56
|
end
|
metadata
CHANGED
@@ -1,134 +1,147 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_health_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Al-waleed shihadeh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: net-telnet
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: codecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rack-test
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.1'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.1.0
|
76
79
|
type: :development
|
77
80
|
prerelease: false
|
78
81
|
version_requirements: !ruby/object:Gem::Requirement
|
79
82
|
requirements:
|
80
83
|
- - "~>"
|
81
84
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
85
|
+
version: '1.1'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.1.0
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: rake
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
95
|
+
version: '13.0'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
102
|
+
version: '13.0'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: rspec
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: 3.
|
109
|
+
version: '3.9'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 3.9.0
|
104
113
|
type: :development
|
105
114
|
prerelease: false
|
106
115
|
version_requirements: !ruby/object:Gem::Requirement
|
107
116
|
requirements:
|
108
117
|
- - "~>"
|
109
118
|
- !ruby/object:Gem::Version
|
110
|
-
version: 3.
|
119
|
+
version: '3.9'
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 3.9.0
|
111
123
|
- !ruby/object:Gem::Dependency
|
112
124
|
name: rubocop
|
113
125
|
requirement: !ruby/object:Gem::Requirement
|
114
126
|
requirements:
|
115
127
|
- - '='
|
116
128
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
129
|
+
version: 1.23.0
|
118
130
|
type: :development
|
119
131
|
prerelease: false
|
120
132
|
version_requirements: !ruby/object:Gem::Requirement
|
121
133
|
requirements:
|
122
134
|
- - '='
|
123
135
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
125
|
-
description: Provides a health check API endpoint
|
136
|
+
version: 1.23.0
|
137
|
+
description: Provides a health check API endpoint for rack apps
|
126
138
|
email:
|
127
139
|
- shihadeh.dev@gmail.com
|
128
140
|
executables: []
|
129
141
|
extensions: []
|
130
142
|
extra_rdoc_files: []
|
131
143
|
files:
|
144
|
+
- ".github/workflows/codecov.yml"
|
132
145
|
- ".github/workflows/gempush.yml"
|
133
146
|
- ".gitignore"
|
134
147
|
- ".rspec"
|
@@ -173,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
186
|
- !ruby/object:Gem::Version
|
174
187
|
version: '0'
|
175
188
|
requirements: []
|
176
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.2.22
|
177
190
|
signing_key:
|
178
191
|
specification_version: 4
|
179
192
|
summary: Provides a health check API endpoint
|