kubernetes-health 3.12.0 → 3.12.4

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: 9db3c40048a1127229efee6653df4da36ef6d38ef1b57ab51677073fecdede0d
4
- data.tar.gz: 12402ee8b8e151cb4c5992d63fc37607f6ae7ae070e6e8fb57862825ec0b7146
3
+ metadata.gz: 69c1ed0bafbc26dfa3d4cf60ed954557841469e134131a58826c5b17dbd2dd6e
4
+ data.tar.gz: 6300a0c9d587f641cd649b0715162f701544560a39a69bfbaab40d16dc0c482d
5
5
  SHA512:
6
- metadata.gz: 598d564124cc3ff32b959538f4e3d9d9863c058ece7eadc9dd37fccfbdd4fe1010b503382a24d319d690c87a12bf3a81f8b1c7717ddb3ae954d7c9f242a7db0b
7
- data.tar.gz: 8c8bd4f687f964583cb2390bd7c43f141173bb8273a47fed82269e4829a36c43a92bcfa681e5c13e104be2488c905f65361714e1ca4e46e6e38a89406e2e210d
6
+ metadata.gz: b622eb35caa632f931a22c4da90c6613ac65307d8def6a635ef91f73709a65b0d303f77ea9752e0a0e9e90e5b87d90892237a86cc4e7fd5bdf77fbb334697385
7
+ data.tar.gz: 749a290a82252eb12a526c06fa84c201ef83d5e4122610ad1de0aa84683e316459515e1a174e6360104b4bd01d407f7ad9f0652b9ae25eb2b8c056ce1b82c334
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Kubernetes::Health
2
- This gem open a HTTP port for monitoring your rails app while it is running Migrates, Sidekiq and Puma.
2
+ This gem opens a dedicated HTTP port to allow Kubernetes to monitor your Rails app while it is running migrations, Rake tasks, Sidekiq, or Puma.
3
3
 
4
4
  # Features
5
5
  - Puma and Sidekiq metrics for autoscaling.
6
- - Prometheus and JSON metrics (tested using https://github.com/zalando-incubator/kube-metrics-adapter and JSON format).
6
+ - Prometheus and JSON metrics.
7
7
  - add routes `/_readiness`, `/_liveness` on Rails Stack.
8
8
  - add routes `/_readiness`, `/_liveness` and `/_metrics` as a puma plugin at another port to avoid problems when your app get busy. (code copied from `puma-metrics` gem).
9
9
  - add routes `/_readiness` and `/_liveness` while `rake db:migrate` runs. (optional)
10
- - add routes `/_readiness` and `/_liveness` while `sidekiq` runs. (optional)
10
+ - add routes `/_metrics` while `sidekiq` runs. (optional)
11
11
  - add support to avoid parallel running of `rake db:migrate` while keep kubernetes waiting (PostgreSQL required).
12
12
  - allow custom checks for `/_readiness` and `/_liveness`.
13
13
 
@@ -16,7 +16,7 @@ This gem open a HTTP port for monitoring your rails app while it is running Migr
16
16
  Add this line to your application's Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'kubernetes-health', '~> 3.7'
19
+ gem 'kubernetes-health', '~> 3.12.1'
20
20
  ```
21
21
 
22
22
  ## Enabling puma plugin
@@ -80,7 +80,7 @@ Rake::Task['assets:precompile'].enhance(['kubernetes_health:rack_on_rake'])
80
80
  Rake::Task['assets:clobber'].enhance(['kubernetes_health:rack_on_rake'])
81
81
  ```
82
82
 
83
- I do recomend doing some check to make it only enables in K8S environment.
83
+ I do recommend doing some checks to make it only enabled in the K8S environment.
84
84
  The defined port at `config/puma.rb` will be used but can be overrided by `KUBERNETES_HEALTH_METRICS_PORT` env var.
85
85
 
86
86
  ## Enabling liveness/readiness routes for `sidekiq`
@@ -96,11 +96,11 @@ Kubernetes::Health::Config.enable_rack_on_sidekiq = true
96
96
  The defined port at `config/puma.rb` will be used but can be overrided by `KUBERNETES_HEALTH_METRICS_PORT` env var.
97
97
 
98
98
  ### How `rake` and `sidekiq` monitoring works
99
- It will run a RACK server for `/_readiness`, `/_liveness` and `/_metrics`.
99
+ It will run a rack server for `/_readiness`, `/_liveness` and `/_metrics` for rake and `/_metrics` for Sidekiq.
100
100
  The liveness route will respond using `200` but readiness `503`.
101
101
 
102
102
  ## Avoiding migrations running in parallel and making kubernetes happy.
103
- Rails already avoid migrations running in parallel, but it raise exceptions. This gem will just wait for other migrations without exit.
103
+ Rails already avoid migrations running in parallel, but it raises exceptions. This gem will just wait for other migrations without exit.
104
104
  If you enable `rack_on_migrate` together with this, kubernetes will just wait, avoiding erros.
105
105
 
106
106
 
@@ -1,5 +1,5 @@
1
1
  module Kubernetes
2
2
  module Health
3
- VERSION = '3.12.0'.freeze
3
+ VERSION = '3.12.4'.freeze
4
4
  end
5
5
  end
@@ -22,7 +22,7 @@ module Puma
22
22
  case req.path_info
23
23
  when ::Kubernetes::Health::Config.route_liveness
24
24
  i_am_live = ::Kubernetes::Health::Config.live_if.arity.zero? ? ::Kubernetes::Health::Config.live_if.call : ::Kubernetes::Health::Config.live_if.call(req.params)
25
- http_code = puma_already_started?(extended_puma_stats) && i_am_live ? 200 : 503
25
+ http_code = i_am_live ? 200 : 503
26
26
  when ::Kubernetes::Health::Config.route_readiness
27
27
  i_am_ready = ::Kubernetes::Health::Config.ready_if.arity.zero? ? ::Kubernetes::Health::Config.ready_if.call : ::Kubernetes::Health::Config.ready_if.call(req.params)
28
28
  http_code = puma_already_started?(extended_puma_stats) && i_am_ready ? 200 : 503
@@ -54,11 +54,13 @@ module Puma
54
54
  end
55
55
 
56
56
  def generate_extended_puma_stats
57
- return {} if @launcher.nil?
58
-
59
- puma_stats = @launcher.stats
57
+ begin
58
+ puma_stats = @launcher.stats
59
+ rescue NoMethodError
60
+ puma_stats = {}
61
+ end
60
62
  # On puma <= 4 puma_stats is a String
61
- puma_stats = JSON.parse(puma_stats, symbolize_names: true) unless puma_stats.is_a?(Hash)
63
+ puma_stats = JSON.parse(puma_stats, symbolize_names: true) if puma_stats.is_a?(String)
62
64
  # Including usage stats.
63
65
  puma_stats = merge_worker_status(puma_stats) if puma_stats[:worker_status].present?
64
66
  puma_stats[:usage] = (1 - puma_stats[:pool_capacity].to_f / puma_stats[:max_threads]).round(2) if puma_stats[:pool_capacity].present?
@@ -87,6 +89,8 @@ module Puma
87
89
  end
88
90
 
89
91
  def puma_already_started?(extended_puma_stats)
92
+ return false if extended_puma_stats.empty?
93
+
90
94
  if extended_puma_stats[:booted_workers].present?
91
95
  # Cluster Mode
92
96
  extended_puma_stats[:booted_workers].positive?
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.12.0
4
+ version: 3.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wagner Caixeta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-28 00:00:00.000000000 Z
11
+ date: 2024-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler