summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@oath.com>2019-02-27 13:15:36 +0100
committerOla Aunrønning <olaa@oath.com>2019-02-27 13:15:36 +0100
commitfaa41485359fdd7170ad695a5990eff11cc07458 (patch)
tree73b708cfbb3b1ceba25920d25897bf4c944b8bd5 /container-core
parentf87646cafcd43d6a20b41591ca62845a07a25ba2 (diff)
Add some leniency to latestLogThreshold
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/LogReader.java6
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java3
2 files changed, 5 insertions, 4 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
index 76ea4579244..c6ae20973fb 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
@@ -4,11 +4,11 @@ package com.yahoo.container.handler;
import org.json.JSONException;
import org.json.JSONObject;
+import java.time.Duration;
import java.util.Base64;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.attribute.BasicFileAttributes;
public class LogReader {
@@ -17,7 +17,7 @@ public class LogReader {
protected JSONObject readLogs(String logDirectory, long earliestLogThreshold, long latestLogThreshold) throws IOException, JSONException {
this.earliestLogThreshold = earliestLogThreshold;
- this.latestLogThreshold = latestLogThreshold;
+ this.latestLogThreshold = latestLogThreshold + Duration.ofMinutes(5).toMillis(); // Add some time to allow retrieving logs currently being modified
JSONObject json = new JSONObject();
File root = new File(logDirectory);
traverse_folder(root, json, "");
@@ -27,7 +27,7 @@ public class LogReader {
private void traverse_folder(File root, JSONObject json, String filename) throws IOException, JSONException {
File[] files = root.listFiles();
for(File child : files) {
- long logTime = Files.readAttributes(child.toPath(), BasicFileAttributes.class).creationTime().toMillis();
+ long logTime = Files.getLastModifiedTime(child.toPath()).toMillis();
if(child.isFile() && earliestLogThreshold < logTime && logTime < latestLogThreshold) {
json.put(filename + child.getName(), Base64.getEncoder().encodeToString(Files.readAllBytes(child.toPath())));
}
diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java
index 3b1be62dfb1..d7c802faa3b 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java
@@ -6,6 +6,7 @@ import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
+import java.time.Instant;
import static org.junit.Assert.*;
@@ -22,7 +23,7 @@ public class LogReaderTest {
public void testThatFilesAreWrittenCorrectlyToOutputStream() throws Exception{
String logDirectory = "src/test/resources/logfolder/";
LogReader logReader = new LogReader();
- JSONObject json = logReader.readLogs(logDirectory, 21, Long.MAX_VALUE);
+ JSONObject json = logReader.readLogs(logDirectory, 21, Instant.now().toEpochMilli());
String expected = "{\"subfolder-log2.log\":\"VGhpcyBpcyBhbm90aGVyIGxvZyBmaWxl\",\"log1.log\":\"VGhpcyBpcyBvbmUgbG9nIGZpbGU=\"}";
String actual = json.toString();
assertEquals(expected, actual);