Skip to content

Commit

Permalink
Proper DynamoDB logging level and lambda timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
gj0dcsa committed Oct 27, 2024
1 parent 819f264 commit 4000cc5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public ConformanceStack(
.code(assetCode)
.handler("org.dcsa.conformance.lambda.SandboxTaskLambda")
.memorySize(1024)
.timeout(Duration.minutes(1))
.timeout(Duration.minutes(5))
.reservedConcurrentExecutions(16)
.logRetention(RetentionDays.SEVEN_YEARS)
.build());
Expand All @@ -191,7 +191,7 @@ public ConformanceStack(
.code(assetCode)
.handler("org.dcsa.conformance.lambda.ApiLambda")
.memorySize(1024)
.timeout(Duration.minutes(1))
.timeout(Duration.minutes(5))
.reservedConcurrentExecutions(16)
.logRetention(RetentionDays.SEVEN_YEARS)
.build());
Expand All @@ -206,7 +206,7 @@ public ConformanceStack(
.code(assetCode)
.handler("org.dcsa.conformance.lambda.WebuiLambda")
.memorySize(1024)
.timeout(Duration.minutes(1))
.timeout(Duration.minutes(5))
.reservedConcurrentExecutions(16)
.logRetention(RetentionDays.SEVEN_YEARS)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DynamoDbSortedPartitionsLockingMap(DynamoDbClient dynamoDbClient, String

@Override
protected void _saveItem(String lockedBy, String partitionKey, String sortKey, JsonNode value) {
log.debug(
log.info(
"START _saveItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
String oldLockedUntil = Instant.now().toString();
String newLockedUntil = Instant.ofEpochMilli(Instant.now().toEpochMilli() - 1).toString();
Expand Down Expand Up @@ -69,7 +69,7 @@ protected void _saveItem(String lockedBy, String partitionKey, String sortKey, J
.build())
.build());
} catch (TransactionCanceledException transactionCanceledException) {
log.debug(
log.info(
"CATCH _saveItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
log.warn(
"%s: %s"
Expand All @@ -80,13 +80,13 @@ protected void _saveItem(String lockedBy, String partitionKey, String sortKey, J
.collect(Collectors.joining(", "))));
throw new RuntimeException(transactionCanceledException);
}
log.debug("END _saveItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
log.info("END _saveItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
}

@Override
protected JsonNode _loadItem(String lockedBy, String partitionKey, String sortKey)
throws TemporaryLockingMapException {
log.debug(
log.info(
"START _loadItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
Map<String, AttributeValue> key =
Map.ofEntries(
Expand All @@ -95,13 +95,15 @@ protected JsonNode _loadItem(String lockedBy, String partitionKey, String sortKe

_createOrLockItem(lockedBy, partitionKey, sortKey, key);

log.info(
"END _loadItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
return _loadLockedItem(lockedBy, partitionKey, sortKey, key);
}

private void _createOrLockItem(
String lockedBy, String partitionKey, String sortKey, Map<String, AttributeValue> key)
throws TemporaryLockingMapException {
log.debug(
log.info(
"START _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
try {
Expand All @@ -127,13 +129,13 @@ private void _createOrLockItem(
} catch (TransactionCanceledException transactionCanceledException) {
if ("ConditionalCheckFailed"
.equals(transactionCanceledException.cancellationReasons().getFirst().code())) {
log.debug(
"CCF _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)"
log.info(
"ConditionalCheckFailed _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
_lockExistingItem(lockedBy, partitionKey, sortKey, key);
} else {
log.debug(
"TCE _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)"
log.info(
"TransactionCanceled _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
log.warn(
"Failed to create non-existing item (exception='%s' reasons='%s')"
Expand All @@ -145,15 +147,15 @@ private void _createOrLockItem(
throw transactionCanceledException;
}
}
log.debug(
log.info(
"END _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
}

private void _lockExistingItem(
String lockedBy, String partitionKey, String sortKey, Map<String, AttributeValue> key)
throws TemporaryLockingMapException {
log.debug(
log.info(
"START _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
String oldLockedUntil = Instant.now().toString();
Expand Down Expand Up @@ -187,12 +189,12 @@ private void _lockExistingItem(
if ("ConditionalCheckFailed"
.equals(transactionCanceledException.cancellationReasons().getFirst().code())) {
log.warn(
"CCF _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)"
"ConditionalCheckFailed _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
throw new TemporaryLockingMapException(transactionCanceledException);
} else {
log.debug(
"TCE _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)"
log.info(
"TransactionCanceled _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
log.warn(
"Failed to lock existing item (exception='%s' reasons='%s')"
Expand All @@ -204,14 +206,14 @@ private void _lockExistingItem(
throw transactionCanceledException;
}
}
log.debug(
log.info(
"END _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
}

private JsonNode _loadLockedItem(
String lockedBy, String partitionKey, String sortKey, Map<String, AttributeValue> key) {
log.debug(
log.info(
"START _loadLockedItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
try {
Expand All @@ -231,13 +233,13 @@ private JsonNode _loadLockedItem(
.get("value"),
AttributeValue.fromS("{}"))
.s());
log.debug(
log.info(
"RETURN _loadLockedItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
return itemValue;
} catch (TransactionCanceledException transactionCanceledException) {
log.debug(
"TCE _loadLockedItem(LB=%s, PK=%s, SK=%s, ...)"
log.info(
"TransactionCanceled _loadLockedItem(LB=%s, PK=%s, SK=%s, ...)"
.formatted(lockedBy, partitionKey, sortKey));
log.warn(
"Failed to get locked item value (exception='%s' reasons='%s')"
Expand All @@ -252,7 +254,7 @@ private JsonNode _loadLockedItem(

@Override
protected void _unlockItem(String lockedBy, String partitionKey, String sortKey) {
log.debug(
log.info(
"START _unlockItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
String oldLockedUntil = Instant.now().toString();
String newLockedUntil = Instant.ofEpochMilli(Instant.now().toEpochMilli() - 1).toString();
Expand Down Expand Up @@ -285,8 +287,8 @@ protected void _unlockItem(String lockedBy, String partitionKey, String sortKey)
.build())
.build());
} catch (TransactionCanceledException transactionCanceledException) {
log.debug(
"TCE _unlockItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
log.info(
"TransactionCanceled _unlockItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
log.warn(
"Failed to unlock item (exception='%s' reasons='%s')"
.formatted(
Expand All @@ -296,7 +298,7 @@ protected void _unlockItem(String lockedBy, String partitionKey, String sortKey)
.collect(Collectors.joining(", "))));
throw transactionCanceledException;
}
log.debug(
log.info(
"END _unlockItem(LB=%s, PK=%s, SK=%s, ...)".formatted(lockedBy, partitionKey, sortKey));
}

Expand Down

0 comments on commit 4000cc5

Please sign in to comment.