From 4000cc5291d83432362378f3f149070c2e603107 Mon Sep 17 00:00:00 2001 From: gj0dcsa <135594855+gj0dcsa@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:24:50 +0100 Subject: [PATCH] Proper DynamoDB logging level and lambda timeouts --- .../conformance/cdk/ConformanceStack.java | 6 +-- .../DynamoDbSortedPartitionsLockingMap.java | 48 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/cdk/src/main/java/org/dcsa/conformance/cdk/ConformanceStack.java b/cdk/src/main/java/org/dcsa/conformance/cdk/ConformanceStack.java index f7175c8d..62c98980 100644 --- a/cdk/src/main/java/org/dcsa/conformance/cdk/ConformanceStack.java +++ b/cdk/src/main/java/org/dcsa/conformance/cdk/ConformanceStack.java @@ -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()); @@ -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()); @@ -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()); diff --git a/sandbox/src/main/java/org/dcsa/conformance/sandbox/state/DynamoDbSortedPartitionsLockingMap.java b/sandbox/src/main/java/org/dcsa/conformance/sandbox/state/DynamoDbSortedPartitionsLockingMap.java index b302c4b6..bb0088d1 100644 --- a/sandbox/src/main/java/org/dcsa/conformance/sandbox/state/DynamoDbSortedPartitionsLockingMap.java +++ b/sandbox/src/main/java/org/dcsa/conformance/sandbox/state/DynamoDbSortedPartitionsLockingMap.java @@ -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(); @@ -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" @@ -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 key = Map.ofEntries( @@ -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 key) throws TemporaryLockingMapException { - log.debug( + log.info( "START _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)" .formatted(lockedBy, partitionKey, sortKey)); try { @@ -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')" @@ -145,7 +147,7 @@ private void _createOrLockItem( throw transactionCanceledException; } } - log.debug( + log.info( "END _createOrLockItem(LB=%s, PK=%s, SK=%s, ...)" .formatted(lockedBy, partitionKey, sortKey)); } @@ -153,7 +155,7 @@ private void _createOrLockItem( private void _lockExistingItem( String lockedBy, String partitionKey, String sortKey, Map key) throws TemporaryLockingMapException { - log.debug( + log.info( "START _lockExistingItem(LB=%s, PK=%s, SK=%s, ...)" .formatted(lockedBy, partitionKey, sortKey)); String oldLockedUntil = Instant.now().toString(); @@ -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')" @@ -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 key) { - log.debug( + log.info( "START _loadLockedItem(LB=%s, PK=%s, SK=%s, ...)" .formatted(lockedBy, partitionKey, sortKey)); try { @@ -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')" @@ -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(); @@ -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( @@ -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)); }