Skip to content

Commit

Permalink
[Integration] Update timeout values to work better with the service.
Browse files Browse the repository at this point in the history
Integration can take 4+ hours to create if the source database is huge. Likewise, the delete should not take more than 30 minutes, so the timeouts are being adjusted.
  • Loading branch information
wbkang committed Mar 4, 2024
1 parent e6ba105 commit c05cff0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import software.amazon.cloudformation.proxy.ProgressEvent;
import software.amazon.cloudformation.proxy.ProxyClient;
import software.amazon.cloudformation.proxy.ResourceHandlerRequest;
import software.amazon.cloudformation.proxy.delay.Constant;
import software.amazon.rds.common.error.ErrorRuleSet;
import software.amazon.rds.common.error.ErrorStatus;
import software.amazon.rds.common.handler.Commons;
Expand All @@ -24,6 +25,7 @@
import software.amazon.rds.common.logging.RequestLogger;
import software.amazon.rds.common.printer.FilteredJsonPrinter;

import java.time.Duration;
import java.util.Collection;
import java.util.Optional;

Expand All @@ -40,6 +42,18 @@ public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> {
protected static final int MAX_LENGTH_INTEGRATION = 63;
protected static final int CALLBACK_DELAY = 6;

/** Huge database resync could potentially take a very long time. */
public static final Constant CREATE_UPDATE_DELAY = Constant.of()
.delay(Duration.ofSeconds(30))
.timeout(Duration.ofHours(8))
.build();

/** Delete shouldn't take too long. */
public static final Constant DELETE_DELAY = Constant.of()
.delay(Duration.ofSeconds(30))
.timeout(Duration.ofMinutes(30))
.build();

protected static final ErrorRuleSet DEFAULT_INTEGRATION_ERROR_RULE_SET = ErrorRuleSet
.extend(Commons.DEFAULT_ERROR_RULE_SET)
.withErrorClasses(ErrorStatus.failWith(HandlerErrorCode.AlreadyExists),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class CreateHandler extends BaseHandlerStd {

/** Default constructor w/ default backoff */
public CreateHandler() {
this(HandlerConfig.builder()
.backoff(CREATE_UPDATE_DELAY)
.build());
}

/** Default constructor w/ custom config */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public class DeleteHandler extends BaseHandlerStd {
static final int CALLBACK_DELAY = 6;

/** Default constructor w/ default backoff */
public DeleteHandler() {}
public DeleteHandler() {
this(HandlerConfig.builder()
.backoff(DELETE_DELAY)
.build());
}

/** Default constructor w/ custom config */
public DeleteHandler(HandlerConfig config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

public class UpdateHandler extends BaseHandlerStd {
/** Default constructor w/ default backoff */
public UpdateHandler() {}
public UpdateHandler() {
this(HandlerConfig.builder()
.backoff(CREATE_UPDATE_DELAY)
.build());
}

/** Default constructor w/ custom config */
public UpdateHandler(HandlerConfig config) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package software.amazon.rds.integration;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import software.amazon.cloudformation.proxy.delay.Constant;

import java.time.Duration;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class TimeoutVerificationTest {

@ParameterizedTest
@MethodSource("timeoutsAndHandlersProvider")
public void verifyDefaultBackoffConfig(final Duration timeout, final BaseHandlerStd handler) {
final Constant backoffConfig = handler.config.getBackoff();
Duration totalWaitTime = Duration.ZERO;
int attempt = 1;
Duration delay = backoffConfig.nextDelay(attempt);
while (delay != Duration.ZERO) {
totalWaitTime = totalWaitTime.plus(delay);
attempt += 1;
delay = backoffConfig.nextDelay(attempt);
}
assertTrue(totalWaitTime.compareTo(timeout) >= 0);
}

static Stream<Arguments> timeoutsAndHandlersProvider() {
return Stream.of(
Arguments.arguments(Duration.ofHours(8), new CreateHandler()),
Arguments.arguments(Duration.ofHours(8), new UpdateHandler()),
Arguments.arguments(Duration.ofMinutes(30), new DeleteHandler())
);
}
}

0 comments on commit c05cff0

Please sign in to comment.