kubernetes-health 3.0.5 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -19
- data/kubernetes-health.gemspec +4 -4
- data/lib/kubernetes/health/config.rb +21 -0
- data/lib/kubernetes/health/rack_on_migrate.rb +1 -1
- data/lib/kubernetes/health/version.rb +1 -1
- data/lib/puma/kubernetes/app.rb +24 -19
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59bbdf0e963539df25aa7a994a4fcc54a653506d76df2fa5aa6bbae70994ee98
|
4
|
+
data.tar.gz: b783c8b8df00a8304b5f853b0c13ce9fe09bf8972b55c906d15f42a23c23c5b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 103a26a9a2224f13e246fe1dcc2544990f39a1944f2c989626e0cf44a903a84b2a2fc88b293e1a6ce4269498ccf9abd988a55c4a2ebe7282cbd209371bebd5a2
|
7
|
+
data.tar.gz: 3cd7707bd895b10acb41c68f9d574320599fe5ac1e01fb29f30e9afe2c2a26b382443e2f1db9f0ef4b9dabe54a8641f32920b38075a8151e0405a67ed815e310
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Kubernetes::Health
|
2
2
|
|
3
|
-
This gem allows kubernetes monitoring your app while it is running migrates and after it
|
3
|
+
This gem allows kubernetes monitoring your app while it is running migrates and after it starts.
|
4
4
|
|
5
5
|
# Features
|
6
6
|
- add routes `/_readiness`, `/_liveness` on rails stack.
|
7
7
|
- add routes `/_readiness`, `/_liveness` and `/_metrics` as a puma plugin.
|
8
|
-
- metrics are prometheus compatible (code copied from `puma-metrics` gem).
|
8
|
+
- metrics are prometheus compatible (code copied from `puma-metrics` gem) or json.
|
9
9
|
- allow custom checks for `/_readiness` and `/_liveness`.
|
10
10
|
- add routes `/_readiness` and `/_liveness` while `rake db:migrate` runs. (optional)
|
11
11
|
- add support to avoid parallel running of `rake db:migrate` while keep kubernetes waiting. (optional)
|
@@ -15,7 +15,7 @@ This gem allows kubernetes monitoring your app while it is running migrates and
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem 'kubernetes-health', '~> 3.
|
18
|
+
gem 'kubernetes-health', '~> 3.3'
|
19
19
|
```
|
20
20
|
|
21
21
|
## Enabling puma plugin
|
@@ -48,18 +48,6 @@ In Kubernetes you need to configure your deployment `readinessProbe` and `livene
|
|
48
48
|
```
|
49
49
|
|
50
50
|
Setting `failureThreshold` is import to avoid problems when app finish migrates and is starting the web process.
|
51
|
-
|
52
|
-
## Enabling prometheus metrics
|
53
|
-
|
54
|
-
```
|
55
|
-
template:
|
56
|
-
metadata:
|
57
|
-
annotations:
|
58
|
-
prometheus.io/path: '/_metrics'
|
59
|
-
prometheus.io/port: '9393'
|
60
|
-
prometheus.io/scrape: 'true'
|
61
|
-
```
|
62
|
-
|
63
51
|
## Enabling monitoring while `rake db:migrate` runs
|
64
52
|
|
65
53
|
Your Dockerfile's entry script needs to run migrates before start your web app.
|
@@ -106,18 +94,19 @@ Kubernetes::Health::Config.unlock = lambda {
|
|
106
94
|
|
107
95
|
It only works for routes in rails stack, they are not executed while `rake db:migrate` runs.
|
108
96
|
|
109
|
-
I prefer do nothing else on `liveness` to avoid unnecessary `CrashLoopBackOff` status. `params` is optional.
|
97
|
+
I prefer do nothing else on `liveness` to avoid unnecessary `CrashLoopBackOff` status. `params` is optional (request params).
|
110
98
|
|
111
99
|
```
|
112
|
-
Kubernetes::Health::Config.live_if = lambda {
|
100
|
+
Kubernetes::Health::Config.live_if = lambda { |params|
|
113
101
|
true
|
114
102
|
}
|
115
103
|
|
116
104
|
```
|
117
|
-
Ex. Check if PostgreSQL is reachable on `readiness
|
105
|
+
Ex. Check if PostgreSQL is reachable on `readiness` indicating that credentials are setup right and keeps cache to avoid doing it a lot. `params` is optional (request params).
|
118
106
|
```
|
119
107
|
Kubernetes::Health::Config.ready_if = lambda { |params|
|
120
|
-
|
108
|
+
return $kubernetes_health_test_db_connection if $kubernetes_health_test_db_connection
|
109
|
+
$kubernetes_health_test_db_connection = ActiveRecord::Base.connection.execute("SELECT 1").cmd_tuples == 1
|
121
110
|
}
|
122
111
|
```
|
123
112
|
|
@@ -127,3 +116,19 @@ Kubernetes::Health::Config.route_liveness = '/liveness'
|
|
127
116
|
Kubernetes::Health::Config.route_readiness = '/readiness'
|
128
117
|
Kubernetes::Health::Config.route_metrics = '/metrics'
|
129
118
|
```
|
119
|
+
|
120
|
+
## Response format
|
121
|
+
If you are using `https://github.com/zalando-incubator/kube-metrics-adapter` you will want to use `json` format.
|
122
|
+
|
123
|
+
Default is `prometheus`.
|
124
|
+
```
|
125
|
+
Kubernetes::Health::Config.response_format = 'json'
|
126
|
+
```
|
127
|
+
|
128
|
+
## Customizing requests logs
|
129
|
+
|
130
|
+
```
|
131
|
+
Kubernetes::Health::Config.request_log_callback = lambda { |req, http_code|
|
132
|
+
Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
|
133
|
+
}
|
134
|
+
```
|
data/kubernetes-health.gemspec
CHANGED
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "bundler"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
32
|
spec.add_dependency "rack"
|
33
33
|
spec.add_dependency "rails"
|
34
34
|
spec.add_runtime_dependency 'prometheus-client', '~> 0.9.0'
|
35
|
-
spec.add_runtime_dependency 'puma'
|
35
|
+
spec.add_runtime_dependency 'puma'
|
36
36
|
end
|
@@ -8,6 +8,12 @@ module Kubernetes
|
|
8
8
|
@@route_liveness = '/_liveness'
|
9
9
|
@@route_readiness = '/_readiness'
|
10
10
|
@@route_metrics = '/_metrics'
|
11
|
+
@@response_format = 'prometheus'
|
12
|
+
|
13
|
+
@@request_log_callback = lambda { |req, http_code, content|
|
14
|
+
Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}\n#{content}" rescue nil
|
15
|
+
}
|
16
|
+
|
11
17
|
@@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
|
12
18
|
@@unlock = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_unlock(123456789123456789);' }
|
13
19
|
|
@@ -19,6 +25,14 @@ module Kubernetes
|
|
19
25
|
@@lock_or_wait = value
|
20
26
|
end
|
21
27
|
|
28
|
+
def self.request_log_callback
|
29
|
+
@@request_log_callback
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.request_log_callback=(value)
|
33
|
+
@@request_log_callback = value
|
34
|
+
end
|
35
|
+
|
22
36
|
def self.unlock
|
23
37
|
@@unlock
|
24
38
|
end
|
@@ -83,6 +97,13 @@ module Kubernetes
|
|
83
97
|
@@ready_if = value
|
84
98
|
end
|
85
99
|
|
100
|
+
def self.response_format
|
101
|
+
@@response_format
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.response_format=(value)
|
105
|
+
@@response_format = value
|
106
|
+
end
|
86
107
|
end
|
87
108
|
end
|
88
109
|
end
|
@@ -11,7 +11,7 @@ module Kubernetes
|
|
11
11
|
else
|
12
12
|
http_code = 404
|
13
13
|
end
|
14
|
-
|
14
|
+
::Kubernetes::Health::Config.request_log_callback.call(req, http_code)
|
15
15
|
[http_code, {}, []]
|
16
16
|
end
|
17
17
|
end
|
data/lib/puma/kubernetes/app.rb
CHANGED
@@ -13,26 +13,31 @@ module Puma
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(_env)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
begin
|
17
|
+
req = ::Rack::Request.new(_env)
|
18
|
+
type = {}
|
19
|
+
content = []
|
20
|
+
type = ::Kubernetes::Health::Config.response_format == 'json' ? { 'Content-Type' => 'application/json' } : { 'Content-Type' => 'text/plain' }
|
21
|
+
case req.path_info
|
22
|
+
when ::Kubernetes::Health::Config.route_liveness
|
23
|
+
i_am_live = ::Kubernetes::Health::Config.live_if.arity == 0 ? ::Kubernetes::Health::Config.live_if.call : ::Kubernetes::Health::Config.live_if.call(req.params)
|
24
|
+
http_code = i_am_live ? 200 : 503
|
25
|
+
when ::Kubernetes::Health::Config.route_readiness
|
26
|
+
i_am_ready = ::Kubernetes::Health::Config.ready_if.arity == 0 ? ::Kubernetes::Health::Config.ready_if.call : ::Kubernetes::Health::Config.ready_if.call(req.params)
|
27
|
+
http_code = i_am_ready ? 200 : 503
|
28
|
+
when ::Kubernetes::Health::Config.route_metrics
|
29
|
+
http_code = 200
|
30
|
+
@parser.parse JSON.parse(@launcher.stats)
|
31
|
+
content = ::Kubernetes::Health::Config.response_format == 'json' ? @launcher.stats : Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)
|
32
|
+
else
|
33
|
+
http_code = 404
|
34
|
+
end
|
35
|
+
rescue
|
36
|
+
http_code = 500
|
37
|
+
content = []
|
33
38
|
end
|
34
|
-
|
35
|
-
[http_code, type, content]
|
39
|
+
::Kubernetes::Health::Config.request_log_callback.call(req, http_code, content)
|
40
|
+
[http_code, type, [content]]
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes-health
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wagner Caixeta
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: puma
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :runtime
|
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: '
|
110
|
+
version: '0'
|
111
111
|
description: "\n This gem allows kubernetes monitoring your app while it is running
|
112
112
|
migrates and after it started.\n Features:\n * add routes /_readiness and
|
113
113
|
/_liveness on rails stack by default;\n * allow custom checks for /_readiness
|
@@ -145,7 +145,7 @@ files:
|
|
145
145
|
homepage: https://github.com/platbr/kubernetes-health
|
146
146
|
licenses: []
|
147
147
|
metadata: {}
|
148
|
-
post_install_message:
|
148
|
+
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|
151
151
|
- lib
|
@@ -160,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
164
|
-
signing_key:
|
163
|
+
rubygems_version: 3.2.17
|
164
|
+
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: This gem allows kubernetes monitoring your app while it is running migrates
|
167
167
|
and after it started.
|