rails-healthcheck 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90d8e05e3632eea15ad496a96cad8ab62120f22bfa1b2b9e5d0d58965fc6015b
4
- data.tar.gz: baa0baa4729818b03ec644ffbfcf1f5b41741458422c6a1c4baff96cef6dca95
3
+ metadata.gz: eb62ca798614c3adf6326d3b15cac4dd404f177d1dc5ad5f491938f2e3534530
4
+ data.tar.gz: 531f13e1c8cf658a26e85569e3d72b47b38498a17843cc0c28722c757369d929
5
5
  SHA512:
6
- metadata.gz: bc248fa637568e69c70389b6d74ae9d1a88608781f9b5b31488355a836cf9549aaec03e5d258cde1c61a44c0d1bb2ca61df019540b60b35276c5d2979059ff78
7
- data.tar.gz: 6e23c81ce1702ddbd4ba205de93194c19384e06c7ca92ff69b1fbc964b2abf2b8af007e96b2f53d757dc77d17dad28030bff31532edc04ad2a179de4b958c258
6
+ metadata.gz: 0c347e99945ed94ce23ee3c4e4c9250b12da9381aa371392ff08e8bd5d247e72179f38f1c57edb1a51008cb113e22e6029795b8c5e22d31a620f30c133085837
7
+ data.tar.gz: a40b7c53c042fa550507fd3d9102eaf4ffb0ec84503f538976a7463c435832d18a0be1816683b9a2157c657c100a09847572ec9864762d454074e987599bc9d4
data/README.md CHANGED
@@ -1,13 +1,27 @@
1
1
  # [Rails::Healthcheck][gem_page]
2
2
 
3
+ [![Gem Version][gem_version_image]][gem_version_page]
3
4
  [![Build Status][travis_status_image]][travis_page]
4
5
  [![Maintainability][code_climate_maintainability_image]][code_climate_maintainability_page]
5
- [![Test Coverage][code_climate_test_coverage_image]][code_climate_test_coverage_page]
6
- [![Gem Version][gem_version_image]][gem_version_page]
7
6
 
8
7
  A simple way to configure a healthcheck route in Rails applications
9
8
 
10
- ## Installation
9
+ ## Table of Contents
10
+ - [Getting started](#getting-started)
11
+ - [Installation](#installation)
12
+ - [Settings](#settings)
13
+ - [Custom Response](#custom-response)
14
+ - [Verbose Errors](#verbose-errors)
15
+ - [Ignoring logs](#ignoring-logs)
16
+ - [Lograge](#lograge)
17
+ - [Datadog](#lograge)
18
+ - [Requests Examples](#requests-examples)
19
+ - [Contributing](#contributing)
20
+ - [License](#license)
21
+
22
+ ## Getting started
23
+
24
+ ### Installation
11
25
 
12
26
  Add this line to your application's Gemfile:
13
27
 
@@ -15,14 +29,15 @@ Add this line to your application's Gemfile:
15
29
  gem 'rails-healthcheck'
16
30
  ```
17
31
 
18
- and run:
32
+ and run the command bellow to create the initializer:
19
33
 
20
34
  ```
21
35
  rails generate healthcheck:install
22
36
  ```
23
37
 
24
- ## Settings
25
- Set the settings in the file _config/initializers/healthcheck.rb_:
38
+ ### Settings
39
+
40
+ You can set the settings in the initializer file (_config/initializers/healthcheck.rb_):
26
41
 
27
42
  ```ruby
28
43
  # frozen_string_literal: true
@@ -34,19 +49,42 @@ Healthcheck.configure do |config|
34
49
  config.route = '/healthcheck'
35
50
  config.method = :get
36
51
 
52
+ # -- Custom Response --
53
+ # config.custom = lambda { |controller, checker|
54
+ # controller.render json: my_custom_response unless checker.errored?
55
+ # ...
56
+ # }
57
+
37
58
  # -- Checks --
38
- # Check if the db is available
39
- # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
40
- # Check if the db is available and without pending migrations
41
- # config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
42
- # Check if the cache is available
43
- # config.add_check :cache, -> { Rails.cache.read('some_key') }
44
- # Check if the application required envs are defined
59
+ # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
60
+ # config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
61
+ # config.add_check :cache, -> { Rails.cache.read('some_key') }
45
62
  # config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
46
63
  end
47
64
  ```
48
65
 
49
- ### Verbose errors
66
+ ### Custom Response
67
+
68
+ You can override the configs `success`, `error` and `verbose` and write your custom behaviour for the healthcheck api using the field `custom` in the initializer:
69
+
70
+ ```ruby
71
+ Healthcheck.configure do |config|
72
+ # ...
73
+
74
+ # -- Custom Response --
75
+ config.custom = lambda { |controller, checker|
76
+ controller.render json: { field_name: 'my custom field value' } unless checker.errored?
77
+ ...
78
+ }
79
+
80
+ # ...
81
+ end
82
+ ```
83
+
84
+ Pass a `lambda` or `proc` receiving the params `controller` and `checker` to use it correctly. To use checker, you can see the avialable methods [here][checker_url] and [how][healthcheck_controller_url] it is implemented on HealthcheckController.
85
+
86
+ ### Verbose Errors
87
+
50
88
  When happen an error and verbose is enabled (`config.verbose = true`), the response will be like this:
51
89
 
52
90
  ```json
@@ -67,79 +105,58 @@ When happen an error and verbose is enabled (`config.verbose = true`), the respo
67
105
  }
68
106
  ```
69
107
 
70
- ### Requests
108
+ ## Ignoring logs
71
109
 
72
- - Success
110
+ If you want to ignore Healthcheck request logs, you can use these options:
111
+
112
+ ### [Lograge](https://github.com/roidrage/lograge)
113
+
114
+ ```ruby
115
+ # config/environments/production.rb
116
+
117
+ Rails.application.configure do
118
+ config.lograge.enabled = true
119
+ config.lograge.ignore_actions = [Healthcheck::CONTROLLER_ACTION]
120
+ end
73
121
  ```
122
+
123
+ ### [Datadog](https://github.com/roidrage/lograge)
124
+
125
+ ```ruby
126
+ # config/environments/production.rb
127
+
128
+ filter = Datadog::Pipeline::SpanFilter.new do |span|
129
+ span.name == 'rack.request' && span.get_tag('http.url') == Healthcheck.configuration.route
130
+ end
131
+
132
+ Datadog::Pipeline.before_flush(filter)
133
+ ```
134
+
135
+ ### Requests Examples
136
+
137
+ - Success
138
+
139
+ ```shell
74
140
  curl -i localhost:3000/healthcheck
75
141
 
76
142
  HTTP/1.1 200 OK
77
- X-Frame-Options: SAMEORIGIN
78
- X-XSS-Protection: 1; mode=block
79
- X-Content-Type-Options: nosniff
80
- X-Download-Options: noopen
81
- X-Permitted-Cross-Domain-Policies: none
82
- Referrer-Policy: strict-origin-when-cross-origin
83
- Content-Type: text/html
84
- Cache-Control: no-cache
85
- X-Request-Id: cbc9fdd0-8090-4927-b061-1e82bcf2e039
86
- X-Runtime: 0.003599
87
- Transfer-Encoding: chunked
88
143
  ```
89
144
 
90
145
  - Error
91
- ```
146
+ ```shell
92
147
  curl -i localhost:3000/healthcheck
93
148
 
94
149
  HTTP/1.1 503 Service Unavailable
95
- X-Frame-Options: SAMEORIGIN
96
- X-XSS-Protection: 1; mode=block
97
- X-Content-Type-Options: nosniff
98
- X-Download-Options: noopen
99
- X-Permitted-Cross-Domain-Policies: none
100
- Referrer-Policy: strict-origin-when-cross-origin
101
- Content-Type: text/html
102
- Cache-Control: no-cache
103
- X-Request-Id: e07eb20f-7d32-4f1a-86ad-32403de2b19a
104
- X-Runtime: 0.033772
105
- Transfer-Encoding: chunked
106
150
  ```
107
151
 
108
152
  - Error (Verbose)
109
- ```
153
+ ```shell
110
154
  curl -i localhost:3000/healthcheck
111
155
 
112
156
  HTTP/1.1 503 Service Unavailable
113
- X-Frame-Options: SAMEORIGIN
114
- X-XSS-Protection: 1; mode=block
115
- X-Content-Type-Options: nosniff
116
- X-Download-Options: noopen
117
- X-Permitted-Cross-Domain-Policies: none
118
- Referrer-Policy: strict-origin-when-cross-origin
119
- Content-Type: application/json; charset=utf-8
120
- Cache-Control: no-cache
121
- X-Request-Id: 8fa5e69a-bfe3-4bbc-875b-ce86f4269467
122
- X-Runtime: 0.019992
123
- Transfer-Encoding: chunked
124
-
125
157
  {"code":503,"errors":[{"name":"zero_division","exception":"ZeroDivisionError","message":"divided by 0"}]}
126
158
  ```
127
159
 
128
- ## Ignoring logs
129
-
130
- ### Lograge
131
-
132
- If you are using [Lograge](https://github.com/roidrage/lograge) you can ignore Healthcheck logs using this code:
133
-
134
- ```ruby
135
- # config/environments/production.rb
136
-
137
- Rails.application.configure do
138
- config.lograge.enabled = true
139
- config.lograge.ignore_actions = [Healthcheck::CONTROLLER_ACTION]
140
- end
141
- ```
142
-
143
160
  ## Contributing
144
161
 
145
162
  1. Fork it
@@ -164,7 +181,7 @@ Everyone interacting in the Rails::Healthcheck project’s codebases, issue trac
164
181
  [travis_page]: https://travis-ci.org/linqueta/rails-healthcheck
165
182
  [code_climate_maintainability_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/maintainability
166
183
  [code_climate_maintainability_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/maintainability
167
- [code_climate_test_coverage_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/test_coverage
168
- [code_climate_test_coverage_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/test_coverage
169
184
  [gem_version_image]: https://badge.fury.io/rb/rails-healthcheck.svg
170
185
  [gem_version_page]: https://rubygems.org/gems/rails-healthcheck
186
+ [checker_url]: https://github.com/linqueta/rails-healthcheck/blob/master/lib/healthcheck/checker.rb
187
+ [healthcheck_controller_url]: https://github.com/linqueta/rails-healthcheck/blob/master/app/controllers/healthcheck/healthchecks_controller.rb
@@ -5,6 +5,7 @@ module Healthcheck
5
5
  class HealthchecksController < ActionController::Base
6
6
  def check
7
7
  checker = Healthcheck.check
8
+ return Healthcheck.configuration.custom.call(self, checker) if Healthcheck.configuration.custom
8
9
  return head Healthcheck.configuration.success unless checker.errored?
9
10
 
10
11
  verbose? ? verbose_error(checker) : head_error
@@ -13,7 +14,7 @@ module Healthcheck
13
14
  private
14
15
 
15
16
  def head_error
16
- head(Healthcheck.configuration.error)
17
+ head Healthcheck.configuration.error
17
18
  end
18
19
 
19
20
  def verbose_error(checker)
@@ -4,6 +4,7 @@ require 'rails/generators/base'
4
4
 
5
5
  module Healthcheck
6
6
  class InstallGenerator < Rails::Generators::Base
7
+ desc 'It creates an initializer to set the healthcheck settings'
7
8
  def create_initializer_file
8
9
  create_file(
9
10
  'config/initializers/healthcheck.rb',
@@ -17,10 +18,16 @@ module Healthcheck
17
18
  config.route = '/healthcheck'
18
19
  config.method = :get
19
20
 
21
+ # -- Custom Response --
22
+ # config.custom = lambda { |controller, checker|
23
+ # controller.render json: my_custom_response unless checker.errored?
24
+ # ...
25
+ # }
26
+
20
27
  # -- Checks --
21
- # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
22
- # config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
23
- # config.add_check :cache, -> { Rails.cache.read('some_key') }
28
+ # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
29
+ # config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
30
+ # config.add_check :cache, -> { Rails.cache.read('some_key') }
24
31
  # config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
25
32
  end
26
33
  HEALTHCHECK_INITIALIZER_TEXT
@@ -2,12 +2,11 @@
2
2
 
3
3
  module Healthcheck
4
4
  class Configuration
5
- SETTINGS = %i[success error verbose route method checks].freeze
5
+ SETTINGS = %i[success error verbose route method checks custom].freeze
6
6
 
7
7
  attr_accessor(*SETTINGS)
8
8
 
9
9
  def initialize
10
- SETTINGS.each { |key, _| instance_variable_set("@#{key}", nil) }
11
10
  clear!
12
11
  end
13
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Healthcheck
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-healthcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - linqueta
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
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: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
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: '3.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.17.0
103
+ version: 0.17.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.17.0
110
+ version: 0.17.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov-console
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: A simple way to configure a healthcheck route for a Rails application
126
140
  email:
127
141
  - lincolnrodrs@gmail.com
@@ -145,7 +159,7 @@ homepage: https://github.com/linqueta/rails-healthcheck
145
159
  licenses:
146
160
  - MIT
147
161
  metadata: {}
148
- post_install_message:
162
+ post_install_message:
149
163
  rdoc_options: []
150
164
  require_paths:
151
165
  - lib
@@ -160,9 +174,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
174
  - !ruby/object:Gem::Version
161
175
  version: '0'
162
176
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.7.6
165
- signing_key:
177
+ rubygems_version: 3.1.2
178
+ signing_key:
166
179
  specification_version: 4
167
- summary: A simple way to configure a healthcheck route for a Rails application
180
+ summary: Healthcheck route for a Rails application
168
181
  test_files: []