kubernetes-health 3.2.0 → 3.4.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 +17 -20
- data/kubernetes-health.gemspec +3 -3
- data/lib/kubernetes/health/config.rb +12 -4
- data/lib/kubernetes/health/version.rb +1 -1
- data/lib/puma/kubernetes/app.rb +23 -7
- data/lib/puma/kubernetes/parser.rb +1 -0
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e002184325d2c508f38c8fc4c73532d748046664fcc65764e345d0119734d066
|
4
|
+
data.tar.gz: 85419dad18b1fe9df0d0fcdcbbf1686f0e7233497bc1685f2a1182baba7cceb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b3cc913270ba83fda812e464bbcd3469e6949778059e707b6de62f4b2391747ade9f957c12062c0f98c42fbd0beb421403caed4c0bd6c15acc553edb917f560
|
7
|
+
data.tar.gz: b147c8e17cee0c3648116ac10eb1e9e6cfa89d1f78a5d03815629d2aa0d27b8b066fb4abcf70b6ea3b0595de36828911b8959c1cf2a0bd9f3077c0f9d1d8a6af
|
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.4'
|
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
|
|
@@ -128,10 +117,18 @@ Kubernetes::Health::Config.route_readiness = '/readiness'
|
|
128
117
|
Kubernetes::Health::Config.route_metrics = '/metrics'
|
129
118
|
```
|
130
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
|
+
|
131
128
|
## Customizing requests logs
|
132
129
|
|
133
130
|
```
|
134
131
|
Kubernetes::Health::Config.request_log_callback = lambda { |req, http_code|
|
135
132
|
Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
|
136
133
|
}
|
137
|
-
```
|
134
|
+
```
|
data/kubernetes-health.gemspec
CHANGED
@@ -26,9 +26,9 @@ 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'
|
@@ -8,9 +8,10 @@ module Kubernetes
|
|
8
8
|
@@route_liveness = '/_liveness'
|
9
9
|
@@route_readiness = '/_readiness'
|
10
10
|
@@route_metrics = '/_metrics'
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
14
15
|
}
|
15
16
|
|
16
17
|
@@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
|
@@ -23,7 +24,7 @@ module Kubernetes
|
|
23
24
|
def self.lock_or_wait=(value)
|
24
25
|
@@lock_or_wait = value
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
def self.request_log_callback
|
28
29
|
@@request_log_callback
|
29
30
|
end
|
@@ -96,6 +97,13 @@ module Kubernetes
|
|
96
97
|
@@ready_if = value
|
97
98
|
end
|
98
99
|
|
100
|
+
def self.response_format
|
101
|
+
@@response_format
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.response_format=(value)
|
105
|
+
@@response_format = value
|
106
|
+
end
|
99
107
|
end
|
100
108
|
end
|
101
109
|
end
|
data/lib/puma/kubernetes/app.rb
CHANGED
@@ -16,8 +16,8 @@ module Puma
|
|
16
16
|
begin
|
17
17
|
req = ::Rack::Request.new(_env)
|
18
18
|
type = {}
|
19
|
-
content =
|
20
|
-
type = { 'Content-Type' => 'text/plain' }
|
19
|
+
content = ''
|
20
|
+
type = ::Kubernetes::Health::Config.response_format == 'json' ? { 'Content-Type' => 'application/json' } : { 'Content-Type' => 'text/plain' }
|
21
21
|
case req.path_info
|
22
22
|
when ::Kubernetes::Health::Config.route_liveness
|
23
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)
|
@@ -27,17 +27,33 @@ module Puma
|
|
27
27
|
http_code = i_am_ready ? 200 : 503
|
28
28
|
when ::Kubernetes::Health::Config.route_metrics
|
29
29
|
http_code = 200
|
30
|
-
|
31
|
-
|
30
|
+
if ::Kubernetes::Health::Config.response_format == 'json'
|
31
|
+
content = include_puma_key_prefix(include_usage(JSON.parse(@launcher.stats))).to_json
|
32
|
+
else
|
33
|
+
@parser.parse include_usage(JSON.parse(@launcher.stats))
|
34
|
+
content = Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)
|
35
|
+
end
|
32
36
|
else
|
33
37
|
http_code = 404
|
34
38
|
end
|
35
39
|
rescue
|
36
40
|
http_code = 500
|
37
|
-
content =
|
41
|
+
content = ''
|
38
42
|
end
|
39
|
-
::Kubernetes::Health::Config.request_log_callback.call(req, http_code)
|
40
|
-
[http_code, type, content]
|
43
|
+
::Kubernetes::Health::Config.request_log_callback.call(req, http_code, content)
|
44
|
+
[http_code, type, [content]]
|
45
|
+
end
|
46
|
+
|
47
|
+
def include_usage(stats)
|
48
|
+
stats['usage'] = (1 - stats['pool_capacity'].to_f / stats['max_threads']).round(2)
|
49
|
+
stats
|
50
|
+
end
|
51
|
+
def include_puma_key_prefix(stats)
|
52
|
+
result = {}
|
53
|
+
stats.each do |k,v|
|
54
|
+
result["puma_#{k}"] = v
|
55
|
+
end
|
56
|
+
result
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|
@@ -29,6 +29,7 @@ module Puma
|
|
29
29
|
registry.gauge(:puma_pool_capacity, 'Number of allocatable worker threads', index: 0)
|
30
30
|
registry.gauge(:puma_max_threads, 'Maximum number of worker threads', index: 0)
|
31
31
|
registry.gauge(:puma_workers, 'Number of configured workers').set({}, 1)
|
32
|
+
registry.gauge(:puma_usage, 'Result of (1 - puma_pool_capacity/puma_max_threads)', index: 0)
|
32
33
|
end
|
33
34
|
|
34
35
|
def registry
|
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.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wagner Caixeta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
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
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
163
|
+
rubygems_version: 3.2.17
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: This gem allows kubernetes monitoring your app while it is running migrates
|