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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 837e823c90a18054f24eeb42e3079edfaed7de08d103dc66c476e5f31d237640
4
- data.tar.gz: 94b9be499506937b5728f7f24863a7fec3ecad6ef0dcf892fca13098cd2d3af7
3
+ metadata.gz: 0e806e827a25b48a56d508d9e002831bad2cabd996fa91ced9409bf2cf74edf4
4
+ data.tar.gz: b72f0abcf77e96dc49a4968ed5094b24b70714fb721ae2c04a20067ea448b503
5
5
  SHA512:
6
- metadata.gz: 1774e274f3cb5a3843629d446cd3e462d063ed9419ac0c904d1261006c4095c3338a7a08fbed249ace233270722528f6871aef8865417e31701ce8eba1e4467d
7
- data.tar.gz: 9a7496f4e793c9b2a6a127b0276154ea14f24171c5857780f8109f00e5c56f9f1a152bce7063cc543bc8e5690bb477f4f5ebadccdb40ced497309a703f0841a0
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
@@ -1,7 +1,8 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - 'bin/*'
4
- Documentation:
4
+
5
+ Style/Documentation:
5
6
  Enabled: false
6
7
 
7
8
  Metrics/BlockLength:
data/.travis.yml CHANGED
@@ -5,7 +5,10 @@ language: ruby
5
5
  rvm:
6
6
  - 2.6.4
7
7
 
8
- bundler_args: --without system_tests
8
+ bundler_args: --without system_tests --jobs=3 --retry=3
9
+
10
+ before_install:
11
+ - gem install bundler
9
12
 
10
13
  script: bin/travis
11
14
 
data/README.md CHANGED
@@ -1,4 +1,11 @@
1
- # HealthCheck
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
 
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # coding: utf-8
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 'net-telnet'
28
- spec.add_dependency 'faraday'
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 'rake', '~> 10.0'
33
- spec.add_development_dependency 'rack-test', '~> 1.1.0'
34
- spec.add_development_dependency 'rspec', '~> 3.5.0'
35
- spec.add_development_dependency 'rubocop', '0.78.0'
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
@@ -10,6 +10,7 @@ module DeepHealthCheck
10
10
 
11
11
  def call
12
12
  return no_dependencies_response if @dependencies.nil?
13
+
13
14
  api_health_check health_status_code, @dependencies
14
15
  end
15
16
 
@@ -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
- { status: response.status, details: response.body }
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
@@ -35,8 +35,9 @@ module DeepHealthCheck
35
35
  'Telnetmode' => false,
36
36
  'Prompt' => /^\+OK/n
37
37
  )
38
+
38
39
  down
39
- rescue
40
+ rescue StandardError
40
41
  down
41
42
  end
42
43
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepHealthCheck
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  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.1
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: 2019-12-20 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: net-telnet
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: faraday
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: faraday_middleware
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
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: '0'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: bundler
56
+ name: codecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.1'
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: '2.1'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
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: '10.0'
85
+ version: '1.1'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.1.0
83
89
  - !ruby/object:Gem::Dependency
84
- name: rack-test
90
+ name: rake
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: 1.1.0
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: 1.1.0
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.5.0
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.5.0
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: 0.78.0
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: 0.78.0
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.0.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