Skip to content

Commit

Permalink
feat: warning levels support in queues monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
c1n1c committed Oct 31, 2017
1 parent 71e6c53 commit 6d011ea
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
28 changes: 26 additions & 2 deletions lib/resque/integration/queues_info/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,52 @@ def max_age(queue)
threshold(queue, 'max_age')
end

def warn_age(queue)
threshold(queue, 'warn_age')
end

def max_size(queue)
threshold(queue, 'max_size')
end

def warn_size(queue)
threshold(queue, 'warn_size')
end

def max_failures_count(queue, period)
threshold(queue, "max_failures_count_per_#{period}")
end

def warn_failures_count(queue, period)
threshold(queue, "warn_failures_count_per_#{period}")
end

def channel(queue)
channel = @queues[queue].try(:[], 'channel') || @defaults['channel']
channel = threshold(queue, 'channel')
Array.wrap(channel).join(' ')
end

def warn_channel(queue)
channel = threshold(queue, 'warn_channel')
Array.wrap(channel).join(' ')
end

def data
@data ||= @queues.map do |queue_name, _queue_params|
{
'{#QUEUE}' => queue_name,

'{#CHANNEL}' => channel(queue_name),
'{#THRESHOLD_AGE}' => max_age(queue_name),
'{#THRESHOLD_SIZE}' => max_size(queue_name),
'{#THRESHOLD_FAILURES_PER_5M}' => max_failures_count(queue_name, '5m'),
'{#THRESHOLD_FAILURES_PER_1H}' => max_failures_count(queue_name, '1h'),
'{#CHANNEL}' => channel(queue_name)

'{#WARNING_CHANNEL}' => warn_channel(queue_name),
'{#WARNING_AGE}' => warn_age(queue_name),
'{#WARNING_SIZE}' => warn_size(queue_name),
'{#WARNING_FAILURES_PER_5M}' => warn_failures_count(queue_name, '5m'),
'{#WARNING_FAILURES_PER_1H}' => warn_failures_count(queue_name, '1h')
}
end
end
Expand Down
19 changes: 18 additions & 1 deletion spec/fixtures/resque_queues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,41 @@ defaults:
max_failures_count_per_1h: 60
channel: default

warn_age: 8
warn_size: 7
warn_failures_count_per_5m: 3
warn_failures_count_per_1h: 30
warn_channel: default_warnings

queues:
?
>
first,
third
:
max_age: 20
warn_age: 10

max_size: 100
warn_size: 50

max_failures_count_per_5m: 15
warn_failures_count_per_5m: 7

max_failures_count_per_1h: 90
warn_failures_count_per_1h: 45

channel: first
warn_channel: first_warnings

third:
max_age: 30
warn_age: 15
max_failures_count_per_1h: 70
warn_failures_count_per_1h: 35

second_queue:
channel: [first, second]
warn_channel: [first_warnings, second_warnings]

without_channel: {}

36 changes: 32 additions & 4 deletions spec/resque/integration/queues_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,35 +338,63 @@
expect(queue_info.data).to eq [
{
'{#QUEUE}' => 'first',

'{#CHANNEL}' => 'first',
'{#THRESHOLD_AGE}' => 20,
'{#THRESHOLD_SIZE}' => 100,
'{#THRESHOLD_FAILURES_PER_5M}' => 15,
'{#THRESHOLD_FAILURES_PER_1H}' => 90,
'{#CHANNEL}' => 'first'

'{#WARNING_CHANNEL}' => 'first_warnings',
'{#WARNING_AGE}' => 10,
'{#WARNING_SIZE}' => 50,
'{#WARNING_FAILURES_PER_5M}' => 7,
'{#WARNING_FAILURES_PER_1H}' => 45
},
{
'{#QUEUE}' => 'third',

'{#CHANNEL}' => 'first',
'{#THRESHOLD_AGE}' => 30,
'{#THRESHOLD_SIZE}' => 100,
'{#THRESHOLD_FAILURES_PER_5M}' => 15,
'{#THRESHOLD_FAILURES_PER_1H}' => 70,
'{#CHANNEL}' => 'first'

'{#WARNING_CHANNEL}' => 'first_warnings',
'{#WARNING_AGE}' => 15,
'{#WARNING_SIZE}' => 50,
'{#WARNING_FAILURES_PER_5M}' => 7,
'{#WARNING_FAILURES_PER_1H}' => 35
},
{
'{#QUEUE}' => 'second_queue',

'{#CHANNEL}' => 'first second',
'{#THRESHOLD_AGE}' => 10,
'{#THRESHOLD_SIZE}' => 10,
'{#THRESHOLD_FAILURES_PER_5M}' => 5,
'{#THRESHOLD_FAILURES_PER_1H}' => 60,
'{#CHANNEL}' => 'first second'

'{#WARNING_CHANNEL}' => 'first_warnings second_warnings',
'{#WARNING_AGE}' => 8,
'{#WARNING_SIZE}' => 7,
'{#WARNING_FAILURES_PER_5M}' => 3,
'{#WARNING_FAILURES_PER_1H}' => 30
},
{
'{#QUEUE}' => 'without_channel',

'{#CHANNEL}' => 'default',
'{#THRESHOLD_AGE}' => 10,
'{#THRESHOLD_SIZE}' => 10,
'{#THRESHOLD_FAILURES_PER_5M}' => 5,
'{#THRESHOLD_FAILURES_PER_1H}' => 60,
'{#CHANNEL}' => 'default'

'{#WARNING_CHANNEL}' => 'default_warnings',
'{#WARNING_AGE}' => 8,
'{#WARNING_SIZE}' => 7,
'{#WARNING_FAILURES_PER_5M}' => 3,
'{#WARNING_FAILURES_PER_1H}' => 30
}
]
end
Expand Down

0 comments on commit 6d011ea

Please sign in to comment.