From 7ebe0688e0ba2d59e586740abbf13949da152713 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Thu, 3 Jun 2021 18:28:52 +0900 Subject: [PATCH] Enable `startFromHead` of EcsClient for `nextToken` (#1593) --- .../io/digdag/standards/command/EcsCommandExecutor.java | 9 +++++++++ .../digdag/standards/command/ecs/DefaultEcsClient.java | 2 ++ 2 files changed, 11 insertions(+) diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/EcsCommandExecutor.java b/digdag-standards/src/main/java/io/digdag/standards/command/EcsCommandExecutor.java index a639ece986..cdef64aa9a 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/EcsCommandExecutor.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/EcsCommandExecutor.java @@ -60,6 +60,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class EcsCommandExecutor @@ -329,6 +330,14 @@ CommandStatus createNextCommandStatus( if (previousExecutorStatus.get("logging_finished_at") != null) { break; } + try { + // Just to avoid DOS attack to ECS endpoint + TimeUnit.SECONDS.sleep(2); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } } while (Instant.now().getEpochSecond() < timeout); diff --git a/digdag-standards/src/main/java/io/digdag/standards/command/ecs/DefaultEcsClient.java b/digdag-standards/src/main/java/io/digdag/standards/command/ecs/DefaultEcsClient.java index ee8fa3270e..0c054e78f4 100644 --- a/digdag-standards/src/main/java/io/digdag/standards/command/ecs/DefaultEcsClient.java +++ b/digdag-standards/src/main/java/io/digdag/standards/command/ecs/DefaultEcsClient.java @@ -270,6 +270,8 @@ public GetLogEventsResult getLog( final Optional nextToken) { final GetLogEventsRequest request = new GetLogEventsRequest() + // This should be true when using `nextToken`. See the doc for details. + .withStartFromHead(true) .withLogGroupName(groupName) .withLogStreamName(streamName); if (nextToken.isPresent()) {