kubernetes-health 3.8.0 → 3.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/config/initializers/enable_rack_on_sidekiq.rb +1 -1
- data/kubernetes-health.gemspec +1 -1
- data/lib/kubernetes/health/config.rb +4 -4
- data/lib/kubernetes/health/rack_on_sidekiq.rb +15 -12
- data/lib/kubernetes/health/sidekiq_options_resolver.rb +13 -0
- data/lib/kubernetes/health/version.rb +1 -1
- data/lib/kubernetes/health.rb +1 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3ad95fa7855c4e929a649861a3b8e76c4c5178d4f0a9d15d4f59dbecd412d05
|
4
|
+
data.tar.gz: 8ddc6657bc1625af9a8397717a5c624363117396aa9f356d686d020753925a29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b50588ad78d95dc0bb29ca932062eaf30ed6fdc5174e6e5a1c158d8c97494315ecde1bc1a67ebf4b53cb769dbabdbf8e8e998a78592a62a41cd108f36ee5f79
|
7
|
+
data.tar.gz: 707b24d2add09186c55db3899765b3ef560c55d8941785ea6b0a727189305dfe178885839f14ce498da1fa070fff67a38c8f42e925c7f927cb2193483c616815
|
data/README.md
CHANGED
@@ -131,6 +131,12 @@ Kubernetes::Health::Config.route_liveness = '/liveness'
|
|
131
131
|
Kubernetes::Health::Config.route_readiness = '/readiness'
|
132
132
|
Kubernetes::Health::Config.route_metrics = '/metrics'
|
133
133
|
```
|
134
|
+
or using env
|
135
|
+
```
|
136
|
+
KUBERNETES_HEALTH_LIVENESS_ROUTE='/liveness'
|
137
|
+
KUBERNETES_HEALTH_READINESS_ROUTE='/readiness'
|
138
|
+
KUBERNETES_HEALTH_RESPONSE_FORMAT='/metrics'
|
139
|
+
```
|
134
140
|
|
135
141
|
## Response format
|
136
142
|
If you are using `https://github.com/zalando-incubator/kube-metrics-adapter` you will want to use `json` format.
|
@@ -139,6 +145,10 @@ Default is `prometheus`.
|
|
139
145
|
```
|
140
146
|
Kubernetes::Health::Config.response_format = 'json'
|
141
147
|
```
|
148
|
+
or using env
|
149
|
+
```
|
150
|
+
KUBERNETES_HEALTH_RESPONSE_FORMAT=json
|
151
|
+
```
|
142
152
|
|
143
153
|
## Customizing requests logs
|
144
154
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'kubernetes/health/rack_on_sidekiq'
|
2
2
|
|
3
|
-
if Kubernetes::Health::Config.enable_rack_on_sidekiq &&
|
3
|
+
if Kubernetes::Health::Config.enable_rack_on_sidekiq && Kubernetes::Health::SidekiqOptionsResolver[:concurrency].positive?
|
4
4
|
Thread.new do
|
5
5
|
Rack::Handler.default.run Kubernetes::Health::RackOnSidekiq.new
|
6
6
|
end
|
data/kubernetes-health.gemspec
CHANGED
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "rspec"
|
32
32
|
spec.add_dependency "rack"
|
33
33
|
spec.add_dependency "rails"
|
34
|
-
spec.add_runtime_dependency 'prometheus-client', '
|
34
|
+
spec.add_runtime_dependency 'prometheus-client', '>= 1.0', '< 5'
|
35
35
|
spec.add_runtime_dependency 'puma', '>= 5.0'
|
36
36
|
end
|
@@ -6,10 +6,10 @@ module Kubernetes
|
|
6
6
|
@@enable_lock_on_migrate = [true, 'true'].include? ENV['KUBERNETES_HEALTH_ENABLE_LOCK_ON_MIGRATE']
|
7
7
|
@@enable_rack_on_migrate = [true, 'true'].include? ENV['KUBERNETES_HEALTH_ENABLE_RACK_ON_MIGRATE']
|
8
8
|
@@enable_rack_on_sidekiq = [true, 'true'].include? ENV['KUBERNETES_HEALTH_ENABLE_RACK_ON_SIDEKIQ']
|
9
|
-
@@route_liveness = '/_liveness'
|
10
|
-
@@route_readiness = '/_readiness'
|
11
|
-
@@route_metrics = '/_metrics'
|
12
|
-
@@response_format = 'prometheus'
|
9
|
+
@@route_liveness = ENV['KUBERNETES_HEALTH_LIVENESS_ROUTE'] || '/_liveness'
|
10
|
+
@@route_readiness = ENV['KUBERNETES_HEALTH_READINESS_ROUTE'] || '/_readiness'
|
11
|
+
@@route_metrics = ENV['KUBERNETES_HEALTH_METRICS_ROUTE'] || '/_metrics'
|
12
|
+
@@response_format = ENV['KUBERNETES_HEALTH_RESPONSE_FORMAT'] || 'prometheus'
|
13
13
|
|
14
14
|
@@request_log_callback = lambda { |req, http_code, content|
|
15
15
|
Rails.logger.debug "Kubernetes Health - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}\n#{content}" rescue nil
|
@@ -5,6 +5,7 @@ require 'prometheus/client/formats/text'
|
|
5
5
|
module Kubernetes
|
6
6
|
module Health
|
7
7
|
class RackOnSidekiq
|
8
|
+
|
8
9
|
def call(env)
|
9
10
|
req = ::Rack::Request.new(env)
|
10
11
|
content = ''
|
@@ -18,10 +19,9 @@ module Kubernetes
|
|
18
19
|
if ::Kubernetes::Health::Config.response_format == 'json'
|
19
20
|
content = sidekiq_metrics.to_json
|
20
21
|
else
|
21
|
-
prometheus_registry
|
22
|
-
prometheus_registry.get(:
|
23
|
-
prometheus_registry.get(:
|
24
|
-
prometheus_registry.get(:sidekiq_usage).set({}, sidekiq_metrics[:sidekiq_usage])
|
22
|
+
prometheus_registry.get(:sidekiq_capacity).set(sidekiq_metrics[:sidekiq_capacity])
|
23
|
+
prometheus_registry.get(:sidekiq_busy).set(sidekiq_metrics[:sidekiq_busy])
|
24
|
+
prometheus_registry.get(:sidekiq_usage).set(sidekiq_metrics[:sidekiq_usage])
|
25
25
|
content = Prometheus::Client::Formats::Text.marshal(prometheus_registry)
|
26
26
|
end
|
27
27
|
else
|
@@ -32,25 +32,28 @@ module Kubernetes
|
|
32
32
|
[http_code, type, [content]]
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
prometheus_registry
|
37
|
-
|
38
|
-
prometheus_registry
|
39
|
-
prometheus_registry.gauge(:
|
40
|
-
prometheus_registry
|
35
|
+
def prometheus_registry
|
36
|
+
return @prometheus_registry unless @prometheus_registry.nil?
|
37
|
+
|
38
|
+
@prometheus_registry = Prometheus::Client.registry
|
39
|
+
@prometheus_registry.gauge(:sidekiq_capacity, docstring: 'Sidekiq Threads Number')
|
40
|
+
@prometheus_registry.gauge(:sidekiq_busy, docstring: 'Sidekiq Busy Threads')
|
41
|
+
@prometheus_registry.gauge(:sidekiq_usage, docstring: 'Result of sidekiq_busy/sidekiq_capacity')
|
42
|
+
@prometheus_registry
|
41
43
|
end
|
42
44
|
|
43
45
|
def generate_sidekiq_metrics
|
44
|
-
sidekiq_info = Sidekiq::ProcessSet.new.to_a.filter { |p| p.identity ==
|
46
|
+
sidekiq_info = Sidekiq::ProcessSet.new.to_a.filter { |p| p.identity == SidekiqOptionsResolver[:identity] }
|
45
47
|
|
46
48
|
stats = {
|
47
|
-
sidekiq_capacity:
|
49
|
+
sidekiq_capacity: SidekiqOptionsResolver[:concurrency],
|
48
50
|
sidekiq_busy: sidekiq_info.size.zero? ? 0 : sidekiq_info[0]['busy']
|
49
51
|
}
|
50
52
|
|
51
53
|
stats[:sidekiq_usage] = (stats[:sidekiq_busy] / stats[:sidekiq_capacity].to_f).round(2)
|
52
54
|
stats
|
53
55
|
end
|
56
|
+
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Kubernetes
|
2
|
+
module Health
|
3
|
+
class SidekiqOptionsResolver
|
4
|
+
def self.[](key)
|
5
|
+
return Sidekiq[key] if Sidekiq.respond_to?('[]')
|
6
|
+
return Sidekiq.options[key] if Sidekiq.respond_to?('options') # Sidekiq ~> 6.0
|
7
|
+
return Sidekiq::Config.new[key] if defined?(Sidekiq::Config) # Sidekiq ~> 7.0
|
8
|
+
|
9
|
+
raise 'Sidekiq version not supported'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/kubernetes/health.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes-health
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wagner Caixeta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,16 +84,22 @@ dependencies:
|
|
84
84
|
name: prometheus-client
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '1.0'
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '5'
|
90
93
|
type: :runtime
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
|
-
- - "
|
97
|
+
- - ">="
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: '1.0'
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '5'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: puma
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +145,7 @@ files:
|
|
139
145
|
- lib/kubernetes/health/rack_on_migrate.rb
|
140
146
|
- lib/kubernetes/health/rack_on_sidekiq.rb
|
141
147
|
- lib/kubernetes/health/railtie.rb
|
148
|
+
- lib/kubernetes/health/sidekiq_options_resolver.rb
|
142
149
|
- lib/kubernetes/health/version.rb
|
143
150
|
- lib/puma/kubernetes/app.rb
|
144
151
|
- lib/puma/kubernetes/dsl.rb
|