healthcheck_endpoint 1.0.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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +213 -0
  3. data/.circleci/gemspecs/compatible +25 -0
  4. data/.circleci/gemspecs/latest +33 -0
  5. data/.circleci/linter_configs/.bundler-audit.yml +4 -0
  6. data/.circleci/linter_configs/.commitspell.yml +33 -0
  7. data/.circleci/linter_configs/.cspell.yml +32 -0
  8. data/.circleci/linter_configs/.fasterer.yml +4 -0
  9. data/.circleci/linter_configs/.lefthook.yml +44 -0
  10. data/.circleci/linter_configs/.markdownlint.yml +9 -0
  11. data/.circleci/linter_configs/.rubocop.yml +143 -0
  12. data/.circleci/linter_configs/.yamllint.yml +7 -0
  13. data/.circleci/scripts/changeloglint.sh +22 -0
  14. data/.circleci/scripts/commitspell.sh +22 -0
  15. data/.circleci/scripts/release.sh +69 -0
  16. data/.circleci/scripts/set_publisher_credentials.sh +12 -0
  17. data/.codeclimate.yml +17 -0
  18. data/.github/BRANCH_NAMING_CONVENTION.md +36 -0
  19. data/.github/DEVELOPMENT_ENVIRONMENT_GUIDE.md +26 -0
  20. data/.github/FUNDING.yml +3 -0
  21. data/.github/ISSUE_TEMPLATE/bug_report.md +28 -0
  22. data/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
  23. data/.github/ISSUE_TEMPLATE/issue_report.md +32 -0
  24. data/.github/ISSUE_TEMPLATE/question.md +22 -0
  25. data/.github/PULL_REQUEST_TEMPLATE.md +49 -0
  26. data/.gitignore +11 -0
  27. data/.reek.yml +39 -0
  28. data/.rspec +2 -0
  29. data/.ruby-gemset +1 -0
  30. data/.ruby-version +1 -0
  31. data/CHANGELOG.md +52 -0
  32. data/CODE_OF_CONDUCT.md +74 -0
  33. data/CONTRIBUTING.md +48 -0
  34. data/Gemfile +5 -0
  35. data/LICENSE.txt +21 -0
  36. data/README.md +256 -0
  37. data/Rakefile +8 -0
  38. data/bin/console +15 -0
  39. data/bin/setup +8 -0
  40. data/healthcheck_endpoint.gemspec +28 -0
  41. data/lib/healthcheck_endpoint/configuration.rb +139 -0
  42. data/lib/healthcheck_endpoint/core.rb +20 -0
  43. data/lib/healthcheck_endpoint/error/configuration/argument_type.rb +13 -0
  44. data/lib/healthcheck_endpoint/error/configuration/enpoint_pattern.rb +13 -0
  45. data/lib/healthcheck_endpoint/error/configuration/http_status_failure.rb +13 -0
  46. data/lib/healthcheck_endpoint/error/configuration/http_status_success.rb +13 -0
  47. data/lib/healthcheck_endpoint/error/configuration/not_callable_service.rb +13 -0
  48. data/lib/healthcheck_endpoint/error/configuration/not_configured.rb +13 -0
  49. data/lib/healthcheck_endpoint/error/configuration/unknown_service.rb +13 -0
  50. data/lib/healthcheck_endpoint/rack_middleware.rb +25 -0
  51. data/lib/healthcheck_endpoint/resolver.rb +82 -0
  52. data/lib/healthcheck_endpoint/version.rb +5 -0
  53. data/lib/healthcheck_endpoint.rb +25 -0
  54. metadata +171 -0
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HealthcheckEndpoint
4
+ class Resolver
5
+ require 'rack'
6
+ require 'securerandom'
7
+ require 'json'
8
+
9
+ PROBE_ENDPOINTS = %i[endpoint_startup endpoint_liveness endpoint_readiness].freeze
10
+ CONTENT_TYPE = { 'Content-Type' => 'application/json' }.freeze
11
+ ROOT_NAMESPACE = '/'
12
+
13
+ def self.call(rack_env)
14
+ new(rack_env).call
15
+ end
16
+
17
+ def initialize(rack_env)
18
+ @request = ::Rack::Request.new(rack_env)
19
+ end
20
+
21
+ def call
22
+ return unless probe_name
23
+
24
+ [response_status, HealthcheckEndpoint::Resolver::CONTENT_TYPE, [response_jsonapi]]
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :request
30
+
31
+ def configuration
32
+ HealthcheckEndpoint.configuration
33
+ end
34
+
35
+ def root_namespace
36
+ @root_namespace ||= configuration.endpoints_namespace
37
+ end
38
+
39
+ def root_namespace?
40
+ root_namespace.eql?(HealthcheckEndpoint::Resolver::ROOT_NAMESPACE)
41
+ end
42
+
43
+ HealthcheckEndpoint::Resolver::PROBE_ENDPOINTS.each do |method|
44
+ define_method(method) do
45
+ target_endpoint = configuration.public_send(method)
46
+ root_namespace? ? target_endpoint : "#{root_namespace}#{target_endpoint}"
47
+ end
48
+ end
49
+
50
+ def probe_name
51
+ @probe_name ||=
52
+ case request.path
53
+ when endpoint_startup then :startup
54
+ when endpoint_liveness then :liveness
55
+ when endpoint_readiness then :readiness
56
+ end
57
+ end
58
+
59
+ def probe_result
60
+ @probe_result ||=
61
+ configuration.public_send(:"services_#{probe_name}").each_with_object({}) do |service_name, response|
62
+ response[service_name] = configuration.services[service_name].call
63
+ end
64
+ end
65
+
66
+ def response_status
67
+ configuration.public_send(
68
+ probe_result.values.all? ? :"endpoint_#{probe_name}_status_success" : :"endpoint_#{probe_name}_status_failure"
69
+ )
70
+ end
71
+
72
+ def response_jsonapi
73
+ {
74
+ data: {
75
+ id: ::SecureRandom.uuid,
76
+ type: "application-#{probe_name}-healthcheck", # TODO: it would be great to be able to configure this
77
+ attributes: probe_result
78
+ }
79
+ }.to_json
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HealthcheckEndpoint
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'healthcheck_endpoint/core'
4
+
5
+ module HealthcheckEndpoint
6
+ class << self
7
+ def configuration(&block)
8
+ @configuration ||= begin
9
+ return unless block
10
+
11
+ HealthcheckEndpoint::Configuration.new(&block)
12
+ end
13
+ end
14
+
15
+ def configure(&block)
16
+ return configuration {} unless block # rubocop:disable Lint/EmptyBlock
17
+
18
+ configuration(&block)
19
+ end
20
+
21
+ def reset_configuration!
22
+ @configuration = nil
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: healthcheck_endpoint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladislav Trotsenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffaker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.21'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.21'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json_matchers
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.11.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.2'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 13.2.1
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '13.2'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 13.2.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.13'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.13'
89
+ description: Simple configurable application healthcheck rack middleware.
90
+ email:
91
+ - admin@bestweb.com.ua
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".circleci/config.yml"
97
+ - ".circleci/gemspecs/compatible"
98
+ - ".circleci/gemspecs/latest"
99
+ - ".circleci/linter_configs/.bundler-audit.yml"
100
+ - ".circleci/linter_configs/.commitspell.yml"
101
+ - ".circleci/linter_configs/.cspell.yml"
102
+ - ".circleci/linter_configs/.fasterer.yml"
103
+ - ".circleci/linter_configs/.lefthook.yml"
104
+ - ".circleci/linter_configs/.markdownlint.yml"
105
+ - ".circleci/linter_configs/.rubocop.yml"
106
+ - ".circleci/linter_configs/.yamllint.yml"
107
+ - ".circleci/scripts/changeloglint.sh"
108
+ - ".circleci/scripts/commitspell.sh"
109
+ - ".circleci/scripts/release.sh"
110
+ - ".circleci/scripts/set_publisher_credentials.sh"
111
+ - ".codeclimate.yml"
112
+ - ".github/BRANCH_NAMING_CONVENTION.md"
113
+ - ".github/DEVELOPMENT_ENVIRONMENT_GUIDE.md"
114
+ - ".github/FUNDING.yml"
115
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
116
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
117
+ - ".github/ISSUE_TEMPLATE/issue_report.md"
118
+ - ".github/ISSUE_TEMPLATE/question.md"
119
+ - ".github/PULL_REQUEST_TEMPLATE.md"
120
+ - ".gitignore"
121
+ - ".reek.yml"
122
+ - ".rspec"
123
+ - ".ruby-gemset"
124
+ - ".ruby-version"
125
+ - CHANGELOG.md
126
+ - CODE_OF_CONDUCT.md
127
+ - CONTRIBUTING.md
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - bin/console
133
+ - bin/setup
134
+ - healthcheck_endpoint.gemspec
135
+ - lib/healthcheck_endpoint.rb
136
+ - lib/healthcheck_endpoint/configuration.rb
137
+ - lib/healthcheck_endpoint/core.rb
138
+ - lib/healthcheck_endpoint/error/configuration/argument_type.rb
139
+ - lib/healthcheck_endpoint/error/configuration/enpoint_pattern.rb
140
+ - lib/healthcheck_endpoint/error/configuration/http_status_failure.rb
141
+ - lib/healthcheck_endpoint/error/configuration/http_status_success.rb
142
+ - lib/healthcheck_endpoint/error/configuration/not_callable_service.rb
143
+ - lib/healthcheck_endpoint/error/configuration/not_configured.rb
144
+ - lib/healthcheck_endpoint/error/configuration/unknown_service.rb
145
+ - lib/healthcheck_endpoint/rack_middleware.rb
146
+ - lib/healthcheck_endpoint/resolver.rb
147
+ - lib/healthcheck_endpoint/version.rb
148
+ homepage: https://github.com/obstools/healthcheck-endpoint
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 2.5.0
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.2.15
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Simple configurable application healthcheck rack middleware
171
+ test_files: []