[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/master] Support bandwidth histories using longer intervals.



commit 9af6db14c89ad37d74fb57b31c25cc2b54a00376
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Dec 22 14:13:27 2014 +0100

    Support bandwidth histories using longer intervals.
    
    The bandwidth history interval may soon change from 900 seconds to
    something else.  Make sure that this doesn't break statistics.  Related
    to #13838 and 13988.
---
 .../cron/RelayDescriptorDatabaseImporter.java      |   27 +++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/modules/legacy/src/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java b/modules/legacy/src/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java
index b5c55c8..59e6740 100644
--- a/modules/legacy/src/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java
+++ b/modules/legacy/src/org/torproject/ernie/cron/RelayDescriptorDatabaseImporter.java
@@ -630,10 +630,30 @@ public final class RelayDescriptorDatabaseImporter {
             + "Ignoring this line.");
         continue;
       }
-      if (intervalLength != 900L) {
-        this.logger.fine("Bandwidth history line does not consist of "
-            + "15-minute intervals. Ignoring this line.");
+      String[] values = parts[5].split(",");
+      if (intervalLength % 900L != 0L) {
+        this.logger.fine("Bandwidth history line does not contain "
+            + "multiples of 15-minute intervals. Ignoring this line.");
         continue;
+      } else if (intervalLength != 900L) {
+        /* This is a really dirty hack to support bandwidth history
+         * intervals that are longer than 15 minutes by linearly
+         * distributing reported bytes to 15 minute intervals.  The
+         * alternative would have been to modify the database schema. */
+        try {
+          long factor = intervalLength / 900L;
+          String[] newValues = new String[values.length * (int) factor];
+          for (int i = 0; i < newValues.length; i++) {
+            newValues[i] = String.valueOf(
+                Long.parseLong(values[i / (int) factor]) / factor);
+          }
+          values = newValues;
+          intervalLength = 900L;
+        } catch (NumberFormatException e) {
+          this.logger.fine("Number format exception while parsing "
+              + "bandwidth history line. Ignoring this line.");
+          continue;
+        }
       }
       String type = parts[0];
       String intervalEndTime = parts[1] + " " + parts[2];
@@ -657,7 +677,6 @@ public final class RelayDescriptorDatabaseImporter {
       }
       long currentIntervalEnd = intervalEnd;
       StringBuilder sb = new StringBuilder();
-      String[] values = parts[5].split(",");
       SortedSet<String> newHistoryLines = new TreeSet<String>();
       try {
         for (int i = values.length - 1; i >= -1; i--) {

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits