[tor-commits] [sbws/master] new: v3bwfile: Set relays exclusion KeyValues

juga at torproject.org juga at torproject.org
Thu Mar 21 18:30:42 UTC 2019


commit f5e611c2972896f6e43c83bef3b36064f86a910e
Author: juga0 <juga at riseup.net>
Date:   Tue Mar 12 10:53:08 2019 +0000

    new: v3bwfile: Set relays exclusion KeyValues
    
    Part of #28565.
---
 sbws/lib/v3bwfile.py            | 23 +++++++++++++++++++++++
 tests/unit/lib/test_v3bwfile.py | 14 ++++++--------
 2 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index cb6d29c..e6dcde1 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -453,6 +453,15 @@ class V3BWHeader(object):
         [setattr(self, k, str(v)) for k, v in kwargs.items()
          if k in STATS_KEYVALUES]
 
+    def add_relays_excluded_counters(self, exclusion_dict):
+        """
+        Add the monitoring KeyValues to the header about the number of
+        relays not included because they were not ``eligible``.
+        """
+        log.debug("Adding relays excluded counters.")
+        for k, v in exclusion_dict.items():
+            setattr(self, k, str(v))
+
 
 class V3BWLine(object):
     """
@@ -798,12 +807,26 @@ class V3BWFile(object):
         number_consensus_relays = cls.read_number_consensus_relays(
             consensus_path)
         state = State(state_fpath)
+
+        # Create a dictionary with the number of relays excluded by any of the
+        # of the filtering rules that makes relays non-`eligible`.
+        # NOTE: In BW_HEADER_KEYVALUES_RECENT_MEASUREMENTS_EXCLUDED it is
+        # explained what are the KeyValues.
+        # See also the comments in `from_results`.
+        exclusion_dict = dict(
+            [(k, 0) for k in BW_HEADER_KEYVALUES_RECENT_MEASUREMENTS_EXCLUDED]
+            )
         for fp, values in results.items():
             # log.debug("Relay fp %s", fp)
             line, reason = V3BWLine.from_results(values, secs_recent,
                                                  secs_away, min_num)
             if line is not None:
                 bw_lines_raw.append(line)
+            else:
+                exclusion_dict[reason] = exclusion_dict.get(reason, 0) + 1
+        # Add the headers with the number of excluded relays by reason
+        header.add_relays_excluded_counters(exclusion_dict)
+
         if not bw_lines_raw:
             log.info("After applying restrictions to the raw results, "
                      "there is not any. Scaling can not be applied.")
diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index da7b456..41b7e9d 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -61,9 +61,7 @@ raw_bwl_str = "bw=56 bw_mean=61423 bw_median=55656 "\
     "nick=A " \
     "node_id=$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "\
     "relay_recent_measurement_attempt_count=2 "\
-    "relay_recent_measurement_exclusion_not_distanciated_count=0 "\
-    "relay_recent_measurement_exclusion_not_recent_count=0 "\
-    "relay_recent_measurement_exclusion_not_success_count=1 "\
+    "relay_recent_measurements_excluded_error_count=1 "\
     "relay_recent_priority_list_count=3 "\
     "rtt=456 success=1 " \
     "time=2018-04-17T14:09:07\n"
@@ -315,7 +313,7 @@ def test_results_away_each_other(datadir):
 
     # There is one result excluded, but the relay is not excluded
     bwl, reason = V3BWLine.from_results(values, secs_away=secs_away, min_num=2)
-    assert bwl.relay_recent_measurement_exclusion_error_count == 1
+    assert bwl.relay_recent_measurements_excluded_error_count == 1
     assert reason is None
 
     success_results = [r for r in values if isinstance(r, ResultSuccess)]
@@ -330,8 +328,8 @@ def test_results_away_each_other(datadir):
     # the relay is excluded
     bwl, reason = V3BWLine.from_results(values, secs_away=secs_away, min_num=2)
     # TODO ticket28563: uncomment
-    # assert bwl.relay_recent_measurement_exclusion_near_count == 2
-    assert reason == 'recent_measurement_exclusion_near_count'
+    # assert bwl.relay_recent_measurements_excluded_near_count == 2
+    assert reason == 'recent_measurements_excluded_near_count'
 
     success_results = [r for r in values if isinstance(r, ResultSuccess)]
     assert len(success_results) >= min_num
@@ -349,8 +347,8 @@ def test_results_away_each_other(datadir):
     # There is only 1 result, the relay is excluded
     bwl, reason = V3BWLine.from_results(values, min_num=2)
     # TODO ticket28563: uncomment
-    # assert bwl.recent_measurement_exclusion_few_count == 1
-    assert reason == 'recent_measurement_exclusion_few_count'
+    # assert bwl.recent_measurements_excluded_few_count == 1
+    assert reason == 'recent_measurements_excluded_few_count'
 
     success_results = [r for r in values if isinstance(r, ResultSuccess)]
     assert len(success_results) < min_num





More information about the tor-commits mailing list