Fix QoS division by 0 55/246255/3
authorMateusz Majewski <m.majewski2@samsung.com>
Tue, 27 Oct 2020 08:57:13 +0000 (09:57 +0100)
committerMichal Bloch <m.bloch@partner.samsung.com>
Tue, 27 Oct 2020 14:45:02 +0000 (14:45 +0000)
commita22cb2fc1f7524fee441824fcaf6a3048e8688d9
tree3e3b98e02d45a03d7c9979beea6fbd8b52ff568f
parent9311a2af5505de62b114fb9ba0c0e4c00c41b039
Fix QoS division by 0

While the count_above_threshold does have a check for 0, it doesn't do
what we want; we want it to return an infinite value somehow, but it
instead returns the dividend. This patch checks for this case and
returns the correct value manually.

The reason why it is important to return infinite value in this case is
that this division is supposed to always increase the threshold value.
Usually it does that correctly, since remaining_throughput has been
decreased by only those values that were under the average value, and
count_above_threshold has been decreased by count of those values.
Therefore, the result of the division is the average of all the values
that weren't lower than the previous average, and this average obviously
can't be lower than the previous average. However, if all the values are
under the average, the new average doesn't exist. It's morally infinite,
but the division instead returns the remaining_throughput, which is
obviously much lower than the original throughput, and often lower than
the threshold value. For example, if throughput is 20 and we have one
log source having written 18 logs, the result will be 2, which is wrong.

Change-Id: Id6d085707aeabc4032f931869c213f01db2c927a
src/logger/qos_distributions.c