commit 2abbad4fa5368a0d85e8425d812d783286d81d1d Author: juga0 juga@riseup.net Date: Sat Oct 27 15:26:16 2018 +0000
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 --- CHANGELOG.md | 6 ++++-- sbws/globals.py | 3 +++ sbws/lib/v3bwfile.py | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md index 484742b..1bba713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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
diff --git a/sbws/globals.py b/sbws/globals.py index 7159f7b..66effd5 100644 --- a/sbws/globals.py +++ b/sbws/globals.py @@ -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
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py index c35c865..4b851d0 100644 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@ -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
@@ -588,6 +591,21 @@ class V3BWFile(object): '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, num_round_dig=TORFLOW_ROUND_DIG, reverse=False):
tor-commits@lists.torproject.org