rails-healthcheck 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1fa5ee15c317c0b060da4844acc3b5bcaedef1e219cf28f07a73afc7d2b83fd8
4
+ data.tar.gz: 1922c4e199e6982c08bb4721332c468849faf6ef9ca3d19417845f4211875737
5
+ SHA512:
6
+ metadata.gz: b4e87b97f9a2c4a8f3693c6478ffe4c2fec72b39a6d3662f17fc2defc58c61dad85241feb477826b66d4476586a848f4e0a411a43d191408a07b5cabf1255ecb
7
+ data.tar.gz: 3ad5804391ca1eee82970829e44ad4a334cbdca2dd6bf5ec557994af2163885d8c9daacc9582b5cc4ad9ac9fcffd64f3e9b6f774a56195c0a58e5b2e46f5d03b
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # [Rails::Healthcheck][gem_page]
2
+
3
+ [![Build Status][travis_status_image]][travis_page]
4
+ [![Maintainability][code_climate_maintainability_image]][code_climate_maintainability_page]
5
+ [![Test Coverage][code_climate_test_coverage_image]][code_climate_test_coverage_page]
6
+
7
+ A simple way to configure a healthcheck route for a Rails application
8
+
9
+ ## Instalation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rails-healthcheck'
15
+ ```
16
+
17
+ and run:
18
+
19
+ ```
20
+ rails healthcheck:install
21
+ ```
22
+
23
+ ## Settings
24
+ Set the settings in the file _config/initializers/healthcheck.rb_:
25
+
26
+ ```ruby
27
+ # frozen_string_literal: true
28
+
29
+ HealthCheck.configure do |config|
30
+ config.success = 200
31
+ config.error = 503
32
+ config.verbose = false
33
+ config.route = '/healthcheck'
34
+ config.method = :get
35
+
36
+ # -- Checks --
37
+ # Check if the db is available
38
+ # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
39
+ # Check if the db is available is without pending migrations
40
+ # config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
41
+ # Check if the cache is available
42
+ # config.add_check :cache, -> { Rails.cache.read('some_key') }
43
+ # Check if the application required envs are defined
44
+ # config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
45
+ end
46
+ ```
47
+
48
+ ### Verbose errors
49
+ When happen an error and verbose is enabled (`config.verbose = true`), the response will be like this:
50
+
51
+ ```json
52
+ {
53
+ "code": 503,
54
+ "errors": [
55
+ {
56
+ "name": "migrations",
57
+ "exception": "ActiveRecord::PendingMigrationError",
58
+ "message": "Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=production"
59
+ },
60
+ {
61
+ "name": "environments",
62
+ "exception": "Dotenv::MissingKeys",
63
+ "message": "Missing required configuration key: [\"RAILS_ENV\"]"
64
+ }
65
+ ]
66
+ }
67
+ ```
68
+
69
+ ### Requests
70
+
71
+ - Success
72
+ ```
73
+ curl -i localhost:3000/healthcheck
74
+
75
+ HTTP/1.1 200 OK
76
+ X-Frame-Options: SAMEORIGIN
77
+ X-XSS-Protection: 1; mode=block
78
+ X-Content-Type-Options: nosniff
79
+ X-Download-Options: noopen
80
+ X-Permitted-Cross-Domain-Policies: none
81
+ Referrer-Policy: strict-origin-when-cross-origin
82
+ Content-Type: text/html
83
+ Cache-Control: no-cache
84
+ X-Request-Id: cbc9fdd0-8090-4927-b061-1e82bcf2e039
85
+ X-Runtime: 0.003599
86
+ Transfer-Encoding: chunked
87
+ ```
88
+
89
+ - Error
90
+ ```
91
+ curl -i localhost:3000/healthcheck
92
+
93
+ HTTP/1.1 503 Service Unavailable
94
+ X-Frame-Options: SAMEORIGIN
95
+ X-XSS-Protection: 1; mode=block
96
+ X-Content-Type-Options: nosniff
97
+ X-Download-Options: noopen
98
+ X-Permitted-Cross-Domain-Policies: none
99
+ Referrer-Policy: strict-origin-when-cross-origin
100
+ Content-Type: text/html
101
+ Cache-Control: no-cache
102
+ X-Request-Id: e07eb20f-7d32-4f1a-86ad-32403de2b19a
103
+ X-Runtime: 0.033772
104
+ Transfer-Encoding: chunked
105
+ ```
106
+
107
+ - Error (Verbose)
108
+ ```
109
+ curl -i localhost:3000/healthcheck
110
+
111
+ HTTP/1.1 503 Service Unavailable
112
+ X-Frame-Options: SAMEORIGIN
113
+ X-XSS-Protection: 1; mode=block
114
+ X-Content-Type-Options: nosniff
115
+ X-Download-Options: noopen
116
+ X-Permitted-Cross-Domain-Policies: none
117
+ Referrer-Policy: strict-origin-when-cross-origin
118
+ Content-Type: application/json; charset=utf-8
119
+ Cache-Control: no-cache
120
+ X-Request-Id: 8fa5e69a-bfe3-4bbc-875b-ce86f4269467
121
+ X-Runtime: 0.019992
122
+ Transfer-Encoding: chunked
123
+
124
+ {"code":503,"errors":[{"name":"zero_division","exception":"ZeroDivisionError","message":"divided by 0"}]}
125
+ ```
126
+
127
+ ## Contributing
128
+
129
+ 1. Fork it
130
+ 2. Create your feature branch (git checkout -b my-new-feature)
131
+ 3. Commit your changes (git commit -am 'Add some feature')
132
+ 4. Push to the branch (git push origin my-new-feature)
133
+ 5. Create new Pull Request
134
+
135
+ ## License
136
+
137
+ The gem is available as open source under the terms of the [MIT License][mit_license_page].
138
+
139
+ ## Code of Conduct
140
+
141
+ Everyone interacting in the Rails::Healthcheck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct][code_of_conduct_page].
142
+
143
+ [gem_page]: https://github.com/linqueta/rails-healthcheck
144
+ [code_of_conduct_page]: https://github.com/linqueta/rails-healthcheck/blob/master/CODE_OF_CONDUCT.md
145
+ [mit_license_page]: https://opensource.org/licenses/MIT
146
+ [contributor_convenant_page]: http://contributor-covenant.org
147
+ [travis_status_image]: https://travis-ci.org/linqueta/rails-healthcheck.svg?branch=master
148
+ [travis_page]: https://travis-ci.org/linqueta/rails-healthcheck
149
+ [code_climate_maintainability_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/maintainability
150
+ [code_climate_maintainability_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/maintainability
151
+ [code_climate_test_coverage_image]: https://api.codeclimate.com/v1/badges/670d851a6c06f77fa36e/test_coverage
152
+ [code_climate_test_coverage_page]: https://codeclimate.com/github/linqueta/rails-healthcheck/test_coverage
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_controller/railtie'
4
+ module Healthcheck
5
+ class HealthchecksController < ActionController::Base
6
+ def check
7
+ execute
8
+ errored? ? error : success
9
+ end
10
+
11
+ private
12
+
13
+ def execute
14
+ checker.check
15
+ end
16
+
17
+ def errored?
18
+ checker.errored?
19
+ end
20
+
21
+ def checker
22
+ @checker ||= Healthcheck::Checker.new
23
+ end
24
+
25
+ def success
26
+ head Healthcheck.success
27
+ end
28
+
29
+ def error
30
+ return head(Healthcheck.error) unless Healthcheck.verbose
31
+
32
+ render json: { code: Healthcheck.error, errors: checker.errors.as_json }, status: Healthcheck.error
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-healthcheck
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - linqueta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.74.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.74.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.4.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.17.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.17.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-console
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.0
125
+ description: A simple way to configure a healthcheck route for a Rails application
126
+ email:
127
+ - lincolnrodrs@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - README.md
133
+ - app/controllers/healthcheck/healthchecks_controller.rb
134
+ homepage: https://github.com/linqueta/rails-healthcheck
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 2.5.1
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.7.6
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A simple way to configure a healthcheck route for a Rails application
158
+ test_files: []