health_check 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,10 +23,6 @@ matrix:
23
23
  gemfile: test/rails_edge.gemfile
24
24
  env: RAILS_VERSION=edge
25
25
 
26
- - rvm: ruby-head
27
- gemfile: test/rails_edge.gemfile
28
- env: RAILS_VERSION=edge
29
-
30
26
  - rvm: ruby-head
31
27
  gemfile: test/rails_5.0.gemfile
32
28
  env: RAILS_VERSION=5.0
@@ -38,12 +34,12 @@ matrix:
38
34
  gemfile: test/rails_edge.gemfile
39
35
  env: RAILS_VERSION=edge
40
36
 
41
- - rvm: ruby-head
42
- gemfile: test/rails_edge.gemfile
43
- env: RAILS_VERSION=edge
44
-
45
37
  # ruby 5.0 Jun. 2016
46
38
 
39
+ - rvm: 2.3.1
40
+ gemfile: test/rails_5.0.gemfile
41
+ env: RAILS_VERSION=5.0
42
+
47
43
  - rvm: 2.2.2
48
44
  gemfile: test/rails_5.0.gemfile
49
45
  env: RAILS_VERSION=5.0
data/Gemfile CHANGED
@@ -15,6 +15,6 @@ group :development, :test do
15
15
  gem 'travis-lint'
16
16
  # mime-types 2.0 requires Ruby version >= 1.9.2
17
17
  # mime-types 3.0 requires Ruby version >= 2.0
18
- gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3.0' : '>= 3.0')
18
+ gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3' : '>= 3.0')
19
19
 
20
20
  end
@@ -38,10 +38,10 @@ The health_check controller disables sessions for versions that eagerly load ses
38
38
  * database - checks that the current migration level can be read from the database
39
39
  * email - basic check of email - :test returns true, :sendmail checks file is present and executable, :smtp sends HELO command to server and checks response
40
40
  * migration - checks that the database migration level matches that in db/migrations
41
- * redis\[-if-present\] - checks Redis connectivity
42
- * resque-redis\[-if-present\] - checks Resque connectivity to Redis
43
- * s3\[-if-present\] - checks proper permissions to s3 buckets
44
- * sidekiq-redis\[-if-present\] - checks Sidekiq connectivity to Redis
41
+ * redis / redis-if-present - checks Redis connectivity
42
+ * resque-redis / resque-redis-if-present - checks Resque connectivity to Redis
43
+ * s3 / s3-if-present - checks proper permissions to s3 buckets
44
+ * sidekiq-redis / sidekiq-redis-if-present - checks Sidekiq connectivity to Redis
45
45
  * site - checks rails is running sufficiently to render text
46
46
 
47
47
  Some checks have a *-if-present form, which only runs the check if the corresponding library has been required.
@@ -100,13 +100,23 @@ To change the configuration of health_check, create a file `config/initializers/
100
100
  config.standard_checks -= [ 'emailconf' ]
101
101
 
102
102
  # You can set what tests are run with the 'full' or 'all' parameter
103
- config.full_checks = ['database', 'migrations', 'custom', 'email', 'cache', 'redis', 'resque-redis', sidekiq-redis', 's3']
103
+ config.full_checks = ['database', 'migrations', 'custom', 'email', 'cache', 'redis', 'resque-redis', 'sidekiq-redis', 's3']
104
104
 
105
105
  # Add one or more custom checks that return a blank string if ok, or an error message if there is an error
106
106
  config.add_custom_check do
107
107
  CustomHealthCheck.perform_check # any code that returns blank on success and non blank string upon failure
108
108
  end
109
109
 
110
+ # max-age of response in seconds
111
+ # cache-control is public when max_age > 1 and basic_auth_username is not set
112
+ # You can force private without authentication for longer max_age by
113
+ # setting basic_auth_username but not basic_auth_password
114
+ config.max_age = 1
115
+
116
+ # Protect health endpoints with basic auth
117
+ # These default to nil and the endpoint is not protected
118
+ config.basic_auth_username = 'my_username'
119
+ config.basic_auth_password = 'my_password'
110
120
  end
111
121
 
112
122
  You may call add_custom_check multiple times with different tests. These tests will be included in the default list ("standard").
@@ -23,10 +23,20 @@ module HealthCheck
23
23
  mattr_accessor :http_status_for_error_object
24
24
  self.http_status_for_error_object = 500
25
25
 
26
+ # max-age of response in seconds
27
+ # cache-control is public when max_age > 1 and basic authentication is used
28
+ mattr_accessor :max_age
29
+ self.max_age = 1
30
+
26
31
  # s3 buckets
27
32
  mattr_accessor :buckets
28
33
  self.buckets = {}
29
34
 
35
+ # Basic Authentication
36
+ mattr_accessor :basic_auth_username, :basic_auth_password
37
+ self.basic_auth_username = nil
38
+ self.basic_auth_password = nil
39
+
30
40
  # Array of custom check blocks
31
41
  mattr_accessor :custom_checks
32
42
  mattr_accessor :full_checks
@@ -5,35 +5,45 @@ module HealthCheck
5
5
  class HealthCheckController < ActionController::Base
6
6
 
7
7
  layout false if self.respond_to? :layout
8
+ before_filter :authenticate
8
9
 
9
10
  def index
10
- checks = params[:checks] || 'standard'
11
- begin
12
- errors = HealthCheck::Utils.process_checks(checks)
13
- rescue Exception => e
14
- errors = e.message.blank? ? e.class.to_s : e.message.to_s
15
- end
16
- if errors.blank?
17
- response.headers['Last-Modified'] = Time.now.httpdate
18
- obj = { :healthy => true, :message => HealthCheck.success }
19
- respond_to do |format|
20
- format.html { render :text => HealthCheck.success, :content_type => 'text/plain' }
21
- format.json { render :json => obj }
22
- format.xml { render :xml => obj }
23
- format.any { render :text => HealthCheck.success, :content_type => 'text/plain' }
24
- end
25
- else
26
- msg = "health_check failed: #{errors}"
27
- obj = { :healthy => false, :message => msg }
28
- respond_to do |format|
29
- format.html { render :text => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain' }
30
- format.json { render :json => obj, :status => HealthCheck.http_status_for_error_object}
31
- format.xml { render :xml => obj, :status => HealthCheck.http_status_for_error_object }
32
- format.any { render :text => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain' }
33
- end
34
- # Log a single line as some uptime checkers only record that it failed, not the text returned
35
- if logger
36
- logger.info msg
11
+ last_modified = Time.now.utc
12
+ max_age = HealthCheck.max_age
13
+ if max_age > 1
14
+ last_modified = Time.at((last_modified.to_f / max_age).floor * max_age).utc
15
+ end
16
+ if stale?(:last_modified => last_modified, :public => (max_age > 1) && ! basic_auth_username)
17
+ # Rails 4.0 doesn't have :plain, but it is deprecated later on
18
+ plain_key = Rails.version < '4.1' ? :text : :plain
19
+ checks = params[:checks] || 'standard'
20
+ begin
21
+ errors = HealthCheck::Utils.process_checks(checks)
22
+ rescue Exception => e
23
+ errors = e.message.blank? ? e.class.to_s : e.message.to_s
24
+ end
25
+ response.headers['Cache-control'] = 'private, no-cache, must-revalidate' + (max_age > 0 ? ", max-age=#{max_age}" : '')
26
+ if errors.blank?
27
+ obj = { :healthy => true, :message => HealthCheck.success }
28
+ respond_to do |format|
29
+ format.html { render plain_key => HealthCheck.success, :content_type => 'text/plain' }
30
+ format.json { render :json => obj }
31
+ format.xml { render :xml => obj }
32
+ format.any { render plain_key => HealthCheck.success, :content_type => 'text/plain' }
33
+ end
34
+ else
35
+ msg = "health_check failed: #{errors}"
36
+ obj = { :healthy => false, :message => msg }
37
+ respond_to do |format|
38
+ format.html { render plain_key => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain' }
39
+ format.json { render :json => obj, :status => HealthCheck.http_status_for_error_object}
40
+ format.xml { render :xml => obj, :status => HealthCheck.http_status_for_error_object }
41
+ format.any { render plain_key => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain' }
42
+ end
43
+ # Log a single line as some uptime checkers only record that it failed, not the text returned
44
+ if logger
45
+ logger.info msg
46
+ end
37
47
  end
38
48
  end
39
49
  end
@@ -41,6 +51,13 @@ module HealthCheck
41
51
 
42
52
  protected
43
53
 
54
+ def authenticate
55
+ return unless HealthCheck.basic_auth_username && HealthCheck.basic_auth_password
56
+ authenticate_or_request_with_http_basic do |username, password|
57
+ username == HealthCheck.basic_auth_username && password == HealthCheck.basic_auth_password
58
+ end
59
+ end
60
+
44
61
  # turn cookies for CSRF off
45
62
  def protect_against_forgery?
46
63
  false
@@ -1,3 +1,3 @@
1
1
  module HealthCheck
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -30,4 +30,4 @@ gem 'therubyrhino', :platform => :jruby # REQUIRED
30
30
  gem 'therubyracer', :platform => :ruby # REQUIRED
31
31
  # mime-types 2.0 requires Ruby version >= 1.9.2
32
32
  # mime-types 3.0 requires Ruby version >= 2.0
33
- gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3.0' : '>= 3.0') # REQUIRED
33
+ gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3' : '>= 3.0') # REQUIRED
@@ -30,4 +30,4 @@ gem 'therubyrhino', :platform => :jruby # REQUIRED
30
30
  gem 'therubyracer', :platform => :ruby # REQUIRED
31
31
  # mime-types 2.0 requires Ruby version >= 1.9.2
32
32
  # mime-types 3.0 requires Ruby version >= 2.0
33
- gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3.0' : '>= 3.0') # REQUIRED
33
+ gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3' : '>= 3.0') # REQUIRED
@@ -27,4 +27,4 @@ end
27
27
 
28
28
  # mime-types 2.0 requires Ruby version >= 1.9.2
29
29
  # mime-types 3.0 requires Ruby version >= 2.0
30
- gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3.0' : '>= 3.0') # REQUIRED
30
+ gem 'mime-types', RUBY_VERSION < '1.9.2' ? '< 2.0' : (defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3' : '>= 3.0') # REQUIRED
@@ -166,6 +166,13 @@ finish()
166
166
  tail -50 $railsapp/log/test.log
167
167
  fi
168
168
 
169
+ if [ -s $railsapp/log/production.log ]
170
+ then
171
+ echo ========================================================
172
+ echo Last 50 lines of production log
173
+ tail -50 $railsapp/log/production.log
174
+ fi
175
+
169
176
  stop_server
170
177
  trap "" 0
171
178
  echo ========================================================
@@ -406,8 +413,17 @@ common_tests()
406
413
  echo
407
414
  fi
408
415
 
409
- date > $custom_file
416
+ test_no=`expr 1 + $test_no`
417
+ if [ -z "$run_test" ] || [ $test_no == "$run_test" ]; then
418
+ echo "${test_no}: TESTING log files to check for deprecation warnings ..."
419
+ if egrep ' is deprecated|DEPRECATION WARNING' $railsapp/log/[tp][er][so][td]*.log
420
+ then
421
+ echo Found deprecation warnings - failed test
422
+ exit 99
423
+ fi
424
+ fi
410
425
 
426
+ date > $custom_file
411
427
  }
412
428
 
413
429
 
@@ -27,7 +27,7 @@ end
27
27
  page_content = response.body
28
28
 
29
29
  puts " response code: #{response.code} #{response.message}"
30
- puts " content_type: #{response.content_type}"
30
+ response.header.each_header {|key,value| puts " #{key}: #{value}" }
31
31
  puts " body: #{page_content}"
32
32
 
33
33
  if ARGV[1] and ARGV[1] != ''
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-11 00:00:00.000000000 Z
12
+ date: 2016-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails