kubernetes-health 3.0.4 → 3.3.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: 1f6652ceb0de891915e55a34edf552781090d114e054fc94d9d3a2b44ace54ab
4
- data.tar.gz: 5dab2e26584268bfa8f4001dbf740f520a67135f9fe559ff9c0b7a002abca3a2
3
+ metadata.gz: 5df4e073ae78f559a70c2664c4d208b8966ddfd26eca774c4dd4b8d51e22088c
4
+ data.tar.gz: 3d1af211d98f43af48d47274cd8b0ea168d6f8f177c0db46352ff8d2e07678f9
5
5
  SHA512:
6
- metadata.gz: dbb0743d9d9b85392908464dc528406dce953d26a4b058745e9fa68cded4dbd96fb4f20e21948dd2245765ef0e5277df552d0ec863b288a294d7f60db4ddd0ae
7
- data.tar.gz: dbd17d495c5c44b25ac18cc593a1c329ec5cf012db45ef97bd4d26d1cecc548d8c734bc4f366f6c5d455317b8b050982559ae4daba6154623cdd91b98d57797d
6
+ metadata.gz: 63aa2dbfa961f84b042530fdeeb4a8950c9f71c769b18f451b0fbffc53348174a8ac2eef0c395ddec0370d3d3e2b975f624f39d39b88ea300df7b1b615d60d93
7
+ data.tar.gz: b41b0cd16d76ac02257525c75af8c65e5891f5607005c8c29f2501d5e5e217096364479fc29b6604e977df071c7a0be7baa50be6549f51988bcdc4c158a74ca8
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Kubernetes::Health
2
2
 
3
- This gem allows kubernetes monitoring your app while it is running migrates and after it started.
3
+ This gem allows kubernetes monitoring your app while it is running migrates and after it starts.
4
4
 
5
5
  # Features
6
6
  - add routes `/_readiness`, `/_liveness` on rails stack.
7
7
  - add routes `/_readiness`, `/_liveness` and `/_metrics` as a puma plugin.
8
- - metrics are prometheus compatible (code copied from `puma-metrics` gem).
8
+ - metrics are prometheus compatible (code copied from `puma-metrics` gem) or json.
9
9
  - allow custom checks for `/_readiness` and `/_liveness`.
10
10
  - add routes `/_readiness` and `/_liveness` while `rake db:migrate` runs. (optional)
11
11
  - add support to avoid parallel running of `rake db:migrate` while keep kubernetes waiting. (optional)
@@ -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.3'
19
19
  ```
20
20
 
21
21
  ## Enabling puma plugin
@@ -48,18 +48,6 @@ In Kubernetes you need to configure your deployment `readinessProbe` and `livene
48
48
  ```
49
49
 
50
50
  Setting `failureThreshold` is import to avoid problems when app finish migrates and is starting the web process.
51
-
52
- ## Enabling prometheus metrics
53
-
54
- ```
55
- template:
56
- metadata:
57
- annotations:
58
- prometheus.io/path: '/_metrics'
59
- prometheus.io/port: '9393'
60
- prometheus.io/scrape: 'true'
61
- ```
62
-
63
51
  ## Enabling monitoring while `rake db:migrate` runs
64
52
 
65
53
  Your Dockerfile's entry script needs to run migrates before start your web app.
@@ -106,18 +94,19 @@ Kubernetes::Health::Config.unlock = lambda {
106
94
 
107
95
  It only works for routes in rails stack, they are not executed while `rake db:migrate` runs.
108
96
 
109
- I prefer do nothing else on `liveness` to avoid unnecessary `CrashLoopBackOff` status. `params` is optional.
97
+ I prefer do nothing else on `liveness` to avoid unnecessary `CrashLoopBackOff` status. `params` is optional (request params).
110
98
 
111
99
  ```
112
- Kubernetes::Health::Config.live_if = lambda {
100
+ Kubernetes::Health::Config.live_if = lambda { |params|
113
101
  true
114
102
  }
115
103
 
116
104
  ```
117
- Ex. Check if PostgreSQL is reachable on `readiness`. `params` is optional.
105
+ Ex. Check if PostgreSQL is reachable on `readiness` indicating that credentials are setup right and keeps cache to avoid doing it a lot. `params` is optional (request params).
118
106
  ```
119
107
  Kubernetes::Health::Config.ready_if = lambda { |params|
120
- ActiveRecord::Base.connection.execute("SELECT 1").cmd_tuples != 1
108
+ return $kubernetes_health_test_db_connection if $kubernetes_health_test_db_connection
109
+ $kubernetes_health_test_db_connection = ActiveRecord::Base.connection.execute("SELECT 1").cmd_tuples == 1
121
110
  }
122
111
  ```
123
112
 
@@ -127,3 +116,19 @@ Kubernetes::Health::Config.route_liveness = '/liveness'
127
116
  Kubernetes::Health::Config.route_readiness = '/readiness'
128
117
  Kubernetes::Health::Config.route_metrics = '/metrics'
129
118
  ```
119
+
120
+ ## Response format
121
+ If you are using `https://github.com/zalando-incubator/kube-metrics-adapter` you will want to use `json` format.
122
+
123
+ Default is `prometheus`.
124
+ ```
125
+ Kubernetes::Health::Config.response_format = 'json'
126
+ ```
127
+
128
+ ## Customizing requests logs
129
+
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
133
+ }
134
+ ```
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.14"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "bundler"
30
+ spec.add_development_dependency "rake"
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', '~> 0.9.0'
35
- spec.add_runtime_dependency 'puma', '~> 3.0'
34
+ spec.add_runtime_dependency 'prometheus-client'
35
+ spec.add_runtime_dependency 'puma'
36
36
  end
@@ -8,6 +8,12 @@ module Kubernetes
8
8
  @@route_liveness = '/_liveness'
9
9
  @@route_readiness = '/_readiness'
10
10
  @@route_metrics = '/_metrics'
11
+ @@response_format = 'prometheus'
12
+
13
+ @@request_log_callback = lambda { |req, http_code, content|
14
+ 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
+ }
16
+
11
17
  @@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
12
18
  @@unlock = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_unlock(123456789123456789);' }
13
19
 
@@ -19,6 +25,14 @@ module Kubernetes
19
25
  @@lock_or_wait = value
20
26
  end
21
27
 
28
+ def self.request_log_callback
29
+ @@request_log_callback
30
+ end
31
+
32
+ def self.request_log_callback=(value)
33
+ @@request_log_callback = value
34
+ end
35
+
22
36
  def self.unlock
23
37
  @@unlock
24
38
  end
@@ -83,6 +97,13 @@ module Kubernetes
83
97
  @@ready_if = value
84
98
  end
85
99
 
100
+ def self.response_format
101
+ @@response_format
102
+ end
103
+
104
+ def self.response_format=(value)
105
+ @@response_format = value
106
+ end
86
107
  end
87
108
  end
88
109
  end
@@ -11,7 +11,7 @@ module Kubernetes
11
11
  else
12
12
  http_code = 404
13
13
  end
14
- Rails.logger.info "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.0.4"
3
+ VERSION = "3.3.0"
4
4
  end
5
5
  end
@@ -13,26 +13,31 @@ 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)
29
- type = { 'Content-Type' => 'text/plain' }
30
- content = [Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]
31
- else
32
- http_code = 404
16
+ begin
17
+ req = ::Rack::Request.new(_env)
18
+ type = {}
19
+ content = []
20
+ type = ::Kubernetes::Health::Config.response_format == 'json' ? { 'Content-Type' => 'application/json' } : { 'Content-Type' => 'text/plain' }
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 = ::Kubernetes::Health::Config.response_format == 'json' ? @launcher.stats : 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.info "Kubernetes Health: Puma Plugin - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
35
- [http_code, type, content]
39
+ ::Kubernetes::Health::Config.request_log_callback.call(req, http_code, content)
40
+ [http_code, type, [content]]
36
41
  end
37
42
  end
38
43
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes-health
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.3.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-10-30 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rack
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,30 +84,30 @@ 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
- version: 0.9.0
89
+ version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 0.9.0
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: puma
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '3.0'
103
+ version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '3.0'
110
+ version: '0'
111
111
  description: "\n This gem allows kubernetes monitoring your app while it is running
112
112
  migrates and after it started.\n Features:\n * add routes /_readiness and
113
113
  /_liveness on rails stack by default;\n * allow custom checks for /_readiness
@@ -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.2.17
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.