diff --git a/kaldb/src/main/java/com/slack/kaldb/chunk/ReadWriteChunk.java b/kaldb/src/main/java/com/slack/kaldb/chunk/ReadWriteChunk.java index 9d5a605796..0a6415adf7 100644 --- a/kaldb/src/main/java/com/slack/kaldb/chunk/ReadWriteChunk.java +++ b/kaldb/src/main/java/com/slack/kaldb/chunk/ReadWriteChunk.java @@ -3,6 +3,7 @@ import static com.slack.kaldb.chunk.ChunkInfo.toSnapshotMetadata; import static com.slack.kaldb.logstore.BlobFsUtils.copyToS3; import static com.slack.kaldb.logstore.BlobFsUtils.createURI; +import static com.slack.kaldb.writer.SpanFormatter.isValidTimestamp; import com.google.common.annotations.VisibleForTesting; import com.slack.kaldb.blobfs.BlobFs; @@ -153,11 +154,13 @@ public void addMessage(Trace.Span message, String kafkaPartitionId, long offset) if (!readOnly) { logStore.addMessage(message); - chunkInfo.updateDataTimeRange( - TimeUnit.MILLISECONDS.convert(message.getTimestamp(), TimeUnit.MICROSECONDS)); - // if we do this i.e also validate the timestamp tests - // that use dates from 2020 start failing so not touching this logic for now - // chunkInfo.updateDataTimeRange(SpanFormatter.getTimestampFromSpan(message).toEpochMilli()); + Instant timestamp = + Instant.ofEpochMilli( + TimeUnit.MILLISECONDS.convert(message.getTimestamp(), TimeUnit.MICROSECONDS)); + if (!isValidTimestamp(timestamp)) { + timestamp = Instant.now(); + } + chunkInfo.updateDataTimeRange(timestamp.toEpochMilli()); chunkInfo.updateMaxOffset(offset); } else { diff --git a/kaldb/src/main/java/com/slack/kaldb/logstore/schema/SchemaAwareLogDocumentBuilderImpl.java b/kaldb/src/main/java/com/slack/kaldb/logstore/schema/SchemaAwareLogDocumentBuilderImpl.java index 552e6475fc..7baace7512 100644 --- a/kaldb/src/main/java/com/slack/kaldb/logstore/schema/SchemaAwareLogDocumentBuilderImpl.java +++ b/kaldb/src/main/java/com/slack/kaldb/logstore/schema/SchemaAwareLogDocumentBuilderImpl.java @@ -3,6 +3,7 @@ import static com.slack.kaldb.logstore.LogMessage.computedIndexName; import static com.slack.kaldb.writer.SpanFormatter.DEFAULT_INDEX_NAME; import static com.slack.kaldb.writer.SpanFormatter.DEFAULT_LOG_MESSAGE_TYPE; +import static com.slack.kaldb.writer.SpanFormatter.isValidTimestamp; import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.annotations.VisibleForTesting; @@ -405,11 +406,20 @@ public Document fromMessage(Trace.Span message) throws JsonProcessingException { throw new IllegalArgumentException("Span id is empty"); } - // TODO: this interferes in tests - // Instant timestamp = SpanFormatter.getTimestampFromSpan(message); Instant timestamp = Instant.ofEpochMilli( TimeUnit.MILLISECONDS.convert(message.getTimestamp(), TimeUnit.MICROSECONDS)); + if (!isValidTimestamp(timestamp)) { + timestamp = Instant.now(); + addField( + doc, + LogMessage.ReservedField.KALDB_INVALID_TIMESTAMP.fieldName, + message.getTimestamp(), + "", + 0); + jsonMap.put( + LogMessage.ReservedField.KALDB_INVALID_TIMESTAMP.fieldName, message.getTimestamp()); + } addField( doc, LogMessage.SystemField.TIME_SINCE_EPOCH.fieldName, timestamp.toEpochMilli(), "", 0); diff --git a/kaldb/src/test/java/com/slack/kaldb/chunk/IndexingChunkImplTest.java b/kaldb/src/test/java/com/slack/kaldb/chunk/IndexingChunkImplTest.java index 102d864058..5008f943c8 100644 --- a/kaldb/src/test/java/com/slack/kaldb/chunk/IndexingChunkImplTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/chunk/IndexingChunkImplTest.java @@ -42,8 +42,6 @@ import java.nio.file.Path; import java.time.Duration; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; @@ -204,8 +202,7 @@ public void testAddAndSearchChunk() { @Test public void testAddAndSearchChunkInTimeRange() { - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); final long messageStartTimeMs = TimeUnit.MILLISECONDS.convert(messages.get(0).getTimestamp(), TimeUnit.MICROSECONDS); @@ -223,7 +220,11 @@ public void testAddAndSearchChunkInTimeRange() { final long expectedEndTimeEpochMs = messageStartTimeMs + (99 * 1000); // Ensure chunk info is correct. - assertThat(chunk.info().getDataStartTimeEpochMs()).isEqualTo(messageStartTimeMs); + Instant oneMinBefore = Instant.now().minus(1, ChronoUnit.MINUTES); + Instant oneMinBeforeAfter = Instant.now().plus(1, ChronoUnit.MINUTES); + assertThat(chunk.info().getDataStartTimeEpochMs()).isGreaterThan(oneMinBefore.toEpochMilli()); + assertThat(chunk.info().getDataStartTimeEpochMs()) + .isLessThan(oneMinBeforeAfter.toEpochMilli()); assertThat(chunk.info().getDataEndTimeEpochMs()).isEqualTo(expectedEndTimeEpochMs); assertThat(chunk.info().chunkId).contains(CHUNK_DATA_PREFIX); assertThat(chunk.info().getChunkSnapshotTimeEpochMs()).isZero(); @@ -248,9 +249,12 @@ public void testAddAndSearchChunkInTimeRange() { // Add more messages in other time range and search again with new time ranges. List newMessages = - SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime.plus(2, ChronoUnit.DAYS)); + SpanUtil.makeSpansWithTimeDifference( + 1, 100, 1000, startTime.plus(10, ChronoUnit.MINUTES)); final long newMessageStartTimeEpochMs = TimeUnit.MILLISECONDS.convert(newMessages.get(0).getTimestamp(), TimeUnit.MICROSECONDS); + final long newMessageEndTimeEpochMs = + TimeUnit.MILLISECONDS.convert(newMessages.get(99).getTimestamp(), TimeUnit.MICROSECONDS); for (Trace.Span m : newMessages) { chunk.addMessage(m, TEST_KAFKA_PARTITION_ID, offset); offset++; @@ -262,9 +266,10 @@ public void testAddAndSearchChunkInTimeRange() { assertThat(getTimerCount(REFRESHES_TIMER, registry)).isEqualTo(2); assertThat(getTimerCount(COMMITS_TIMER, registry)).isEqualTo(2); - assertThat(chunk.info().getDataStartTimeEpochMs()).isEqualTo(messageStartTimeMs); - assertThat(chunk.info().getDataEndTimeEpochMs()) - .isEqualTo(newMessageStartTimeEpochMs + (99 * 1000)); + assertThat(chunk.info().getDataStartTimeEpochMs()).isGreaterThan(oneMinBefore.toEpochMilli()); + assertThat(chunk.info().getDataStartTimeEpochMs()) + .isLessThan(oneMinBeforeAfter.toEpochMilli()); + assertThat(chunk.info().getDataEndTimeEpochMs()).isEqualTo(newMessageEndTimeEpochMs); // Search for message in expected time range. searchChunk("Message1", messageStartTimeMs, expectedEndTimeEpochMs, 1); diff --git a/kaldb/src/test/java/com/slack/kaldb/chunk/RecoveryChunkImplTest.java b/kaldb/src/test/java/com/slack/kaldb/chunk/RecoveryChunkImplTest.java index 3db8d6d198..7dfe1b37fe 100644 --- a/kaldb/src/test/java/com/slack/kaldb/chunk/RecoveryChunkImplTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/chunk/RecoveryChunkImplTest.java @@ -40,8 +40,6 @@ import java.nio.file.Path; import java.time.Duration; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; @@ -192,8 +190,7 @@ public void testAddAndSearchChunk() { @Test public void testAddAndSearchChunkInTimeRange() { - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); final long messageStartTimeMs = TimeUnit.MILLISECONDS.convert(messages.get(0).getTimestamp(), TimeUnit.MICROSECONDS); @@ -212,7 +209,11 @@ public void testAddAndSearchChunkInTimeRange() { final long expectedEndTimeEpochMs = TimeUnit.MILLISECONDS.convert(messages.get(99).getTimestamp(), TimeUnit.MICROSECONDS); // Ensure chunk info is correct. - assertThat(chunk.info().getDataStartTimeEpochMs()).isEqualTo(messageStartTimeMs); + Instant oneMinBefore = Instant.now().minus(1, ChronoUnit.MINUTES); + Instant oneMinBeforeAfter = Instant.now().plus(1, ChronoUnit.MINUTES); + assertThat(chunk.info().getDataStartTimeEpochMs()).isGreaterThan(oneMinBefore.toEpochMilli()); + assertThat(chunk.info().getDataStartTimeEpochMs()) + .isLessThan(oneMinBeforeAfter.toEpochMilli()); assertThat(chunk.info().getDataEndTimeEpochMs()).isEqualTo(expectedEndTimeEpochMs); assertThat(chunk.info().chunkId).contains(CHUNK_DATA_PREFIX); assertThat(chunk.info().getChunkSnapshotTimeEpochMs()).isZero(); @@ -238,9 +239,12 @@ public void testAddAndSearchChunkInTimeRange() { // Add more messages in other time range and search again with new time ranges. List newMessages = - SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime.plus(2, ChronoUnit.DAYS)); + SpanUtil.makeSpansWithTimeDifference( + 1, 100, 1000, startTime.plus(10, ChronoUnit.MINUTES)); final long newMessageStartTimeEpochMs = TimeUnit.MILLISECONDS.convert(newMessages.get(0).getTimestamp(), TimeUnit.MICROSECONDS); + final long newMessageEndTimeEpochMs = + TimeUnit.MILLISECONDS.convert(newMessages.get(99).getTimestamp(), TimeUnit.MICROSECONDS); for (Trace.Span m : newMessages) { chunk.addMessage(m, TEST_KAFKA_PARTITION_ID, offset); offset++; @@ -252,9 +256,10 @@ public void testAddAndSearchChunkInTimeRange() { assertThat(getTimerCount(REFRESHES_TIMER, registry)).isEqualTo(2); assertThat(getTimerCount(COMMITS_TIMER, registry)).isEqualTo(2); - assertThat(chunk.info().getDataStartTimeEpochMs()).isEqualTo(messageStartTimeMs); - assertThat(chunk.info().getDataEndTimeEpochMs()) - .isEqualTo(newMessageStartTimeEpochMs + (99 * 1000)); + assertThat(chunk.info().getDataStartTimeEpochMs()).isGreaterThan(oneMinBefore.toEpochMilli()); + assertThat(chunk.info().getDataStartTimeEpochMs()) + .isLessThan(oneMinBeforeAfter.toEpochMilli()); + assertThat(chunk.info().getDataEndTimeEpochMs()).isEqualTo(newMessageEndTimeEpochMs); // Search for message in expected time range. searchChunk("Message1", messageStartTimeMs, expectedEndTimeEpochMs, 1); diff --git a/kaldb/src/test/java/com/slack/kaldb/chunkManager/IndexingChunkManagerTest.java b/kaldb/src/test/java/com/slack/kaldb/chunkManager/IndexingChunkManagerTest.java index 811e021121..db7225a943 100644 --- a/kaldb/src/test/java/com/slack/kaldb/chunkManager/IndexingChunkManagerTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/chunkManager/IndexingChunkManagerTest.java @@ -1071,16 +1071,15 @@ public void testCommitInvalidChunk() throws Exception { @Test public void testMultiChunkSearch() throws Exception { - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); final List messages = SpanUtil.makeSpansWithTimeDifference(1, 10, 1000, startTime); messages.addAll( - SpanUtil.makeSpansWithTimeDifference(11, 20, 1000, startTime.plus(2, ChronoUnit.HOURS))); + SpanUtil.makeSpansWithTimeDifference(11, 20, 1000, startTime.plus(2, ChronoUnit.MINUTES))); messages.addAll( - SpanUtil.makeSpansWithTimeDifference(21, 30, 1000, startTime.plus(4, ChronoUnit.HOURS))); + SpanUtil.makeSpansWithTimeDifference(21, 30, 1000, startTime.plus(4, ChronoUnit.MINUTES))); messages.addAll( - SpanUtil.makeSpansWithTimeDifference(31, 35, 1000, startTime.plus(6, ChronoUnit.HOURS))); + SpanUtil.makeSpansWithTimeDifference(31, 35, 1000, startTime.plus(6, ChronoUnit.MINUTES))); final ChunkRollOverStrategy chunkRollOverStrategy = new DiskOrMessageCountBasedRolloverStrategy(metricsRegistry, 10 * 1024 * 1024 * 1024L, 10L); @@ -1148,7 +1147,7 @@ public void testMultiChunkSearch() throws Exception { chunkManager, "Message11", messagesStartTimeMs, messagesStartTimeMs + 10000)) .isEqualTo(0); - final long chunk2StartTimeMs = chunk1StartTimeMs + Duration.ofHours(2).toMillis(); + final long chunk2StartTimeMs = chunk1StartTimeMs + Duration.ofMinutes(2).toMillis(); final long chunk2EndTimeMs = chunk2StartTimeMs + 10000; assertThat(searchAndGetHitCount(chunkManager, "Message11", chunk2StartTimeMs, chunk2EndTimeMs)) @@ -1161,7 +1160,7 @@ public void testMultiChunkSearch() throws Exception { .isEqualTo(0); // Chunk 3 - final long chunk3StartTimeMs = chunk1StartTimeMs + Duration.ofHours(4).toMillis(); + final long chunk3StartTimeMs = chunk1StartTimeMs + Duration.ofMinutes(4).toMillis(); final long chunk3EndTimeMs = chunk3StartTimeMs + 10000; assertThat(searchAndGetHitCount(chunkManager, "Message21", chunk3StartTimeMs, chunk3EndTimeMs)) @@ -1174,7 +1173,7 @@ public void testMultiChunkSearch() throws Exception { .isEqualTo(0); // Chunk 4 - final long chunk4StartTimeMs = chunk1StartTimeMs + Duration.ofHours(6).toMillis(); + final long chunk4StartTimeMs = chunk1StartTimeMs + Duration.ofMinutes(6).toMillis(); final long chunk4EndTimeMs = chunk4StartTimeMs + 10000; assertThat(searchAndGetHitCount(chunkManager, "Message31", chunk4StartTimeMs, chunk4EndTimeMs)) diff --git a/kaldb/src/test/java/com/slack/kaldb/chunkrollover/DiskOrMessageCountBasedRolloverStrategyTest.java b/kaldb/src/test/java/com/slack/kaldb/chunkrollover/DiskOrMessageCountBasedRolloverStrategyTest.java index 488b052ed7..2b5c519c32 100644 --- a/kaldb/src/test/java/com/slack/kaldb/chunkrollover/DiskOrMessageCountBasedRolloverStrategyTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/chunkrollover/DiskOrMessageCountBasedRolloverStrategyTest.java @@ -257,8 +257,7 @@ public void testDiskBasedRolloverWithMaxMessages() throws Exception { initChunkManager( chunkRollOverStrategy, S3_TEST_BUCKET, MoreExecutors.newDirectExecutorService()); - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); int totalMessages = 10; int offset = 1; diff --git a/kaldb/src/test/java/com/slack/kaldb/logstore/search/KaldbLocalQueryServiceTest.java b/kaldb/src/test/java/com/slack/kaldb/logstore/search/KaldbLocalQueryServiceTest.java index 756e259771..1b4ff15e07 100644 --- a/kaldb/src/test/java/com/slack/kaldb/logstore/search/KaldbLocalQueryServiceTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/logstore/search/KaldbLocalQueryServiceTest.java @@ -33,8 +33,6 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.util.List; import java.util.concurrent.TimeoutException; import org.junit.jupiter.api.AfterEach; @@ -108,8 +106,7 @@ private static KaldbSearch.SearchRequest.SearchAggregation buildHistogramRequest public void testKalDbSearch() throws IOException { IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { @@ -176,8 +173,7 @@ public void testKalDbSearch() throws IOException { public void testKalDbSearchNoData() throws IOException { IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { @@ -222,8 +218,7 @@ public void testKalDbSearchNoData() throws IOException { public void testKalDbSearchNoHits() throws IOException { IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { @@ -270,8 +265,7 @@ public void testKalDbSearchNoHits() throws IOException { public void testKalDbSearchNoHistogram() throws IOException { IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { @@ -326,8 +320,7 @@ public void testKalDbSearchNoHistogram() throws IOException { public void testKalDbBadArgSearch() throws Throwable { IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { @@ -361,8 +354,7 @@ public void testKalDbGrpcSearch() throws IOException { // Load test data into chunk manager. IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { @@ -440,8 +432,7 @@ public void testKalDbGrpcSearchThrowsException() throws IOException { // Load test data into chunk manager. IndexingChunkManager chunkManager = chunkManagerUtil.chunkManager; - final Instant startTime = - LocalDateTime.of(2020, 10, 1, 10, 10, 0).atZone(ZoneOffset.UTC).toInstant(); + final Instant startTime = Instant.now(); List messages = SpanUtil.makeSpansWithTimeDifference(1, 100, 1000, startTime); int offset = 1; for (Trace.Span m : messages) { diff --git a/kaldb/src/test/java/com/slack/kaldb/logstore/search/LogIndexSearcherImplTest.java b/kaldb/src/test/java/com/slack/kaldb/logstore/search/LogIndexSearcherImplTest.java index 7fd6d52d93..f3b182ba11 100644 --- a/kaldb/src/test/java/com/slack/kaldb/logstore/search/LogIndexSearcherImplTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/logstore/search/LogIndexSearcherImplTest.java @@ -29,8 +29,7 @@ import com.slack.service.murron.trace.Trace; import java.io.IOException; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -82,10 +81,7 @@ private void loadTestData(Instant time) { @Test public void testTimeBoundSearch() { - Instant time = - LocalDateTime.ofEpochSecond(1593365471, 0, ZoneOffset.UTC) - .atZone(ZoneOffset.UTC) - .toInstant(); + Instant time = Instant.now(); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(1, time)); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(2, time.plusSeconds(100))); strictLogStore.logStore.commit(); @@ -236,7 +232,7 @@ public void testIndexBoundSearch() { @Test public void testSearchMultipleItemsAndIndices() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult babies = strictLogStore.logSearcher.search( @@ -560,7 +556,7 @@ public void testQueryParsingFieldTypes() { @Test public void testTopKQuery() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult apples = @@ -587,7 +583,7 @@ public void testTopKQuery() { @Test public void testSearchMultipleCommits() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(1, "apple", time)); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(2, "apple baby", time.plusSeconds(2))); @@ -691,8 +687,7 @@ public void testSearchMultipleCommits() { @Test public void testFullIndexSearch() { - Instant time = Instant.ofEpochSecond(1593365471); - loadTestData(time); + loadTestData(Instant.now()); SearchResult allIndexItems = strictLogStore.logSearcher.search( @@ -755,7 +750,7 @@ public void testAggregationWithScripting() { @Test public void testFilterAggregations() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult scriptNull = @@ -800,7 +795,7 @@ public void testFilterAggregations() { @Test public void testFullIndexSearchForMinAgg() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult allIndexItems = @@ -818,14 +813,12 @@ public void testFullIndexSearchForMinAgg() { InternalMin internalMin = (InternalMin) Objects.requireNonNull(allIndexItems.internalAggregation); - // NOTE: 1.593365471E12 is the epoch seconds above but in milliseconds and in scientific - // notation - assertThat(internalMin.getValue()).isEqualTo(Double.parseDouble("1.593365471E12")); + assertThat(Double.valueOf(internalMin.getValue()).longValue()).isEqualTo(time.toEpochMilli()); } @Test public void testFullIndexSearchForMaxAgg() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult allIndexItems = @@ -843,11 +836,9 @@ public void testFullIndexSearchForMaxAgg() { InternalMax internalMax = (InternalMax) Objects.requireNonNull(allIndexItems.internalAggregation); - // NOTE: 1.593365475E12 is the epoch seconds above, with 4 more seconds added on due to the - // test - // data, but in - // milliseconds and in scientific notation - assertThat(internalMax.getValue()).isEqualTo(Double.parseDouble("1.593365475E12")); + // 4 seconds because of test data + assertThat(Double.valueOf(internalMax.getValue()).longValue()) + .isEqualTo(time.plus(4, ChronoUnit.SECONDS).toEpochMilli()); } @Test @@ -1512,7 +1503,7 @@ public void testNoResultQuery() { @Test public void testSearchAndNoStats() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult results = strictLogStore.logSearcher.search( @@ -1528,7 +1519,7 @@ public void testSearchAndNoStats() { @Test public void testSearchOnlyHistogram() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult babies = strictLogStore.logSearcher.search( @@ -1757,7 +1748,7 @@ public void testConcurrentSearches() throws InterruptedException { @Test public void testSearchById() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); loadTestData(time); SearchResult index = strictLogStore.logSearcher.search( diff --git a/kaldb/src/test/java/com/slack/kaldb/logstore/search/SearchResultAggregatorImplTest.java b/kaldb/src/test/java/com/slack/kaldb/logstore/search/SearchResultAggregatorImplTest.java index 0445e6fc4c..6d178a91d0 100644 --- a/kaldb/src/test/java/com/slack/kaldb/logstore/search/SearchResultAggregatorImplTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/logstore/search/SearchResultAggregatorImplTest.java @@ -20,8 +20,6 @@ import java.io.IOException; import java.time.Duration; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; @@ -45,8 +43,8 @@ public void testSimpleSearchResultsAggWithOneResult() throws IOException { long tookMs = 10; int bucketCount = 13; int howMany = 1; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); - Instant startTime2 = LocalDateTime.of(2020, 1, 1, 2, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); + Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); long histogramStartMs = startTime1.toEpochMilli(); long histogramEndMs = startTime1.plus(2, ChronoUnit.HOURS).toEpochMilli(); @@ -116,7 +114,7 @@ public void testSimpleSearchResultsAggWithMultipleResults() throws IOException { long tookMs = 10; int bucketCount = 13; int howMany = 10; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); long histogramStartMs = startTime1.toEpochMilli(); long histogramEndMs = startTime1.plus(2, ChronoUnit.HOURS).toEpochMilli(); @@ -186,7 +184,7 @@ public void testSearchResultAggregatorOn4Results() throws IOException { long tookMs = 10; int bucketCount = 25; int howMany = 10; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); Instant startTime3 = startTime1.plus(2, ChronoUnit.HOURS); Instant startTime4 = startTime1.plus(3, ChronoUnit.HOURS); @@ -275,7 +273,7 @@ public void testSearchResultAggregatorOn4Results() throws IOException { public void testSimpleSearchResultsAggWithNoHistograms() throws IOException { long tookMs = 10; int howMany = 10; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); long searchStartMs = startTime1.toEpochMilli(); long searchEndMs = startTime1.plus(2, ChronoUnit.HOURS).toEpochMilli(); @@ -325,7 +323,7 @@ public void testSimpleSearchResultsAggNoHits() throws IOException { long tookMs = 10; int bucketCount = 13; int howMany = 0; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); long histogramStartMs = startTime1.toEpochMilli(); long histogramEndMs = startTime1.plus(2, ChronoUnit.HOURS).toEpochMilli(); @@ -390,7 +388,7 @@ public void testSimpleSearchResultsAggNoHits() throws IOException { public void testSearchResultsAggIgnoresBucketsInSearchResultsSafely() throws IOException { long tookMs = 10; int howMany = 10; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); long startTimeMs = startTime1.toEpochMilli(); long endTimeMs = startTime1.plus(2, ChronoUnit.HOURS).toEpochMilli(); @@ -449,7 +447,7 @@ public void testSimpleSearchResultsAggIgnoreHitsSafely() throws IOException { long tookMs = 10; int bucketCount = 13; int howMany = 0; - Instant startTime1 = LocalDateTime.of(2020, 1, 1, 1, 0, 0).atZone(ZoneOffset.UTC).toInstant(); + Instant startTime1 = Instant.now(); Instant startTime2 = startTime1.plus(1, ChronoUnit.HOURS); long histogramStartMs = startTime1.toEpochMilli(); long histogramEndMs = startTime1.plus(2, ChronoUnit.HOURS).toEpochMilli(); diff --git a/kaldb/src/test/java/com/slack/kaldb/logstore/search/StatsCollectorTest.java b/kaldb/src/test/java/com/slack/kaldb/logstore/search/StatsCollectorTest.java index f6c7503f32..89fdd571fb 100644 --- a/kaldb/src/test/java/com/slack/kaldb/logstore/search/StatsCollectorTest.java +++ b/kaldb/src/test/java/com/slack/kaldb/logstore/search/StatsCollectorTest.java @@ -36,7 +36,7 @@ public void setUp() throws Exception { @Test public void testStatsCollectorWithPerMinuteMessages() { - Instant time = Instant.ofEpochSecond(1593365471); + Instant time = Instant.now(); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(1, time)); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(2, time.plusSeconds(60))); strictLogStore.logStore.addMessage(SpanUtil.makeSpan(3, time.plusSeconds(2 * 60)));