commit 2b90d656d1b6c27f1e9f1d05a4cf747afec26353
Author: Karsten Loesing <karsten.loesing(a)gmx.net>
Date: Wed Apr 1 12:45:07 2020 +0200
Set default locale US and default time zone UTC.
Part of #33655.
---
CHANGELOG.md | 2 ++
src/build | 2 +-
src/main/java/org/torproject/metrics/collector/Main.java | 4 ++++
.../collector/bridgedescs/SanitizedBridgesWriter.java | 4 ----
.../metrics/collector/exitlists/ExitListDownloader.java | 7 ++-----
.../metrics/collector/onionperf/OnionPerfDownloader.java | 2 --
.../metrics/collector/persist/PersistenceUtils.java | 3 ---
.../metrics/collector/relaydescs/ArchiveReader.java | 2 --
.../metrics/collector/relaydescs/ArchiveWriter.java | 14 --------------
.../collector/relaydescs/CachedRelayDescriptorReader.java | 2 --
.../metrics/collector/relaydescs/ReferenceChecker.java | 6 +-----
.../collector/relaydescs/RelayDescriptorDownloader.java | 3 ---
.../collector/relaydescs/RelayDescriptorParser.java | 3 ---
13 files changed, 10 insertions(+), 44 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c284d47..fa9bb16 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
* Minor changes
- Simplify logging configuration.
+ - Set default locale `US` and default time zone `UTC` at the
+ beginning of the execution.
# Changes in version 1.14.1 - 2020-01-16
diff --git a/src/build b/src/build
index fd85646..b5e1a2d 160000
--- a/src/build
+++ b/src/build
@@ -1 +1 @@
-Subproject commit fd856466bcb260f53ef69a24c102d0e49d171cc3
+Subproject commit b5e1a2d7b29e58cc0645f068a1ebf4377bf9d8b8
diff --git a/src/main/java/org/torproject/metrics/collector/Main.java b/src/main/java/org/torproject/metrics/collector/Main.java
index 3e8ec33..9a04c6e 100644
--- a/src/main/java/org/torproject/metrics/collector/Main.java
+++ b/src/main/java/org/torproject/metrics/collector/Main.java
@@ -28,7 +28,9 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
+import java.util.TimeZone;
/**
* Main class for starting a CollecTor instance.
@@ -71,6 +73,8 @@ public class Main {
* See class description {@link Main}.
*/
public static void main(String[] args) {
+ Locale.setDefault(Locale.US);
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
try {
Path confPath;
if (args == null || args.length == 0) {
diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
index 6aee057..c4f783a 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -43,7 +43,6 @@ import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.TreeMap;
/**
@@ -139,7 +138,6 @@ public class SanitizedBridgesWriter extends CollecTorMain {
config.getBool(Key.ReplaceIpAddressesWithHashes);
SimpleDateFormat rsyncCatFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH-mm-ss");
- rsyncCatFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
this.rsyncCatString = rsyncCatFormat.format(
System.currentTimeMillis());
@@ -604,7 +602,6 @@ public class SanitizedBridgesWriter extends CollecTorMain {
* whether this status is possibly stale. */
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
- formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
if (null == mostRecentDescPublished) {
logger.warn("The bridge network status published at {}"
+ " does not contain a single entry. Please ask the bridge "
@@ -1355,7 +1352,6 @@ public class SanitizedBridgesWriter extends CollecTorMain {
private void checkStaleDescriptors() {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
long tooOldMillis = System.currentTimeMillis() - 330L * 60L * 1000L;
try {
long maxNetworkStatusPublishedMillis =
diff --git a/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java b/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
index 49e176b..c6b45da 100644
--- a/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
@@ -28,7 +28,6 @@ import java.util.Arrays;
import java.util.Date;
import java.util.SortedSet;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.TreeSet;
public class ExitListDownloader extends CollecTorMain {
@@ -61,9 +60,6 @@ public class ExitListDownloader extends CollecTorMain {
@Override
protected void startProcessing() throws ConfigurationException {
- SimpleDateFormat dateTimeFormat =
- new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
outputPathName = Paths.get(config.getPath(Key.OutputPath).toString(),
EXITLISTS).toString();
recentPathName = Paths.get(config.getPath(Key.RecentPath).toString(),
@@ -73,6 +69,8 @@ public class ExitListDownloader extends CollecTorMain {
logger.debug("Downloading exit list...");
StringBuilder sb = new StringBuilder();
sb.append(Annotation.ExitList.toString());
+ SimpleDateFormat dateTimeFormat =
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sb.append("Downloaded ").append(dateTimeFormat.format(downloadedDate))
.append("\n");
URL url = config.getUrl(Key.ExitlistUrl);
@@ -94,7 +92,6 @@ public class ExitListDownloader extends CollecTorMain {
SimpleDateFormat tarballFormat =
new SimpleDateFormat("yyyy/MM/dd/yyyy-MM-dd-HH-mm-ss");
- tarballFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(outputPathName,
tarballFormat.format(downloadedDate)).toFile();
diff --git a/src/main/java/org/torproject/metrics/collector/onionperf/OnionPerfDownloader.java b/src/main/java/org/torproject/metrics/collector/onionperf/OnionPerfDownloader.java
index dc1a675..b651620 100644
--- a/src/main/java/org/torproject/metrics/collector/onionperf/OnionPerfDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/onionperf/OnionPerfDownloader.java
@@ -35,7 +35,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.SortedSet;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -156,7 +155,6 @@ public class OnionPerfDownloader extends CollecTorMain {
static {
DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
DATE_FORMAT.setLenient(false);
- DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
}
private void downloadAndParseOnionPerfTpfFile(URL baseUrl, String source,
diff --git a/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java b/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java
index da1403c..c958aec 100644
--- a/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java
+++ b/src/main/java/org/torproject/metrics/collector/persist/PersistenceUtils.java
@@ -19,7 +19,6 @@ import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.TimeZone;
public class PersistenceUtils {
@@ -118,7 +117,6 @@ public class PersistenceUtils {
/** Return all date-time parts as array. */
public static String[] dateTimeParts(Date dateTime) {
SimpleDateFormat printFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
- printFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return printFormat.format(dateTime).split("-");
}
@@ -130,7 +128,6 @@ public class PersistenceUtils {
/** Return all date-time as string. */
public static String dateTime(Date dateTime) {
SimpleDateFormat printFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
- printFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return printFormat.format(dateTime);
}
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
index 5a80058..83ef2ea 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
@@ -31,7 +31,6 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.TreeSet;
/**
@@ -201,7 +200,6 @@ public class ArchiveReader {
}
SimpleDateFormat parseFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- parseFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String ascii = new String(allData, StandardCharsets.US_ASCII);
int start;
int end = -1;
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
index e0e1623..8addd5e 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
@@ -47,7 +47,6 @@ import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -146,7 +145,6 @@ public class ArchiveWriter extends CollecTorMain {
RELAY_DESCRIPTORS).toString();
SimpleDateFormat rsyncCatFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH-mm-ss");
- rsyncCatFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
this.rsyncCatString = rsyncCatFormat.format(
System.currentTimeMillis());
this.descriptorParser =
@@ -225,7 +223,6 @@ public class ArchiveWriter extends CollecTorMain {
private void loadDescriptorDigests() {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
if (this.storedServerDescriptorsFile.exists()) {
BufferedReader br = new BufferedReader(new FileReader(
@@ -339,7 +336,6 @@ public class ArchiveWriter extends CollecTorMain {
+ "descriptors:");
SimpleDateFormat dateTimeFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Map<String, String> knownServerDescriptors = new HashMap<>();
for (Map<String, String> descriptors :
this.storedServerDescriptors.values()) {
@@ -513,7 +509,6 @@ public class ArchiveWriter extends CollecTorMain {
private void checkStaledescriptors() {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
long tooOldMillis = this.now - 330L * 60L * 1000L;
if (!this.storedConsensuses.isEmpty()
&& this.storedConsensuses.lastKey() < tooOldMillis) {
@@ -604,7 +599,6 @@ public class ArchiveWriter extends CollecTorMain {
private void saveDescriptorDigests() {
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
if (!this.storedServerDescriptorsFile.getParentFile().exists()
&& !this.storedServerDescriptorsFile.getParentFile().mkdirs()) {
@@ -671,7 +665,6 @@ public class ArchiveWriter extends CollecTorMain {
SortedSet<String> serverDescriptorDigests) {
SimpleDateFormat printFormat = new SimpleDateFormat(
"yyyy/MM/dd/yyyy-MM-dd-HH-mm-ss");
- printFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory, "consensus",
printFormat.format(new Date(validAfter)) + "-consensus").toFile();
boolean tarballFileExistedBefore = tarballFile.exists();
@@ -694,10 +687,8 @@ public class ArchiveWriter extends CollecTorMain {
SortedSet<String> microdescriptorDigests) {
SimpleDateFormat yearMonthDirectoryFormat = new SimpleDateFormat(
"yyyy/MM");
- yearMonthDirectoryFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
SimpleDateFormat dayDirectoryFileFormat = new SimpleDateFormat(
"dd/yyyy-MM-dd-HH-mm-ss");
- dayDirectoryFileFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory, MICRODESC,
yearMonthDirectoryFormat.format(validAfter), CONSENSUS_MICRODESC,
dayDirectoryFileFormat.format(validAfter)
@@ -724,7 +715,6 @@ public class ArchiveWriter extends CollecTorMain {
SortedSet<String> serverDescriptorDigests) {
SimpleDateFormat printFormat = new SimpleDateFormat(
"yyyy/MM/dd/yyyy-MM-dd-HH-mm-ss");
- printFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory, "vote",
printFormat.format(new Date(validAfter)) + "-vote-"
+ fingerprint + "-" + digest).toFile();
@@ -778,7 +768,6 @@ public class ArchiveWriter extends CollecTorMain {
long published) {
SimpleDateFormat printFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH-mm-ss");
- printFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory, "certs",
fingerprint + "-" + printFormat.format(new Date(published))).toFile();
File[] outputFiles = new File[] { tarballFile };
@@ -792,7 +781,6 @@ public class ArchiveWriter extends CollecTorMain {
public void storeServerDescriptor(byte[] data, String digest,
long published, String extraInfoDigest) {
SimpleDateFormat printFormat = new SimpleDateFormat("yyyy/MM/");
- printFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory,
"server-descriptor", printFormat.format(new Date(published)),
digest.substring(0, 1), digest.substring(1, 2), digest).toFile();
@@ -818,7 +806,6 @@ public class ArchiveWriter extends CollecTorMain {
public void storeExtraInfoDescriptor(byte[] data,
String extraInfoDigest, long published) {
SimpleDateFormat descriptorFormat = new SimpleDateFormat("yyyy/MM/");
- descriptorFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory, "extra-info",
descriptorFormat.format(new Date(published)),
extraInfoDigest.substring(0, 1),
@@ -850,7 +837,6 @@ public class ArchiveWriter extends CollecTorMain {
* called twice to store the same microdescriptor in two different
* valid-after months. */
SimpleDateFormat descriptorFormat = new SimpleDateFormat("yyyy/MM/");
- descriptorFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
File tarballFile = Paths.get(this.outputDirectory, MICRODESC,
descriptorFormat.format(validAfter), MICRO,
microdescriptorDigest.substring(0, 1),
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
index 21a3041..0c0ccab 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
@@ -26,7 +26,6 @@ import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
-import java.util.TimeZone;
import java.util.TreeSet;
/**
@@ -139,7 +138,6 @@ public class CachedRelayDescriptorReader {
.append(line.substring("valid-after ".length()));
SimpleDateFormat dateTimeFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
if (dateTimeFormat.parse(line.substring("valid-after "
.length())).getTime() < System.currentTimeMillis()
- 6L * 60L * 60L * 1000L) {
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java
index 5ff77e7..4cc03eb 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ReferenceChecker.java
@@ -28,10 +28,8 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashSet;
-import java.util.Locale;
import java.util.Set;
import java.util.SortedSet;
-import java.util.TimeZone;
import java.util.TreeSet;
public class ReferenceChecker {
@@ -56,10 +54,8 @@ public class ReferenceChecker {
private static DateFormat dateTimeFormat;
static {
- dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",
- Locale.US);
+ dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
dateTimeFormat.setLenient(false);
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
private static final long ONE_HOUR = 60L * 60L * 1000L;
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
index b0fcebb..7155caa 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
@@ -29,7 +29,6 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
-import java.util.TimeZone;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -327,7 +326,6 @@ public class RelayDescriptorDownloader {
* list and the list of authorities to download all server and
* extra-info descriptors from. */
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- format.setTimeZone(TimeZone.getTimeZone("UTC"));
long now = System.currentTimeMillis();
this.currentValidAfter = format.format((now / (60L * 60L * 1000L))
* (60L * 60L * 1000L));
@@ -924,7 +922,6 @@ public class RelayDescriptorDownloader {
* pretty badly. */
SimpleDateFormat parseFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- parseFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String ascii = new String(allData, StandardCharsets.US_ASCII);
int start;
int end = -1;
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
index 3905458..53f205a 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
@@ -21,7 +21,6 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.util.SortedSet;
-import java.util.TimeZone;
import java.util.TreeSet;
/**
@@ -61,7 +60,6 @@ public class RelayDescriptorParser {
this.aw = aw;
this.dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- this.dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public void setRelayDescriptorDownloader(
@@ -96,7 +94,6 @@ public class RelayDescriptorParser {
}
SimpleDateFormat parseFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- parseFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
if (line.startsWith("network-status-version 3")) {
String statusType = "consensus";
if (line.equals("network-status-version 3 microdesc")) {