kubernetes-health 3.2.0 → 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: 33187ecbabbca1f845ed61bd7159731e7477d113fa83f319eeeb77e715458f12
4
- data.tar.gz: 40059808df7f3f1f91b94f77583ab43a8bb8a6bc41df9794f1345f45b5f4c218
3
+ metadata.gz: 5df4e073ae78f559a70c2664c4d208b8966ddfd26eca774c4dd4b8d51e22088c
4
+ data.tar.gz: 3d1af211d98f43af48d47274cd8b0ea168d6f8f177c0db46352ff8d2e07678f9
5
5
  SHA512:
6
- metadata.gz: 37f4e926a7a7d649b723c692f903b8863dc91ba8088e392ea2afeab1666fe20a43d411a56577fff4795ac1538c923cc320e1527a58cfb0da02e886dab62e9f15
7
- data.tar.gz: abdc9fe6fcf8a28c508a2508d3e996887a936e125f8817e7a9756c10a24d7dac10c0d6330bb3d623325b8a940d571c37191fd3f0cbe8ccab96e5fddbc4cb5e86
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.2'
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
 
@@ -128,10 +117,18 @@ Kubernetes::Health::Config.route_readiness = '/readiness'
128
117
  Kubernetes::Health::Config.route_metrics = '/metrics'
129
118
  ```
130
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
+
131
128
  ## Customizing requests logs
132
129
 
133
130
  ```
134
131
  Kubernetes::Health::Config.request_log_callback = lambda { |req, http_code|
135
132
  Rails.logger.debug "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}" rescue nil
136
133
  }
137
- ```
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'
34
+ spec.add_runtime_dependency 'prometheus-client'
35
35
  spec.add_runtime_dependency 'puma'
36
36
  end
@@ -8,9 +8,10 @@ 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
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
14
15
  }
15
16
 
16
17
  @@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
@@ -23,7 +24,7 @@ module Kubernetes
23
24
  def self.lock_or_wait=(value)
24
25
  @@lock_or_wait = value
25
26
  end
26
-
27
+
27
28
  def self.request_log_callback
28
29
  @@request_log_callback
29
30
  end
@@ -96,6 +97,13 @@ module Kubernetes
96
97
  @@ready_if = value
97
98
  end
98
99
 
100
+ def self.response_format
101
+ @@response_format
102
+ end
103
+
104
+ def self.response_format=(value)
105
+ @@response_format = value
106
+ end
99
107
  end
100
108
  end
101
109
  end
@@ -1,5 +1,5 @@
1
1
  module Kubernetes
2
2
  module Health
3
- VERSION = "3.2.0"
3
+ VERSION = "3.3.0"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ module Puma
17
17
  req = ::Rack::Request.new(_env)
18
18
  type = {}
19
19
  content = []
20
- type = { 'Content-Type' => 'text/plain' }
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
23
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)
@@ -28,7 +28,7 @@ module Puma
28
28
  when ::Kubernetes::Health::Config.route_metrics
29
29
  http_code = 200
30
30
  @parser.parse JSON.parse(@launcher.stats)
31
- content = [Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]
31
+ content = ::Kubernetes::Health::Config.response_format == 'json' ? @launcher.stats : Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)
32
32
  else
33
33
  http_code = 404
34
34
  end
@@ -36,8 +36,8 @@ module Puma
36
36
  http_code = 500
37
37
  content = []
38
38
  end
39
- ::Kubernetes::Health::Config.request_log_callback.call(req, http_code)
40
- [http_code, type, content]
39
+ ::Kubernetes::Health::Config.request_log_callback.call(req, http_code, content)
40
+ [http_code, type, [content]]
41
41
  end
42
42
  end
43
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.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wagner Caixeta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-04 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,16 +84,16 @@ 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
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.1.4
163
+ rubygems_version: 3.2.17
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: This gem allows kubernetes monitoring your app while it is running migrates