kubernetes-health 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -5
- data/kubernetes-health.gemspec +2 -0
- data/lib/kubernetes/health/config.rb +28 -0
- data/lib/kubernetes/health/lock_on_migrate.rake +13 -0
- data/lib/kubernetes/health/rack_on_migrate.rake +5 -16
- data/lib/kubernetes/health/rack_on_migrate.rb +19 -0
- data/lib/kubernetes/health/railtie.rb +1 -0
- data/lib/kubernetes/health/version.rb +1 -1
- metadata +31 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4425830e42d12960033f406ddb4e3da9d33e7d4f2836362cfad272b2aefa7aee
|
4
|
+
data.tar.gz: 72ea97e57b9100f0e465abf1e1e17168a8706f8eeb85f9d14b3e4f5d5660d6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 779947240739615102d287539e8f9542c1e73c2af1c5cc4d2d11d2760c866b5b6669d4482a881518844d028be4e53e930549d80b41bbfb6af3136ea6207ad84f
|
7
|
+
data.tar.gz: 16127f3a04957449a1c731ff2649e5b480b88486c1d2d94d572c80c162cfdd802e05c8db36a722b7435624d4b604d5d4deae151281702468182cc3a2b95390ed
|
data/README.md
CHANGED
@@ -5,14 +5,15 @@ This gem allows kubernetes monitoring your app while it is running migrates and
|
|
5
5
|
# Features
|
6
6
|
- add routes `/_readiness` and `/_liveness` on rails stack by default.
|
7
7
|
- allow custom checks for `/_readiness` and `/_liveness` on rails stack.
|
8
|
-
- add routes `/_readiness` and `/_liveness` while `rake db:migrate` runs. (optional)
|
8
|
+
- add routes `/_readiness` and `/_liveness` while `rake db:migrate` runs. (optional)
|
9
|
+
- add support to avoid parallel running of `rake db:migrate` while keep kubernetes waiting. (optional)
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
12
13
|
Add this line to your application's Gemfile:
|
13
14
|
|
14
15
|
```ruby
|
15
|
-
gem 'kubernetes-health', '~> 2.
|
16
|
+
gem 'kubernetes-health', '~> 2.1'
|
16
17
|
```
|
17
18
|
|
18
19
|
## Enabling monitoring while `rake db:migrate` runs
|
@@ -24,8 +25,8 @@ Add `KUBERNETES_HEALTH_ENABLE_RACK_ON_MIGRATE=true` environment variable.
|
|
24
25
|
or add in your `application.rb`.
|
25
26
|
|
26
27
|
```
|
27
|
-
|
28
|
-
|
28
|
+
# default: false
|
29
|
+
Kubernetes::Health::Config.enable_rack_on_migrate = true
|
29
30
|
```
|
30
31
|
|
31
32
|
In Kubernetes you need to configure your deployment `readinessProbe` like this:
|
@@ -46,7 +47,30 @@ In Kubernetes you need to configure your deployment `readinessProbe` like this:
|
|
46
47
|
```
|
47
48
|
|
48
49
|
### How `rake db:migrate` monitoring works
|
49
|
-
It will run a RACK server for `/_readiness` and `/_liveness` routes while
|
50
|
+
It will run a RACK server for `/_readiness` and `/_liveness` routes while `rake db:migrate` is running.
|
51
|
+
|
52
|
+
## Avoid `rake db:migrate` parallel running.
|
53
|
+
|
54
|
+
Add `KUBERNETES_HEALTH_ENABLE_LOCK_ON_MIGRATE=true` environment variable.
|
55
|
+
|
56
|
+
or add in your `application.rb`.
|
57
|
+
|
58
|
+
```
|
59
|
+
# default: false
|
60
|
+
Kubernetes::Health::Config.enable_lock_on_migrate = true
|
61
|
+
```
|
62
|
+
|
63
|
+
### Customizing locking
|
64
|
+
By default it is working for PostgreSQL, but you can customize it using a lambda:
|
65
|
+
```
|
66
|
+
Kubernetes::Health::Config.lock_or_wait = lambda {
|
67
|
+
ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);'
|
68
|
+
}
|
69
|
+
|
70
|
+
Kubernetes::Health::Config.unlock = lambda {
|
71
|
+
ActiveRecord::Base.connection.execute 'select pg_advisory_unlock(123456789123456789);'
|
72
|
+
}
|
73
|
+
```
|
50
74
|
|
51
75
|
## Customizing checks
|
52
76
|
|
data/kubernetes-health.gemspec
CHANGED
@@ -3,9 +3,36 @@ module Kubernetes
|
|
3
3
|
class Config
|
4
4
|
@@live_if = lambda { true }
|
5
5
|
@@ready_if = lambda { true }
|
6
|
+
@@enable_lock_on_migrate = ActiveRecord::Type::Boolean.new.cast(ENV['KUBERNETES_HEALTH_ENABLE_LOCK_ON_MIGRATE']) || false
|
6
7
|
@@enable_rack_on_migrate = ActiveRecord::Type::Boolean.new.cast(ENV['KUBERNETES_HEALTH_ENABLE_RACK_ON_MIGRATE']) || false
|
7
8
|
@@route_liveness = '/_liveness'
|
8
9
|
@@route_readiness = '/_readiness'
|
10
|
+
@@lock_or_wait = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_lock(123456789123456789);' }
|
11
|
+
@@unlock = lambda { ActiveRecord::Base.connection.execute 'select pg_advisory_unlock(123456789123456789);' }
|
12
|
+
|
13
|
+
def self.lock_or_wait
|
14
|
+
@@lock_or_wait
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.lock_or_wait=(value)
|
18
|
+
@@lock_or_wait = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.unlock
|
22
|
+
@@unlock
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.unlock=(value)
|
26
|
+
@@unlock = value
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.enable_lock_on_migrate
|
30
|
+
@@enable_lock_on_migrate
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.enable_lock_on_migrate=(value)
|
34
|
+
@@enable_lock_on_migrate = value
|
35
|
+
end
|
9
36
|
|
10
37
|
def self.enable_rack_on_migrate
|
11
38
|
@@enable_rack_on_migrate
|
@@ -46,6 +73,7 @@ module Kubernetes
|
|
46
73
|
def self.ready_if=(value)
|
47
74
|
@@ready_if = value
|
48
75
|
end
|
76
|
+
|
49
77
|
end
|
50
78
|
end
|
51
79
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :kubernetes_health do
|
2
|
+
task :lock_on_migrate do
|
3
|
+
Rails.logger.info "Kubernetes Health: Lock on Migrate - Locking or waiting started."
|
4
|
+
Kubernetes::Health::Config.lock_or_wait.call
|
5
|
+
Rails.logger.info "Kubernetes Health: Lock on Migrate - Locking or waiting finished."
|
6
|
+
at_exit {
|
7
|
+
Rails.logger.info "Kubernetes Health: Lock on Migrate - Unlocking started."
|
8
|
+
Kubernetes::Health::Config.unlock.call
|
9
|
+
Rails.logger.info "Kubernetes Health: Lock on Migrate - Unlocking finished."
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
Rake::Task['db:migrate'].enhance(['kubernetes_health:lock_on_migrate'])
|
@@ -1,21 +1,10 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require "kubernetes/health/rack_on_migrate"
|
1
3
|
namespace :kubernetes_health do
|
2
|
-
task :
|
4
|
+
task :rack_on_migrate do
|
3
5
|
Thread.new {
|
4
|
-
|
5
|
-
Rack::Handler.default.run ->(env) {
|
6
|
-
req = Rack::Request.new(env)
|
7
|
-
case req.path_info
|
8
|
-
when Kubernetes::Health::Config.route_readiness
|
9
|
-
http_code = 503
|
10
|
-
when Kubernetes::Health::Config.route_liveness
|
11
|
-
http_code = 200
|
12
|
-
else
|
13
|
-
http_code = 404
|
14
|
-
end
|
15
|
-
Rails.logger.info "Kubernetes Health: Rack on Migrate - Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}"
|
16
|
-
[http_code, {}, []]
|
17
|
-
}
|
6
|
+
Rack::Handler.default.run Kubernetes::Health::RackOnMigrate.new
|
18
7
|
}
|
19
8
|
end
|
20
9
|
end
|
21
|
-
Rake::Task['db:migrate'].enhance(['kubernetes_health:
|
10
|
+
Rake::Task['db:migrate'].enhance(['kubernetes_health:rack_on_migrate'])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Kubernetes
|
2
|
+
module Health
|
3
|
+
class RackOnMigrate
|
4
|
+
def call(env)
|
5
|
+
req = Rack::Request.new(env)
|
6
|
+
case req.path_info
|
7
|
+
when Kubernetes::Health::Config.route_readiness
|
8
|
+
http_code = 503
|
9
|
+
when Kubernetes::Health::Config.route_liveness
|
10
|
+
http_code = 200
|
11
|
+
else
|
12
|
+
http_code = 404
|
13
|
+
end
|
14
|
+
Rails.logger.info "Kubernetes Health: Rack on Migrate - Request: Path: #{req.path_info} / Params: #{req.params} / HTTP Code: #{http_code}"
|
15
|
+
[http_code, {}, []]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,6 +3,7 @@ module Kubernetes
|
|
3
3
|
class Railtie < Rails::Railtie
|
4
4
|
rake_tasks do
|
5
5
|
load 'kubernetes/health/rack_on_migrate.rake' if Kubernetes::Health::Config.enable_rack_on_migrate
|
6
|
+
load 'kubernetes/health/lock_on_migrate.rake' if Kubernetes::Health::Config.enable_lock_on_migrate
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes-health
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wagner Caixeta
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: "\n This gem allows kubernetes monitoring your app while it is running
|
56
84
|
migrates and after it started.\n Features:\n * add routes /_readiness and
|
57
85
|
/_liveness on rails stack by default;\n * allow custom checks for /_readiness
|
@@ -77,7 +105,9 @@ files:
|
|
77
105
|
- lib/kubernetes/health.rb
|
78
106
|
- lib/kubernetes/health/config.rb
|
79
107
|
- lib/kubernetes/health/engine.rb
|
108
|
+
- lib/kubernetes/health/lock_on_migrate.rake
|
80
109
|
- lib/kubernetes/health/rack_on_migrate.rake
|
110
|
+
- lib/kubernetes/health/rack_on_migrate.rb
|
81
111
|
- lib/kubernetes/health/railtie.rb
|
82
112
|
- lib/kubernetes/health/version.rb
|
83
113
|
homepage: https://github.com/platbr/kubernetes-health
|