mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudwatch-logs): preserve ingestion order for same-timestamp events (#1592)
* fix(cloudwatch-logs): preserve ingestion order for same-timestamp events GetLogEvents and FilterLogEvents sorted events by timestamp only, so events sharing the same millisecond came back in arbitrary store order. Add a monotonic ingestion sequence to LogEvent and use it as a sort tie-breaker, matching CloudWatch Logs which returns same-timestamp events in ingestion order. The counter is seeded from the highest stored sequence so ordering survives persistence reloads. Closes #1584 * fix(cloudwatch-logs): add eventId as final ordering tie-breaker Legacy events created before the sequence field default to sequence 0, so timestamp+sequence alone left their relative order to arbitrary scan order. Fall back to eventId to keep ordering deterministic. * test(cloudwatch-logs): import ArrayList instead of inline FQN Add an import for java.util.ArrayList and use the short name across the test, replacing inline new java.util.ArrayList<>() usages.
This commit is contained in:
1 parent
189d893803
commit
7f76009cdb
3 files changed
+83
-3
No files matched your search
+49
-1
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.cloudwatch.logs.model.SubscriptionFil
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -174,6 +175,53 @@ class CloudWatchLogsServiceTest {
|
||||
assertEquals("second", result.events().get(1).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLogEventsPreservesIngestionOrderForSameTimestamp() {
|
||||
// Regression for issue #1584: events written in order within the same millisecond
|
||||
// must come back from GetLogEvents in ingestion order, not shuffled.
|
||||
service.createLogGroup("/app/logs", null, null, REGION);
|
||||
service.createLogStream("/app/logs", "stream-1", REGION);
|
||||
|
||||
long ts = System.currentTimeMillis();
|
||||
List<Map<String, Object>> events = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
events.add(Map.of("timestamp", ts, "message", "SEQLINE-" + i));
|
||||
}
|
||||
service.putLogEvents("/app/logs", "stream-1", events, REGION);
|
||||
|
||||
CloudWatchLogsService.LogEventsResult result = service.getLogEvents(
|
||||
"/app/logs", "stream-1", null, null, 100, true, null, REGION);
|
||||
|
||||
assertEquals(10, result.events().size());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertEquals("SEQLINE-" + i, result.events().get(i).getMessage(),
|
||||
"event at index " + i + " out of ingestion order");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void filterLogEventsPreservesIngestionOrderForSameTimestamp() {
|
||||
// Same-timestamp ordering must also hold for FilterLogEvents.
|
||||
service.createLogGroup("/app/logs", null, null, REGION);
|
||||
service.createLogStream("/app/logs", "stream-1", REGION);
|
||||
|
||||
long ts = System.currentTimeMillis();
|
||||
List<Map<String, Object>> events = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
events.add(Map.of("timestamp", ts, "message", "SEQLINE-" + i));
|
||||
}
|
||||
service.putLogEvents("/app/logs", "stream-1", events, REGION);
|
||||
|
||||
CloudWatchLogsService.FilteredLogEventsResult result = service.filterLogEvents(
|
||||
"/app/logs", null, null, null, "SEQLINE", 100, REGION);
|
||||
|
||||
assertEquals(10, result.events().size());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertEquals("SEQLINE-" + i, result.events().get(i).getMessage(),
|
||||
"event at index " + i + " out of ingestion order");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLogEventsWithTimeRange() {
|
||||
service.createLogGroup("/app/logs", null, null, REGION);
|
||||
@@ -270,7 +318,7 @@ class CloudWatchLogsServiceTest {
|
||||
// ──────────────────────────── GetLogEvents pagination (issue #90) ────────────────────────────
|
||||
|
||||
private void putEvents(String group, String stream, long baseTs, int count) {
|
||||
List<Map<String, Object>> events = new java.util.ArrayList<>();
|
||||
List<Map<String, Object>> events = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
events.add(Map.of("timestamp", baseTs + i, "message", "msg-" + i));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user