-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add failed resque jobs data for zabbix
- Loading branch information
1 parent
9518bfc
commit 64b383d
Showing
10 changed files
with
239 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Resque | ||
module Integration | ||
module FailureBackends | ||
autoload :QueuesTotals, 'resque/integration/failure_backends/queues_totals' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Resque | ||
module Integration | ||
module FailureBackends | ||
class QueuesTotals < ::Resque::Failure::Base | ||
REDIS_COUNTER_KEY = 'resque:integration:failure_backends:queues_totals'.freeze | ||
MAX_COUNTER_VALUE = 10_000_000 | ||
|
||
private_constant :REDIS_COUNTER_KEY | ||
|
||
def save | ||
current_value = Resque.redis.hincrby(REDIS_COUNTER_KEY, queue, 1) | ||
Resque.redis.hset(REDIS_COUNTER_KEY, queue, 1) if current_value >= MAX_COUNTER_VALUE | ||
end | ||
|
||
def self.queues | ||
Resque.redis.hkeys(REDIS_COUNTER_KEY) | ||
end | ||
|
||
def self.count(queue = nil, _class_name = nil) | ||
if queue.nil? | ||
Resque.redis.hvals(REDIS_COUNTER_KEY).map(&:to_i).sum | ||
else | ||
Resque.redis.hget(REDIS_COUNTER_KEY, queue).to_i | ||
end | ||
end | ||
|
||
def self.clear(queue = nil) | ||
if queue.nil? | ||
Resque.redis.del(REDIS_COUNTER_KEY) | ||
else | ||
Resque.redis.hdel(REDIS_COUNTER_KEY, queue) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
defaults: | ||
max_age: 10 | ||
max_size: 10 | ||
max_failures_count_per_5m: 5 | ||
max_failures_count_per_1h: 60 | ||
|
||
queues: | ||
first: | ||
? | ||
> | ||
first, | ||
third | ||
: | ||
max_age: 20 | ||
max_size: 100 | ||
max_failures_count_per_5m: 15 | ||
max_failures_count_per_1h: 90 | ||
|
||
third: | ||
max_age: 30 | ||
max_failures_count_per_1h: 70 |
105 changes: 105 additions & 0 deletions
105
spec/resque/integration/failure_backends/queues_totals_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
require 'spec_helper' | ||
|
||
describe Resque::Integration::FailureBackends::QueuesTotals do | ||
let(:failure) { double('UnbelievableError') } | ||
let(:worker) { double('Worker') } | ||
let(:payload) { double('Payload') } | ||
|
||
describe '#save' do | ||
let(:queue) { 'images' } | ||
let(:backend) { described_class.new(failure, worker, queue, payload) } | ||
|
||
before { stub_const('Resque::Integration::FailureBackends::QueuesTotals::MAX_COUNTER_VALUE', 3) } | ||
|
||
it 'increments failures count for specified queue' do | ||
expect do | ||
2.times { backend.save } | ||
end.to change { described_class.count(queue) }.from(0).to(2) | ||
end | ||
|
||
context 'when counter overflows' do | ||
it 'resets failures count for specified queue to 1' do | ||
expect do | ||
3.times { backend.save } | ||
end.to change { described_class.count(queue) }.from(0).to(1) | ||
end | ||
end | ||
end | ||
|
||
describe '.count' do | ||
let(:images_queue) { 'images' } | ||
let(:products_queue) { 'products' } | ||
let(:images_failure_backend) { described_class.new(failure, worker, images_queue, payload) } | ||
let(:products_failure_backend) { described_class.new(failure, worker, products_queue, payload) } | ||
|
||
before do | ||
2.times { images_failure_backend.save } | ||
3.times { products_failure_backend.save } | ||
end | ||
|
||
context 'with specified queue' do | ||
it 'returns failures count for specified queue' do | ||
expect(described_class.count(images_queue)).to eq(2) | ||
expect(described_class.count(products_queue)).to eq(3) | ||
end | ||
end | ||
|
||
context 'with queue which has no failures' do | ||
it 'returns 0' do | ||
expect(described_class.count('not_failed')).to eq(0) | ||
end | ||
end | ||
|
||
context 'without specified queue' do | ||
it 'returns aggregated failures count from all queues' do | ||
expect(described_class.count).to eq(5) | ||
end | ||
end | ||
end | ||
|
||
describe '.queues' do | ||
context 'when has failures data' do | ||
let(:images_queue) { 'images' } | ||
let(:products_queue) { 'products' } | ||
|
||
before do | ||
described_class.new(failure, worker, images_queue, payload).save | ||
described_class.new(failure, worker, products_queue, payload).save | ||
end | ||
|
||
it 'returns names of failed queues' do | ||
expect(described_class.queues).to match_array([images_queue, products_queue]) | ||
end | ||
end | ||
|
||
context 'when does not have failures data' do | ||
it { expect(described_class.queues).to be_empty } | ||
end | ||
end | ||
|
||
describe '.clear' do | ||
let(:images_queue) { 'images' } | ||
let(:products_queue) { 'products' } | ||
|
||
before do | ||
described_class.new(failure, worker, images_queue, payload).save | ||
described_class.new(failure, worker, products_queue, payload).save | ||
end | ||
|
||
context 'with specified queue' do | ||
it 'deletes counter data for specified queue' do | ||
expect { described_class.clear(products_queue) }.to change { described_class.count }.from(2).to(1) | ||
expect(described_class.count(images_queue)).to eq(1) | ||
expect(described_class.count(products_queue)).to eq(0) | ||
end | ||
end | ||
|
||
context 'without specified queue' do | ||
it 'deletes counter data for all queues' do | ||
expect { described_class.clear }.to change { described_class.count }.from(2).to(0) | ||
expect(described_class.count(images_queue)).to eq(0) | ||
expect(described_class.count(products_queue)).to eq(0) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters