mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudtrail): stop CloudTrailLogWriterBoundedRetryIntegrationTest relying on S3 key order (#3363)
RETRY_RECORD_LIMIT (1024) sits just above MAX_RECORDS_PER_LOG_FILE (1000), so recovery always splits retained records into two log files written in the same delivery minute, distinguished only by a random filename suffix with no relation to write order. deliveredRecords() read files back in S3 listing order and assumed that matched write order, so the test's pass/fail flipped depending on which random suffix sorted first. Sort delivered records by the sequence already embedded in each event's own key (events/NNNN.txt) instead. Introduced by #3298. Fixes #3361
This commit is contained in:
1 parent
50fa334dc5
commit
34be181c0c
1 file changed
+17
+17
@@ -12,10 +12,13 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
@@ -301,6 +304,14 @@ class CloudTrailLogWriterBoundedRetryIntegrationTest {
|
||||
return String.format("events/%04d.txt", index);
|
||||
}
|
||||
|
||||
// Two log files written in the same flush cycle can land in the same delivery
|
||||
// minute, leaving only a random filename suffix (CloudTrailLogWriter#randomFilenameSuffix)
|
||||
// to distinguish their S3 keys. That suffix carries no relationship to write order, so
|
||||
// relying on S3 listing order across files (as real CloudTrail's own key layout would
|
||||
// also not support) is not a reliable way to reconstruct delivery order. Each event's
|
||||
// own key already encodes its original sequence, so sort on that instead.
|
||||
private static final Pattern EVENT_INDEX = Pattern.compile("(\\d+)\\.txt$");
|
||||
|
||||
private static List<JsonNode> deliveredRecords(String bucket) throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
List<JsonNode> records = new ArrayList<>();
|
||||
@@ -313,9 +324,15 @@ class CloudTrailLogWriterBoundedRetryIntegrationTest {
|
||||
}
|
||||
mapper.readTree(json).path("Records").forEach(records::add);
|
||||
}
|
||||
records.sort(Comparator.comparingInt(CloudTrailLogWriterBoundedRetryIntegrationTest::sourceEventIndex));
|
||||
return records;
|
||||
}
|
||||
|
||||
private static int sourceEventIndex(JsonNode record) {
|
||||
Matcher m = EVENT_INDEX.matcher(record.path("requestParameters").path("key").asText(""));
|
||||
return m.find() ? Integer.parseInt(m.group(1)) : Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
private static List<String> listLogKeys(String bucket) {
|
||||
String xml = given().when().get("/" + bucket + "?list-type=2")
|
||||
.then().statusCode(200).extract().asString();
|
||||
|
||||
Reference in new issue
Block a user