Commit 2abbad4f authored by juga  's avatar juga
Browse files

Compare consensus bandwidth with lines

When the difference between the total consensus bandwidth and the
total in the bandwidth lines is larger than 50%, warn
parent ed1d61c9
......@@ -24,11 +24,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Write bw file only when the percentage of measured relays is bigger than 60%
(#28062)
- When the percentage of measured relays is less than the 60%, do not include
the relays in the bandwidth file and instead include some statistics in the
- When the percentage of measured relays is less than the 60%, do not include
the relays in the bandwidth file and instead include some statistics in the
header (#28076)
- When the percentage of measured relays is less than the 60% and it was more
before, warn about it (#28155)
- When the difference between the total consensus bandwidth and the total
in the bandwidth lines is larger than 50%, warn (#28216)
## [0.8.0] - 2018-10-08
......
......@@ -41,6 +41,9 @@ TORFLOW_ROUND_DIG = 3
DAY_SECS = 86400
NUM_MIN_RESULTS = 2
MIN_REPORT = 60
# Maximum difference between the total consensus bandwidth and the total in
# in the bandwidth lines in percentage
MAX_BW_DIFF_PERC = 50
BW_LINE_SIZE = 510
......
......@@ -13,7 +13,7 @@ from sbws import __version__
from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT,
TORFLOW_SCALING, SBWS_SCALING, TORFLOW_BW_MARGIN,
TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN,
TORFLOW_ROUND_DIG, MIN_REPORT)
TORFLOW_ROUND_DIG, MIN_REPORT, MAX_BW_DIFF_PERC)
from sbws.lib.resultdump import ResultSuccess, _ResultType
from sbws.util.filelock import DirectoryLock
from sbws.util.timestamp import (now_isodt_str, unixts_to_isodt_str,
......@@ -460,7 +460,8 @@ class V3BWFile(object):
torflow_cap=TORFLOW_BW_MARGIN,
torflow_round_digs=TORFLOW_ROUND_DIG,
secs_recent=None, secs_away=None, min_num=0,
consensus_path=None, reverse=False):
consensus_path=None, max_bw_diff_perc=MAX_BW_DIFF_PERC,
reverse=False):
"""Create V3BWFile class from sbws Results.
:param dict results: see below
......@@ -509,6 +510,8 @@ class V3BWFile(object):
else:
bw_lines = cls.bw_kb(bw_lines_raw)
# log.debug(bw_lines[-1])
# Not using the result for now, just warning
cls.is_max_bw_diff_perc_reached(bw_lines, max_bw_diff_perc)
f = cls(header, bw_lines)
return f
......@@ -587,6 +590,21 @@ class V3BWFile(object):
log.warning('There was %f%% error and only +/- %f%% is '
'allowed', (1 - accuracy_ratio) * 100, margin * 100)
@staticmethod
def is_max_bw_diff_perc_reachede(bw_lines, max_bw_diff_perc,
MAX_BW_DIFF_PERC):
sum_consensus_bw = sum([l.desc_obs_bw_bs_last for l in bw_lines])
sum_bw = sum([l.bw for l in bw_lines])
diff = min(sum_consensus_bw, sum_bw) / max(sum_consensus_bw, sum_bw)
diff_perc = diff * 100
log.info("The difference between the total consensus bandwidth "
"and the total measured bandwidth is %s%% percent",
diff_perc)
if diff_perc > MAX_BW_DIFF_PERC:
log.warning("It is more than %s%%", max_bw_diff_perc)
return True
return False
@staticmethod
def bw_torflow_scale(bw_lines, desc_obs_bws=TORFLOW_OBS_MEAN,
cap=TORFLOW_BW_MARGIN,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment