kubernetes-health 3.7.2 → 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: dd3b71bfaba5d0455cb081dfd694554370f858167f3aeafa3e34deb66de9a7b0
4
- data.tar.gz: 030dd33dda0725a7d711d808a5e776fd3cd467a610fd17d3ab47c20d9629d756
3
+ metadata.gz: 5153394dce8ea22cce62b0826008d9febbeb406b6385296471cb00b6e6c50c52
4
+ data.tar.gz: ae76165497abc6c256d4609c28f27b782fc7d69f88a93a511c94567395c2716c
5
5
  SHA512:
6
- metadata.gz: ea3434326f57be5a3ebe8c40fce7865484e405862c8a81f93c49d79c0497e6d3723069de9ba2ca77f308e56f7791ff786134c458f5d8011e6cff611191cd6db8
7
- data.tar.gz: bb146f7557012fb1b1bdd9ac4dcf7627f2a8385e8f86608e5905bae799f558647e66217356f73350a55b5094bdca37779617a6928f533a6ab837262b86db6c34
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'
35
- spec.add_runtime_dependency 'puma'
34
+ spec.add_runtime_dependency 'prometheus-client', '>= 1.0', '< 5'
35
+ spec.add_runtime_dependency 'puma', '>= 5.0'
36
36
  end
@@ -6,13 +6,13 @@ 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
- 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
+ Rails.logger.debug "Kubernetes Health - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}\n#{content}" rescue nil
16
16
  }
17
17
 
18
18
  @@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
@@ -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.7.2'.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"
@@ -9,26 +9,26 @@ Puma::Plugin.create do
9
9
 
10
10
  app = Puma::Kubernetes::App.new launcher
11
11
  uri = URI.parse str
12
-
13
- kubernetes = Puma::Server.new app, launcher.events
14
- kubernetes.min_threads = 0
15
- kubernetes.max_threads = 1
12
+ log_writer = launcher.respond_to?(:log_writer) ? launcher.log_writer : launcher.events
13
+ puma_options = { min_threads: 0, max_threads: 1 }
14
+ puma_options[:log_writer] = log_writer unless log_writer.nil?
15
+ puma_server = Puma::Server.new app, launcher.events, puma_options
16
16
 
17
17
  case uri.scheme
18
18
  when 'tcp'
19
- launcher.events.log "* Starting kubernetes-healh server on #{str}"
20
- kubernetes.add_tcp_listener uri.host, uri.port
19
+ log_writer.log "* Starting kubernetes-healh server on #{str}"
20
+ puma_server.add_tcp_listener uri.host, uri.port
21
21
  else
22
- launcher.events.error "Invalid control URI: #{str}"
22
+ log_writer.error "Invalid control URI: #{str}"
23
23
  end
24
24
 
25
25
  launcher.events.register(:state) do |state|
26
26
  if %i[halt restart stop].include?(state)
27
- kubernetes.stop(true) unless kubernetes.shutting_down?
27
+ puma_server.stop(true) unless puma_server.shutting_down?
28
28
  end
29
29
  end
30
30
 
31
- kubernetes.run
31
+ puma_server.run
32
32
  end
33
33
  # rubocop:enable Kubernetes/MethodLength, Kubernetes/AbcSize
34
34
  end
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.7.2
4
+ version: 3.9.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: 2022-08-12 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,30 +84,36 @@ 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
100
106
  requirements:
101
107
  - - ">="
102
108
  - !ruby/object:Gem::Version
103
- version: '0'
109
+ version: '5.0'
104
110
  type: :runtime
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
114
  - - ">="
109
115
  - !ruby/object:Gem::Version
110
- version: '0'
116
+ version: '5.0'
111
117
  description: "\n This gem allows kubernetes monitoring your app while it is running
112
118
  migrates and after it started.\n Features:\n * add routes /_readiness and
113
119
  /_liveness on rails stack by default;\n * allow custom checks for /_readiness
@@ -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
@@ -147,7 +154,7 @@ files:
147
154
  homepage: https://github.com/platbr/kubernetes-health
148
155
  licenses: []
149
156
  metadata: {}
150
- post_install_message:
157
+ post_install_message:
151
158
  rdoc_options: []
152
159
  require_paths:
153
160
  - lib
@@ -162,8 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
169
  - !ruby/object:Gem::Version
163
170
  version: '0'
164
171
  requirements: []
165
- rubygems_version: 3.0.3.1
166
- signing_key:
172
+ rubygems_version: 3.3.3
173
+ signing_key:
167
174
  specification_version: 4
168
175
  summary: This gem allows kubernetes monitoring your app while it is running migrates
169
176
  and after it started.