diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2020-06-12 15:46:21 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2020-06-12 15:46:21 +0200 |
commit | 4a36842785c919e626fcb3665e8be9d4a9df31a6 (patch) | |
tree | fb2676afa6917c0b985f559991e12bbeb90ebce4 /container-core/src/test/java | |
parent | 153813c0969f821c869689ebaebef589b6af118c (diff) |
Extract time stamp from path instead of modified time
Diffstat (limited to 'container-core/src/test/java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java | 51 |
1 files changed, 28 insertions, 23 deletions
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 c5ddfe898b9..6b7be1d8cd3 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 @@ -12,7 +12,7 @@ import java.io.OutputStream; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.attribute.FileTime; +import java.time.Duration; import java.time.Instant; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; @@ -26,51 +26,56 @@ public class LogReaderTest { private final FileSystem fileSystem = TestFileSystem.create(); private final Path logDirectory = fileSystem.getPath("/opt/vespa/logs"); - private static final String log1 = "0.1\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstdout\tinfo\tERROR: Bundle canary-application [71] Unable to get module class path. (java.lang.NullPointerException)\n"; - private static final String log2 = "0.15\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstderr\twarning\twarning\n"; - private static final String log3 = "0.2\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstderr\twarning\tjava.lang.NullPointerException\\n\\tat org.apache.felix.framework.BundleRevisionImpl.calculateContentPath(BundleRevisionImpl.java:438)\\n\\tat org.apache.felix.framework.BundleRevisionImpl.initializeContentPath(BundleRevisionImpl.java:371)\n"; + private static final String logv11 = "3600.2\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstdout\tinfo\tfourth\n"; + private static final String logv = "90000.1\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstdout\tinfo\tlast\n"; + private static final String log100 = "0.2\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstdout\tinfo\tsecond\n"; + private static final String log101 = "0.1\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstdout\tinfo\tERROR: Bundle canary-application [71] Unable to get module class path. (java.lang.NullPointerException)\n"; + private static final String log110 = "3600.1\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstderr\twarning\tthird\n"; + private static final String log200 = "86400.1\t17491290-v6-1.ostk.bm2.prod.ne1.yahoo.com\t5480\tcontainer\tstderr\twarning\tjava.lang.NullPointerException\\n\\tat org.apache.felix.framework.BundleRevisionImpl.calculateContentPath(BundleRevisionImpl.java:438)\\n\\tat org.apache.felix.framework.BundleRevisionImpl.initializeContentPath(BundleRevisionImpl.java:371)\n"; @Before public void setup() throws IOException { - Files.createDirectories(logDirectory.resolve("subfolder")); - - Files.setLastModifiedTime( - Files.write(logDirectory.resolve("log1.log.gz"), compress(log1)), - FileTime.from(Instant.ofEpochMilli(123))); - Files.setLastModifiedTime( - Files.write(logDirectory.resolve("subfolder/log2.log.gz"), compress(log2)), - FileTime.from(Instant.ofEpochMilli(180))); - Files.setLastModifiedTime( - Files.write(logDirectory.resolve("subfolder/log3.log"), log3.getBytes(UTF_8)), - FileTime.from(Instant.ofEpochMilli(234))); - + // Log archive paths and file names indicate what hour they contain logs for, with the start of that hour. + // Multiple entries may exist for each hour. + Files.createDirectories(logDirectory.resolve("1970/01/01")); + Files.write(logDirectory.resolve("1970/01/01/00-0.gz"), compress(log100)); + Files.write(logDirectory.resolve("1970/01/01/00-1"), log101.getBytes(UTF_8)); + Files.write(logDirectory.resolve("1970/01/01/01-0.gz"), compress(log110)); + + Files.createDirectories(logDirectory.resolve("1970/01/02")); + Files.write(logDirectory.resolve("1970/01/02/00-0"), log200.getBytes(UTF_8)); + + // Vespa log file names are the second-truncated timestamp of the last entry. + // The current log file has no timestamp suffix. + Files.write(logDirectory.resolve("vespa.log-1970-01-01.01-00-00"), logv11.getBytes(UTF_8)); + Files.write(logDirectory.resolve("vespa.log"), logv.getBytes(UTF_8)); } @Test public void testThatLogsOutsideRangeAreExcluded() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*")); - logReader.writeLogs(baos, Instant.ofEpochMilli(150), Instant.ofEpochMilli(160)); + logReader.writeLogs(baos, Instant.ofEpochMilli(150), Instant.ofEpochMilli(3601050)); - assertEquals("", decompress(baos.toByteArray())); + assertEquals(log100 + logv11 + log110, decompress(baos.toByteArray())); } @Test public void testThatLogsNotMatchingRegexAreExcluded() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*3\\.log")); - logReader.writeLogs(baos, Instant.ofEpochMilli(0), Instant.ofEpochMilli(300)); + LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*-1.*")); + logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2))); - assertEquals(log3, decompress(baos.toByteArray())); + assertEquals(log101 + logv11, decompress(baos.toByteArray())); } @Test public void testZippedStreaming() throws IOException { ByteArrayOutputStream zippedBaos = new ByteArrayOutputStream(); LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*")); - logReader.writeLogs(zippedBaos, Instant.ofEpochMilli(0), Instant.ofEpochMilli(300)); + logReader.writeLogs(zippedBaos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2))); - assertEquals(log1 + log2 + log3, decompress(zippedBaos.toByteArray())); + assertEquals(log100 + log101 + logv11 + log110 + log200 + logv, decompress(zippedBaos.toByteArray())); } private byte[] compress(String input) throws IOException { |