kubernetes-health 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e427d7c50b8d63641547d488f86ea2d0e1d8ef3bb2203e6038c7e72fdbaf9983
4
- data.tar.gz: 4b3d7dc8dcf097ec2bb26c416261271dbe2d438cc4d05988eaf960b824b1fb9f
3
+ metadata.gz: 33187ecbabbca1f845ed61bd7159731e7477d113fa83f319eeeb77e715458f12
4
+ data.tar.gz: 40059808df7f3f1f91b94f77583ab43a8bb8a6bc41df9794f1345f45b5f4c218
5
5
  SHA512:
6
- metadata.gz: 135d139da735b92862dda7579219f8e7e9b6faca03a537792a187fc43ac1f5ef200e86b95abf62495d515ed036a7a23f811229660f5d781651d13c5bc38d2c41
7
- data.tar.gz: fe05142bde12ed043ecf91fc776f213272e5fa8ee0e261dbcf9702d82db674964ddb58130aaf8a6fc4a6e8cb6a03f3da2999347635ea10670d10dccf608d751a
6
+ metadata.gz: 37f4e926a7a7d649b723c692f903b8863dc91ba8088e392ea2afeab1666fe20a43d411a56577fff4795ac1538c923cc320e1527a58cfb0da02e886dab62e9f15
7
+ data.tar.gz: abdc9fe6fcf8a28c508a2508d3e996887a936e125f8817e7a9756c10a24d7dac10c0d6330bb3d623325b8a940d571c37191fd3f0cbe8ccab96e5fddbc4cb5e86
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.0'
18
+ gem 'kubernetes-health', '~> 3.2'
19
19
  ```
20
20
 
21
21
  ## Enabling puma plugin
@@ -127,3 +127,11 @@ Kubernetes::Health::Config.route_liveness = '/liveness'
127
127
  Kubernetes::Health::Config.route_readiness = '/readiness'
128
128
  Kubernetes::Health::Config.route_metrics = '/metrics'
129
129
  ```
130
+
131
+ ## Customizing requests logs
132
+
133
+ ```
134
+ Kubernetes::Health::Config.request_log_callback = lambda { |req, http_code|
135
+ Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
136
+ }
137
+ ```
@@ -8,6 +8,11 @@ module Kubernetes
8
8
  @@route_liveness = '/_liveness'
9
9
  @@route_readiness = '/_readiness'
10
10
  @@route_metrics = '/_metrics'
11
+
12
+ @@request_log_callback = lambda { |req, http_code|
13
+ Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
14
+ }
15
+
11
16
  @@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
12
17
  @@unlock = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_unlock(123456789123456789);' }
13
18
 
@@ -18,6 +23,14 @@ module Kubernetes
18
23
  def self.lock_or_wait=(value)
19
24
  @@lock_or_wait = value
20
25
  end
26
+
27
+ def self.request_log_callback
28
+ @@request_log_callback
29
+ end
30
+
31
+ def self.request_log_callback=(value)
32
+ @@request_log_callback = value
33
+ end
21
34
 
22
35
  def self.unlock
23
36
  @@unlock
@@ -11,7 +11,7 @@ module Kubernetes
11
11
  else
12
12
  http_code = 404
13
13
  end
14
- Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}"
14
+ ::Kubernetes::Health::Config.request_log_callback.call(req, http_code)
15
15
  [http_code, {}, []]
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Kubernetes
2
2
  module Health
3
- VERSION = "3.1.0"
3
+ VERSION = "3.2.0"
4
4
  end
5
5
  end
@@ -13,25 +13,30 @@ module Puma
13
13
  end
14
14
 
15
15
  def call(_env)
16
- req = ::Rack::Request.new(_env)
17
- type = {}
18
- content = []
19
- case req.path_info
20
- when ::Kubernetes::Health::Config.route_liveness
21
- i_am_live = ::Kubernetes::Health::Config.live_if.arity == 0 ? ::Kubernetes::Health::Config.live_if.call : ::Kubernetes::Health::Config.live_if.call(req.params)
22
- http_code = i_am_live ? 200 : 503
23
- when ::Kubernetes::Health::Config.route_readiness
24
- i_am_ready = ::Kubernetes::Health::Config.ready_if.arity == 0 ? ::Kubernetes::Health::Config.ready_if.call : ::Kubernetes::Health::Config.ready_if.call(req.params)
25
- http_code = i_am_ready ? 200 : 503
26
- when ::Kubernetes::Health::Config.route_metrics
27
- http_code = 200
28
- @parser.parse JSON.parse(@launcher.stats)
16
+ begin
17
+ req = ::Rack::Request.new(_env)
18
+ type = {}
19
+ content = []
29
20
  type = { 'Content-Type' => 'text/plain' }
30
- content = [Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]
31
- else
32
- http_code = 404
21
+ case req.path_info
22
+ when ::Kubernetes::Health::Config.route_liveness
23
+ i_am_live = ::Kubernetes::Health::Config.live_if.arity == 0 ? ::Kubernetes::Health::Config.live_if.call : ::Kubernetes::Health::Config.live_if.call(req.params)
24
+ http_code = i_am_live ? 200 : 503
25
+ when ::Kubernetes::Health::Config.route_readiness
26
+ i_am_ready = ::Kubernetes::Health::Config.ready_if.arity == 0 ? ::Kubernetes::Health::Config.ready_if.call : ::Kubernetes::Health::Config.ready_if.call(req.params)
27
+ http_code = i_am_ready ? 200 : 503
28
+ when ::Kubernetes::Health::Config.route_metrics
29
+ http_code = 200
30
+ @parser.parse JSON.parse(@launcher.stats)
31
+ content = [Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]
32
+ else
33
+ http_code = 404
34
+ end
35
+ rescue
36
+ http_code = 500
37
+ content = []
33
38
  end
34
- Rails.logger.debug "Kubernetes Health: Puma Plugin - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
39
+ ::Kubernetes::Health::Config.request_log_callback.call(req, http_code)
35
40
  [http_code, type, content]
36
41
  end
37
42
  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.1.0
4
+ version: 3.2.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: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2021-02-04 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.0.3
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.