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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adaef68a4c3f4b6e2dcb2b3c7aa5f8c4e72544b22edb147e35e2f72c3e8c6da4
4
- data.tar.gz: 52f4cf9f5aabdf55ad239ff23fab548e3d2e883c674b7a68bef0848699774078
3
+ metadata.gz: f3ad95fa7855c4e929a649861a3b8e76c4c5178d4f0a9d15d4f59dbecd412d05
4
+ data.tar.gz: 8ddc6657bc1625af9a8397717a5c624363117396aa9f356d686d020753925a29
5
5
  SHA512:
6
- metadata.gz: ee8c2fc80a2e8635a573beb6e8298a9756aaf292c0deb658797d77cc3a3337c7e9bfd83d00409068574b538156c2836d1fc5b2c6a41e5984d759864e05850595
7
- data.tar.gz: 99855e3a23eb0c0f3fe90957c4d106bfebdd09c0e4434a1550907b300640ba4a7ed70c3ec8a845ca1aa2e2fc9f801a2ec811e000024544587d955dfbd945d469
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 && 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,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
@@ -1,5 +1,5 @@
1
1
  module Kubernetes
2
2
  module Health
3
- VERSION = '3.8.0'.freeze
3
+ VERSION = '3.10.0'.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.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-01-03 00:00:00.000000000 Z
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