kubernetes-health 3.3.1 → 3.5.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: 59bbdf0e963539df25aa7a994a4fcc54a653506d76df2fa5aa6bbae70994ee98
4
- data.tar.gz: b783c8b8df00a8304b5f853b0c13ce9fe09bf8972b55c906d15f42a23c23c5b0
3
+ metadata.gz: b35fdf1eae585364a30777a0f0c8d67210ab99d97c492c33ea7e9c5a71b7d01c
4
+ data.tar.gz: a4b4f532380c9295e6077d4aba889abb9a17c36889a713d7e84d864b8f9c8e6d
5
5
  SHA512:
6
- metadata.gz: 103a26a9a2224f13e246fe1dcc2544990f39a1944f2c989626e0cf44a903a84b2a2fc88b293e1a6ce4269498ccf9abd988a55c4a2ebe7282cbd209371bebd5a2
7
- data.tar.gz: 3cd7707bd895b10acb41c68f9d574320599fe5ac1e01fb29f30e9afe2c2a26b382443e2f1db9f0ef4b9dabe54a8641f32920b38075a8151e0405a67ed815e310
6
+ metadata.gz: 67cd817d32945e1f17f0b9363c393a408df9aec7352af14567d52a7562eab4969719b637f3c7acf3870595951f33a292ba9855c863b70bc125705f2b9f813ef1
7
+ data.tar.gz: ca42a6d7350435fb33c40521e4e2c72f2046af6fda5c634b3b4994960b8dea4af93d0015b037e80344559149ce329673dccdee6156baf9cabb98607f87519a6a
data/README.md CHANGED
@@ -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.3'
18
+ gem 'kubernetes-health', '~> 3.5'
19
19
  ```
20
20
 
21
21
  ## Enabling puma plugin
@@ -128,7 +128,7 @@ Kubernetes::Health::Config.response_format = 'json'
128
128
  ## Customizing requests logs
129
129
 
130
130
  ```
131
- Kubernetes::Health::Config.request_log_callback = lambda { |req, http_code|
132
- Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
131
+ Kubernetes::Health::Config.request_log_callback = lambda { |req, http_code, content|
132
+ Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}\n#{content}" rescue nil
133
133
  }
134
134
  ```
@@ -1,5 +1,5 @@
1
1
  module Kubernetes
2
2
  module Health
3
- VERSION = "3.3.1"
3
+ VERSION = "3.5.0"
4
4
  end
5
5
  end
@@ -16,7 +16,7 @@ module Puma
16
16
  begin
17
17
  req = ::Rack::Request.new(_env)
18
18
  type = {}
19
- content = []
19
+ content = ''
20
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
@@ -27,18 +27,52 @@ 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
- @parser.parse JSON.parse(@launcher.stats)
31
- content = ::Kubernetes::Health::Config.response_format == 'json' ? @launcher.stats : Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)
30
+ if ::Kubernetes::Health::Config.response_format == 'json'
31
+ content = include_puma_key_prefix(include_usage(merge_worker_status_if_needed(@launcher.stats))).to_json
32
+ else
33
+ @parser.parse include_usage(merge_worker_status_if_needed(@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
- rescue
39
+ rescue => e
40
+ puts e.message
41
+ puts e.backtrace.join("\n")
36
42
  http_code = 500
37
- content = []
43
+ content = ''
38
44
  end
39
45
  ::Kubernetes::Health::Config.request_log_callback.call(req, http_code, content)
40
46
  [http_code, type, [content]]
41
47
  end
48
+
49
+ def merge_worker_status_if_needed(stats)
50
+ return stats unless stats[:worker_status]
51
+
52
+ merded_stats = stats[:worker_status].map { |ws| ws[:last_status] }.inject({}) { |sum, hash| sum.merge(hash) { |_key, val1, val2| val1+val2 } }
53
+ merded_stats[:puma_started_at] = stats[:puma_started_at]
54
+ merded_stats[:worker_status] = stats[:worker_status]
55
+ merded_stats
56
+ end
57
+
58
+ def include_usage(stats)
59
+ if stats.is_a?(String)
60
+ # puma <= 4.
61
+ stats = JSON.parse(stats)
62
+ else
63
+ # Puma >=5 uses symbol.
64
+ stats = JSON.parse(stats.to_json)
65
+ end
66
+ stats['usage'] = (1 - stats['pool_capacity'].to_f / stats['max_threads']).round(2)
67
+ stats
68
+ end
69
+ def include_puma_key_prefix(stats)
70
+ result = {}
71
+ stats.each do |k,v|
72
+ result["puma_#{k}"] = v
73
+ end
74
+ result
75
+ end
42
76
  end
43
77
  end
44
78
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes-health
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.5.0
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: 2021-07-29 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -145,7 +145,7 @@ files:
145
145
  homepage: https://github.com/platbr/kubernetes-health
146
146
  licenses: []
147
147
  metadata: {}
148
- post_install_message:
148
+ post_install_message:
149
149
  rdoc_options: []
150
150
  require_paths:
151
151
  - lib
@@ -160,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.2.17
164
- signing_key:
163
+ rubygems_version: 3.1.4
164
+ signing_key:
165
165
  specification_version: 4
166
166
  summary: This gem allows kubernetes monitoring your app while it is running migrates
167
167
  and after it started.