mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(maint) Fix Divide by 0 Bug
When a redis key does not exist for a single-day summary, the total_clones_per_day array has a length of 1 with a single value of 0. This gets past an initial check of array length, but is then reduced to a value of 0, which is then used as the denominator of an average calculation. The result of this calculation is NaN and later causes JSON.pretty_generate to raise an exception. This also includes a check on the min_max_clone_times array, because [].minmax returns [nil, nil].
This commit is contained in:
parent
b044ea6c8e
commit
67ee061776
1 changed files with 8 additions and 2 deletions
|
|
@ -345,8 +345,14 @@ module Vmpooler
|
||||||
result[:clone][:duration][:total] = total_clone_dur_day.reduce(:+).to_f
|
result[:clone][:duration][:total] = total_clone_dur_day.reduce(:+).to_f
|
||||||
|
|
||||||
# averages and other things.
|
# averages and other things.
|
||||||
|
if result[:clone][:count][:total] != 0
|
||||||
result[:clone][:duration][:average] = result[:clone][:duration][:total] / result[:clone][:count][:total]
|
result[:clone][:duration][:average] = result[:clone][:duration][:total] / result[:clone][:count][:total]
|
||||||
|
end
|
||||||
|
|
||||||
|
if min_max_clone_times.length > 0
|
||||||
result[:clone][:duration][:min], result[:clone][:duration][:max] = min_max_clone_times.minmax
|
result[:clone][:duration][:min], result[:clone][:duration][:max] = min_max_clone_times.minmax
|
||||||
|
end
|
||||||
|
|
||||||
result[:clone][:count][:min], result[:clone][:count][:max] = total_clones_per_day.minmax
|
result[:clone][:count][:min], result[:clone][:count][:max] = total_clones_per_day.minmax
|
||||||
result[:clone][:count][:average] = mean(total_clones_per_day)
|
result[:clone][:count][:average] = mean(total_clones_per_day)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue