[metrics-bugs] #24532 [Metrics/Statistics]: Make metrics-web runs independent of server locale

Tor Bug Tracker & Wiki blackhole at torproject.org
Mon Jan 13 11:08:03 UTC 2020

#24532: Make metrics-web runs independent of server locale
 Reporter:  iwakeh              |          Owner:  metrics-team
     Type:  defect              |         Status:  needs_review
 Priority:  Medium              |      Milestone:
Component:  Metrics/Statistics  |        Version:
 Severity:  Normal              |     Resolution:
 Keywords:                      |  Actual Points:
Parent ID:                      |         Points:
 Reviewer:  irl                 |        Sponsor:
Changes (by karsten):

 * cc: metrics-team (added)
 * reviewer:   => irl
 * status:  new => needs_review
 * component:  Metrics/Website => Metrics/Statistics


 This is as simple as setting the default locale for the instance of the
 JVM at the beginning of the `main` method. For metrics-web that's the
 patch below:

 diff --git a/src/main/java/org/torproject/metrics/stats/main/Main.java
 index 4ea15b46..3a4baf75 100644
 --- a/src/main/java/org/torproject/metrics/stats/main/Main.java
 +++ b/src/main/java/org/torproject/metrics/stats/main/Main.java
 @@ -8,10 +8,11 @@ import java.io.IOException;
  import java.lang.reflect.InvocationTargetException;
  import java.nio.file.Files;
  import java.nio.file.StandardCopyOption;
  import java.util.ArrayList;
  import java.util.List;
 +import java.util.Locale;

  public class Main {

    private static final Logger log = LoggerFactory.getLogger(Main.class);

 @@ -27,10 +28,12 @@ public class Main {
    /** Start the metrics update run. */
    public static void main(String[] args) {

      log.info("Starting metrics update run.");

 +    Locale.setDefault(Locale.US);
      File[] outputDirs = new File[] { modulesDir, statsDir };
      for (File outputDir : outputDirs) {
        if (outputDir.exists()) {

 That `main` method invokes all the other `main` methods of data-processing
 modules. But setting the locale in this first `main` method is sufficient
 for all subsequent module runs in the same JVM.

 I tested this line in a throw-away EC2 instance, and it worked just fine.

 If this fix looks good, we should apply the same fix to all other `main`
 methods of our various code bases:


 In case of Onionoo we can then simplify all `String.format` invocations
 containing a locale, like `String.format(Locale.US, "%.12f",
 weights[i]));`. It will be sufficient to specify the locale once at the
 beginning of the execution. Doesn't hurt to keep it there, but having less
 code wouldn't hurt, either.

Ticket URL: <https://trac.torproject.org/projects/tor/ticket/24532#comment:2>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online

More information about the metrics-bugs mailing list