fix(ecs): retry FireLens configuration uploads (#6075)

* fix(ecs): retry FireLens configuration archive uploads

* test(ecs): cover FireLens upload failure boundaries

* perf(ecs): avoid streaming pipes for prebuilt FireLens archives

Reuse byte-backed archive retries without the 16 MiB pipe and writer thread per attempt. Preserve exact archive bytes and the shared retry policy. Warmed launch measurements dropped from 17.3 MB to 0.5-0.6 MB on the caller thread, with zero new writer threads. Add regression coverage for allocation path, consumed streams and failure boundaries.

* test(ecs): make FireLens retry regressions sleep-free

Add a package-private task-launch overload for the FireLens upload delay. The public entry point retains six attempts and the shared 500 ms initial backoff. Preserve real replay and cleanup assertions, and verify default, zero and nonzero delay selection. The expanded 32-case class runs in 0.54-0.68 seconds instead of 22.19 seconds.
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-20 12:12:47 -04:00
1 parent d09b3215d5
commit 17f32c9d04
5 files changed
+293 -21

No files matched your search

@@ -62,8 +62,19 @@ public final class RetryingTarCopier {
public static void copyBytes(DockerClient docker, String containerId, String remotePath,
String entryName, byte[] content, int mode,
int maxAttempts, long backoffMillis) {
byte[] tar = singleFileTar(entryName, content, mode);
retry(entryName, containerId, maxAttempts, backoffMillis, () ->
copyArchive(docker, containerId, remotePath, entryName, singleFileTar(entryName, content, mode),
maxAttempts, backoffMillis);
}
/** Copies an already-built tar through fresh byte-backed streams; do not modify it during the copy. */
public static void copyArchive(DockerClient docker, String containerId, String remotePath,
String label, byte[] tar) {
copyArchive(docker, containerId, remotePath, label, tar, DEFAULT_MAX_ATTEMPTS, DEFAULT_BACKOFF_MS);
}
public static void copyArchive(DockerClient docker, String containerId, String remotePath,
String label, byte[] tar, int maxAttempts, long backoffMillis) {
retry(label, containerId, maxAttempts, backoffMillis, () ->
docker.copyArchiveToContainerCmd(containerId)
.withRemotePath(remotePath)
.withTarInputStream(new ByteArrayInputStream(tar))
@@ -26,6 +26,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
import io.github.hectorvent.floci.core.common.docker.LaunchedContainerAwsEnv;
import io.github.hectorvent.floci.core.common.docker.RetryingTarCopier;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.SecurityGroupFirewallManager;
import io.github.hectorvent.floci.services.ec2.SecurityGroupNftCompiler;
@@ -70,7 +71,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
@@ -243,6 +243,11 @@ public class EcsContainerManager {
*/
public EcsTaskHandle startTask(EcsTask task, TaskDefinition taskDef,
List<ContainerOverride> containerOverrides, String region) {
return startTask(task, taskDef, containerOverrides, region, RetryingTarCopier.DEFAULT_BACKOFF_MS);
}
EcsTaskHandle startTask(EcsTask task, TaskDefinition taskDef,
List<ContainerOverride> containerOverrides, String region, long firelensBackoffMillis) {
String taskId = extractTaskId(task.getTaskArn());
Map<String, String> containerIds = new LinkedHashMap<>();
@@ -543,7 +548,7 @@ public class EcsContainerManager {
dockerId = lifecycleManager.create(spec);
try {
copyFirelensConfig(dockerId, firelensConfig, isFluentdRouter(firelensRouter),
firelensExternalConfig);
firelensExternalConfig, firelensBackoffMillis);
lifecycleManager.startCreated(dockerId, spec);
} catch (RuntimeException e) {
lifecycleManager.removeIfExists(dockerId);
@@ -1784,7 +1789,7 @@ public class EcsContainerManager {
}
private void copyFirelensConfig(
String containerId, String configText, boolean fluentd, String externalConfig) {
String containerId, String configText, boolean fluentd, String externalConfig, long backoffMillis) {
byte[] content = configText.getBytes(StandardCharsets.UTF_8);
String fileName = fluentd ? "fluent.conf" : "fluent-bit.conf";
String remotePath = fluentd ? "/fluentd/etc" : "/fluent-bit/etc";
@@ -1798,10 +1803,9 @@ public class EcsContainerManager {
throw new AwsException("ClientException",
"unable to write FireLens config: " + e.getMessage(), 500);
}
lifecycleManager.getDockerClient().copyArchiveToContainerCmd(containerId)
.withRemotePath(remotePath)
.withTarInputStream(new ByteArrayInputStream(archive.toByteArray()))
.exec();
byte[] tarBytes = archive.toByteArray();
RetryingTarCopier.copyArchive(lifecycleManager.getDockerClient(), containerId,
remotePath, "firelens-config", tarBytes, RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, backoffMillis);
}
private static void putTarEntry(TarArchiveOutputStream tar, String name, byte[] content) throws IOException {