resque-kubernetes-probes 1.0.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/resque_health_check +24 -0
- data/bin/setup +8 -0
- data/lib/resque/kubernetes/probes.rb +2 -0
- data/lib/resque/kubernetes/probes/resque-scheduler.rb +18 -0
- data/lib/resque/kubernetes/probes/resque.rb +18 -0
- data/lib/resque/kubernetes/probes/version.rb +7 -0
- data/resque-kubernetes-probes.gemspec +27 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f3d4cee1fc200619809dabb192e0d413029e16032f779f2fe98af3df136f64c
|
4
|
+
data.tar.gz: 4e28446cba8d457ac3b13b9b5fe5d2ecca8abc470f0a169545a097e01094e11e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 360111824372d9c5881ef82c0f3d3af1708d086fe3030aa09809683939f886238b66a00125394604d7d8771c4490a0cbf1e35d5ab6b2f33ac505d0d07ca5d472
|
7
|
+
data.tar.gz: 7ac6683d5a63d5ef9fd7a3cf0bb4fb5c5b1aba73cc61135ddf31adc47aeda5462ec94c94c059498405e20873dfeefbd355b698adfe464906d0d9f7c1c6b4837c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
resque-kubernetes-probes (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (12.3.3)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.1)
|
16
|
+
rspec-support (~> 3.9.1)
|
17
|
+
rspec-expectations (3.9.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
rake (~> 12.0)
|
30
|
+
resque-kubernetes-probes!
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Micke Lisinge
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Resque::Kubernetes::Probes
|
2
|
+
|
3
|
+
This gem injects code into Resque and Resque::Scheduler that touches a file in
|
4
|
+
the `tmp` directory `resque_health` for Resque and `resque_scheduler_health` for
|
5
|
+
Resque::Scheduler. These files can then be used by the Kubernetes liveness
|
6
|
+
probes to check that the worker and scheduler is running properly.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'resque-kubernetes-probes'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install resque-kubernetes-probes
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Download the script in your Dockerfile
|
27
|
+
|
28
|
+
The script is simple and checks that the heartbeat file has been updated in the
|
29
|
+
last `interval` seconds.
|
30
|
+
|
31
|
+
```dockerfile
|
32
|
+
RUN curl -f -o /usr/local/bin/resque_health_check -L "https://raw.githubusercontent.com/apoex/resque-kubernetes-probes/master/bin/resque_health_check" && \
|
33
|
+
chmod +x /usr/local/bin/resque_health_check
|
34
|
+
```
|
35
|
+
|
36
|
+
### Resque
|
37
|
+
|
38
|
+
The gem hooks into resque's heartbeat logic and by default the heartbeat
|
39
|
+
interval is quite high (60 seconds). We recommend lowering the default value and
|
40
|
+
making it configurable through environment variables.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
Resque.heartbeat_interval = ENV.fetch("RESQUE_HEARTBEAT_INTERVAL", 10).to_i
|
44
|
+
Resque.prune_interval = Resque.heartbeat_interval * 5
|
45
|
+
```
|
46
|
+
|
47
|
+
```yaml
|
48
|
+
livenessProbe:
|
49
|
+
timeoutSeconds: 1
|
50
|
+
periodSeconds: 5
|
51
|
+
exec:
|
52
|
+
command:
|
53
|
+
- resque_health_check
|
54
|
+
- tmp/resque_health
|
55
|
+
```
|
56
|
+
|
57
|
+
### Resque Scheduler
|
58
|
+
|
59
|
+
The gem does not inject itself into resque-scheduler by default, to do that you
|
60
|
+
need to add the probe to the list of required files.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
gem "resque-kubernetes-probes", require: ["resque/kubernetes/probes/resque", "resque/kubernetes/probes/resque-scheduler"]
|
64
|
+
```
|
65
|
+
|
66
|
+
```yaml
|
67
|
+
livenessProbe:
|
68
|
+
timeoutSeconds: 1
|
69
|
+
periodSeconds: 5
|
70
|
+
exec:
|
71
|
+
command:
|
72
|
+
- resque_health_check
|
73
|
+
- tmp/resque_scheduler_health
|
74
|
+
```
|
75
|
+
|
76
|
+
## Development
|
77
|
+
|
78
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
79
|
+
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/micke/resque-kubernetes-probes.
|
85
|
+
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "resque/kubernetes/probes"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
FILE="${1:-tmp/resque_health}"
|
6
|
+
|
7
|
+
if [[ $FILE =~ "scheduler" ]]; then
|
8
|
+
INTERVAL=${RESQUE_SCHEDULER_INTERVAL:-5}
|
9
|
+
else
|
10
|
+
INTERVAL=${RESQUE_HEARTBEAT_INTERVAL:-60}
|
11
|
+
fi
|
12
|
+
|
13
|
+
if test -f "$FILE"; then
|
14
|
+
if [ "$(( $(date +"%s") - $(date -r $FILE +%s) ))" -gt "$INTERVAL" ]; then
|
15
|
+
echo "UNHEALTHY. $FILE is older than $INTERVAL seconds."
|
16
|
+
exit 2
|
17
|
+
else
|
18
|
+
echo "HEALTHY"
|
19
|
+
exit 0
|
20
|
+
fi
|
21
|
+
else
|
22
|
+
echo "$FILE does not exist"
|
23
|
+
exit 1
|
24
|
+
fi
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
unless defined?(Resque::Scheduler)
|
2
|
+
raise ResqueNotLoadedError, "[resque-kubernetes-probes] resque-scheduler is not loaded. " \
|
3
|
+
"Make sure the resque-scheduler gem is loaded before `resque-kubernetes-probes` in your Gemfile"
|
4
|
+
end
|
5
|
+
|
6
|
+
module Resque
|
7
|
+
module Scheduler
|
8
|
+
class << self
|
9
|
+
alias original_poll_sleep poll_sleep
|
10
|
+
|
11
|
+
def poll_sleep
|
12
|
+
FileUtils.touch(File.join(Rails.root, "tmp", "resque_scheduler_health"))
|
13
|
+
|
14
|
+
original_poll_sleep
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class ResqueNotLoadedError < StandardError; end
|
2
|
+
|
3
|
+
unless defined?(Resque)
|
4
|
+
raise ResqueNotLoadedError, "[resque-kubernetes-probes] resque is not loaded. " \
|
5
|
+
"Make sure the resque gem is loaded before `resque-kubernetes-probes` in your Gemfile"
|
6
|
+
end
|
7
|
+
|
8
|
+
module Resque
|
9
|
+
class Worker
|
10
|
+
alias original_heartbeat! heartbeat!
|
11
|
+
|
12
|
+
def heartbeat!
|
13
|
+
FileUtils.touch(File.join(Rails.root, "tmp", "resque_health"))
|
14
|
+
|
15
|
+
original_heartbeat!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/resque/kubernetes/probes/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "resque-kubernetes-probes"
|
5
|
+
spec.version = Resque::Kubernetes::Probes::VERSION
|
6
|
+
spec.authors = ["Micke Lisinge"]
|
7
|
+
spec.email = ["hi@micke.me"]
|
8
|
+
|
9
|
+
spec.summary = %q{Kubernetes probes for resque}
|
10
|
+
spec.description = %q{Kubernetes probes for resque}
|
11
|
+
spec.homepage = "https://github.com/apoex/resque-kubernetes-probes"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/apoex/resque-kubernetes-probes"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/apoex/resque-kubernetes-probes"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resque-kubernetes-probes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micke Lisinge
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Kubernetes probes for resque
|
14
|
+
email:
|
15
|
+
- hi@micke.me
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/resque_health_check
|
30
|
+
- bin/setup
|
31
|
+
- lib/resque/kubernetes/probes.rb
|
32
|
+
- lib/resque/kubernetes/probes/resque-scheduler.rb
|
33
|
+
- lib/resque/kubernetes/probes/resque.rb
|
34
|
+
- lib/resque/kubernetes/probes/version.rb
|
35
|
+
- resque-kubernetes-probes.gemspec
|
36
|
+
homepage: https://github.com/apoex/resque-kubernetes-probes
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://github.com/apoex/resque-kubernetes-probes
|
41
|
+
source_code_uri: https://github.com/apoex/resque-kubernetes-probes
|
42
|
+
changelog_uri: https://github.com/apoex/resque-kubernetes-probes
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 2.3.0
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.0.3
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Kubernetes probes for resque
|
62
|
+
test_files: []
|