hcheck 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: e8d9d1373ccfab7fe053f2413da9474f371b5cd9
4
- data.tar.gz: ece2db1ed128d3356a931cc635129f6369872645
3
+ metadata.gz: 4e3d277ec5fd7cb5d49761ed2437b79cbe60c3c2
4
+ data.tar.gz: bfcc780533bdef656e295a4211331f823ee77339
5
5
  SHA512:
6
- metadata.gz: 35332044c5f470d706ed3ec67fc080a316fdc707f52c4852b47e80bf720dd95b3a28d45b8c34e8d57f066134e5476056d6006ab275f51f95b37d7dfd8169953b
7
- data.tar.gz: 83aee556a3c44eb030fcb7df957f758b9c4bfa5febff4f2a60a7dc6c01da5584ddd004d9481d6af7937af479e4d83b2ad436627ee4fd2aaf719dba7869d73e78
6
+ metadata.gz: f58c28e881cb5de5c7520a846e911fcbf2d721fd77913bb38923725c94be5ae922156cef76a16bf05ee175f104f41919f2f9197ae3c731eea3fe12d1c23a7223
7
+ data.tar.gz: b0fd9d9d065454d8723a5fc82f6f78cb4a6bbb5c047bebee69c7fc917e36e26f474913f8689d627e0813e27fd502746fcbfa84c394553009f1d0f5b6b3f1fbd3
@@ -1,5 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.2
5
- before_install: gem install bundler -v 1.16.1
4
+ - 2.4.4
5
+ - 2.5.1
6
+ cache: bundler
7
+ branches:
8
+ only:
9
+ - master
10
+ script:
11
+ - bundle exec rake
12
+ - bundle exec rubocop --parallel
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hcheck (0.1.0)
4
+ hcheck (0.1.1)
5
5
  haml (~> 5.0)
6
6
  sinatra (~> 2.0)
7
7
 
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Hcheck
2
+ [![Build Status](https://travis-ci.com/cloudfactory/hcheck.svg?branch=master)](https://travis-ci.com/cloudfactory/hcheck)
2
3
 
3
4
  Configuration driven health checker for ruby apps. Can be mounted or booted as standalone app.
4
5
 
@@ -112,8 +113,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
112
113
  ## Todo
113
114
 
114
115
  Travis CI Integrations
115
- - Github PR status
116
- - Continuous Integration
116
+ - ~~Github PR status~~
117
+ - ~~Continuous Integration~~
117
118
  - Continuous release to RubyGems
118
119
 
119
120
  ## Contributing
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
19
  # to allow pushing to a single host or delete this section to allow pushing to any host.
20
20
  if spec.respond_to?(:metadata)
21
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
22
  else
23
23
  raise 'RubyGems 2.0 or newer is required to protect against ' \
24
24
  'public gem pushes.'
@@ -8,10 +8,6 @@ module Hcheck
8
8
  def status(config)
9
9
  client = Dalli::Client.new(config.delete(:url), config)
10
10
  client.get('_')
11
- 'ok'
12
- rescue Dalli::RingError => e
13
- Hcheck.logger.error "[HCheck] Memcached::Error::NoServerAvailable #{e.message}"
14
- 'bad'
15
11
  end
16
12
 
17
13
  def self.included(_base)
@@ -11,10 +11,6 @@ module Hcheck
11
11
  client = Mongo::Client.new(hosts, mongo_config.merge(server_selection_timeout: hosts.count * 2))
12
12
  client.database_names
13
13
  client.close
14
- 'ok'
15
- rescue Mongo::Error::NoServerAvailable => e
16
- Hcheck.logger.error "[HCheck] Mongo::Error::NoServerAvailable #{e.message}"
17
- 'bad'
18
14
  end
19
15
 
20
16
  def self.included(_base)
@@ -8,10 +8,6 @@ module Hcheck
8
8
  def status(config)
9
9
  connection = Mysql2::Client.new(config)
10
10
  connection.close
11
- 'ok'
12
- rescue Mysql2::Error => e
13
- Hcheck.logger.error "[HCheck] Mysql2::Error::ConnectionError #{e.message}"
14
- 'bad'
15
11
  end
16
12
 
17
13
  def self.included(_base)
@@ -10,15 +10,11 @@ module Hcheck
10
10
  url = URI.parse(config[:url])
11
11
  request = build_request(url)
12
12
 
13
- case request.request_head(url.path)
14
- when Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPInformation
15
- 'ok'
16
- else
17
- 'bad'
18
- end
19
- rescue Net::ReadTimeout, Errno::ECONNREFUSED => e
20
- Hcheck.logger.error "[HCheck] Ping Fail #{e.message}"
21
- 'bad'
13
+ res = request.request_head(url.path)
14
+
15
+ ok_responses = [Net::HTTPSuccess, Net::HTTPInformation, Net::HTTPMovedPermanently]
16
+
17
+ fail_with(res, url) unless ok_responses.include?(res.class)
22
18
  end
23
19
 
24
20
  def self.included(_base)
@@ -33,6 +29,11 @@ module Hcheck
33
29
  url.path = '/' if url.path.empty?
34
30
  req
35
31
  end
32
+
33
+ def fail_with(response, url)
34
+ raise Hcheck::Errors::HTTPError,
35
+ [response.class, response.code, response.message].join(' ') + " from #{url}"
36
+ end
36
37
  end
37
38
  end
38
39
  end
@@ -10,10 +10,6 @@ module Hcheck
10
10
  config[:dbname] = config.delete(:database) if config[:database]
11
11
 
12
12
  PG::Connection.new(config).close
13
- 'ok'
14
- rescue PG::ConnectionBad => e
15
- Hcheck.logger.error "[HCheck] PG::ConnectionBad #{e.message}"
16
- 'bad'
17
13
  end
18
14
 
19
15
  def self.included(_base)
@@ -9,16 +9,6 @@ module Hcheck
9
9
  connection = Bunny.new(config)
10
10
  connection.start
11
11
  connection.close
12
- 'ok'
13
- rescue Bunny::TCPConnectionFailed,
14
- Bunny::TCPConnectionFailedForAllHosts,
15
- Bunny::NetworkFailure,
16
- Bunny::AuthenticationFailureError,
17
- Bunny::PossibleAuthenticationFailureError,
18
- AMQ::Protocol::EmptyResponseError => e
19
-
20
- Hcheck.logger.error "[HCheck] Bunny::Error #{e.message}"
21
- 'bad'
22
12
  end
23
13
 
24
14
  def self.included(_base)
@@ -9,10 +9,6 @@ module Hcheck
9
9
  config[:sentinels] = config[:sentinels].map(&:symbolize_keys) if config[:sentinels]
10
10
 
11
11
  ::Redis.new(config).ping
12
- 'ok'
13
- rescue ::Redis::CannotConnectError => e
14
- Hcheck.logger.error "[HCheck] Redis server unavailable #{e.message}"
15
- 'bad'
16
12
  end
17
13
 
18
14
  def self.included(_base)
@@ -30,12 +30,20 @@ module Hcheck
30
30
  {
31
31
  name: @name,
32
32
  desc: @check,
33
- status: @check_not_available ? NOT_IMPLEMENTED_MSG : status(@options)
33
+ status: @check_not_available ? NOT_IMPLEMENTED_MSG : check_status
34
34
  }
35
35
  end
36
36
 
37
37
  private
38
38
 
39
+ def check_status
40
+ status(@options)
41
+ 'ok'
42
+ rescue StandardError => e
43
+ Hcheck.logger.error "[HCheck] #{e.class.name} #{e.message}"
44
+ 'bad'
45
+ end
46
+
39
47
  def load_mod
40
48
  Hcheck::Checks.const_get(@name.capitalize)
41
49
  rescue NameError
@@ -13,14 +13,17 @@ module Hcheck
13
13
  end
14
14
  end
15
15
 
16
+ # Invalid auth token, when hcheck secure enabled
16
17
  class InvalidAuthentication < HcheckError
17
18
  MSG = 'Invalid authenticity token!'
18
19
  end
19
20
 
21
+ # Incomplete auth setup, auth token not setup, when hcheck secure enabled
20
22
  class IncompleteAuthSetup < HcheckError
21
23
  MSG = 'Incomplete auth setup in HCheck server'
22
24
  end
23
25
 
26
+ # Configuration related error
24
27
  class ConfigurationError < HcheckError
25
28
  MSG = 'Hcheck configuration cannot not be found or read'
26
29
 
@@ -28,5 +31,12 @@ module Hcheck
28
31
  super("#{MSG}\n#{err.class}\n#{err.message}")
29
32
  end
30
33
  end
34
+
35
+ # HTTP related error
36
+ class HTTPError < HcheckError
37
+ def initialize(msg)
38
+ super("Couldn't get a successful response code. #{msg}")
39
+ end
40
+ end
31
41
  end
32
42
  end
@@ -25,7 +25,7 @@ end
25
25
  # Imported from rails/active_support
26
26
  class Object
27
27
  def blank?
28
- respond_to?(:empty?) ? !!empty? : !self
28
+ respond_to?(:empty?) ? empty? : !self
29
29
  end
30
30
 
31
31
  def present?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hcheck
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rohit Joshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
11
+ date: 2018-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml