kubernetes-health 3.8.0 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adaef68a4c3f4b6e2dcb2b3c7aa5f8c4e72544b22edb147e35e2f72c3e8c6da4
4
- data.tar.gz: 52f4cf9f5aabdf55ad239ff23fab548e3d2e883c674b7a68bef0848699774078
3
+ metadata.gz: 5153394dce8ea22cce62b0826008d9febbeb406b6385296471cb00b6e6c50c52
4
+ data.tar.gz: ae76165497abc6c256d4609c28f27b782fc7d69f88a93a511c94567395c2716c
5
5
  SHA512:
6
- metadata.gz: ee8c2fc80a2e8635a573beb6e8298a9756aaf292c0deb658797d77cc3a3337c7e9bfd83d00409068574b538156c2836d1fc5b2c6a41e5984d759864e05850595
7
- data.tar.gz: 99855e3a23eb0c0f3fe90957c4d106bfebdd09c0e4434a1550907b300640ba4a7ed70c3ec8a845ca1aa2e2fc9f801a2ec811e000024544587d955dfbd945d469
6
+ metadata.gz: 81ce8eaa10395f924d68cca575114a8e47c65f3c3c710b9a66f1801834518556dfa401f5c365586dd13a868758afdb2c83cfbd127034026cf0bf3b83eecde7ce
7
+ data.tar.gz: e2d8ce82aeb1fe27b7e0a76db760f24dcbf297fbb41bcbc0a4b66354bf04cb4a3e830b8409f6a9fdbd17e88fc79e1627e4b8cb06315619f84fbd2d74e53a0f89
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 && Sidekiq.options[:concurrency].positive?
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
@@ -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', '~> 1.0'
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 = generate_prometheus_registry
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])
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 generate_prometheus_registry
36
- prometheus_registry = Prometheus::Client.registry
37
- prometheus_registry.gauge(:sidekiq_capacity, 'Sidekiq Threads Number', index: 0)
38
- prometheus_registry.gauge(:sidekiq_busy, 'Sidekiq Busy Threads', index: 0)
39
- prometheus_registry.gauge(:sidekiq_usage, 'Result of sidekiq_busy/sidekiq_capacity', index: 0)
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 == Sidekiq.options[:identity] }
46
+ sidekiq_info = Sidekiq::ProcessSet.new.to_a.filter { |p| p.identity == SidekiqOptionsResolver[:identity] }
45
47
 
46
48
  stats = {
47
- sidekiq_capacity: Sidekiq.options[:concurrency],
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,12 @@
1
+ module Kubernetes
2
+ module Health
3
+ class SidekiqOptionsResolver
4
+ def self.[](key)
5
+ # Sidekiq >= 6.0.0
6
+ return Sidekiq[key] if Sidekiq.respond_to?('[]')
7
+
8
+ Sidekiq.options[key]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Kubernetes
2
2
  module Health
3
- VERSION = '3.8.0'.freeze
3
+ VERSION = '3.9.1'.freeze
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require "kubernetes/health/config"
2
+ require "kubernetes/health/sidekiq_options_resolver"
2
3
  require "kubernetes/health/version"
3
4
  require "kubernetes/health/engine"
4
5
  require "kubernetes/health/railtie"
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.8.0
4
+ version: 3.9.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: 2023-01-03 00:00:00.000000000 Z
11
+ date: 2023-03-30 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