diff --git a/.github/workflows/telemetry-conformance-tests.yml b/.github/workflows/telemetry-conformance-tests.yml index 507b43b86..5eb3063d1 100644 --- a/.github/workflows/telemetry-conformance-tests.yml +++ b/.github/workflows/telemetry-conformance-tests.yml @@ -44,8 +44,8 @@ jobs: id-token: write # The pinned SHA also selects the runner and telemetry-extension revision the shared # workflow installs, so it must be reachable from a branch. It is the merge commit of - # aws-durable-execution-conformance-tests PR #183 on that repository's main branch. - uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@cf13ef27d6e13a4423f7e0a178f9a3d4bb1099f0 + # aws-durable-execution-conformance-tests PR #185 on that repository's main branch. + uses: aws/aws-durable-execution-conformance-tests/.github/workflows/telemetry-suite.yml@b380cbf19bbc4f08a2d7c593d4bf24f585946415 with: language: java resource_prefix: java diff --git a/conformance-tests-telemetry/README.md b/conformance-tests-telemetry/README.md index c8085e38b..adf3ff7f4 100644 --- a/conformance-tests-telemetry/README.md +++ b/conformance-tests-telemetry/README.md @@ -21,6 +21,7 @@ template that maps it to the requirement ID. | `telemetry` | `telemetry-1` | One successful single-step execution emits one `SUCCEEDED` record with `input`, `output`, ARN-derived identity fields, and `operationsByName`. | | `telemetry` | `telemetry-2` | One failed execution emits one `FAILED` record with an `error` on the execution and on `operationsByName.charge`. | | `telemetry` | `telemetry-3` | An `OperationOverride.withResult` transform exports exactly `{userId}` of a three-key step result; the record has no `input` or `output`. | +| `telemetry` | `telemetry-4` | `FULL_TREE` operation detail exports a map, its two `MapIteration` contexts, and the step inside each, five keys in `operationsByName`. | ## Layout @@ -31,9 +32,10 @@ src/main/java/software/amazon/lambda/durable/conformance/telemetry/ Telemetry1Success.java # single step "increment"; plugin + CloudWatchLogsExporter Telemetry2Failure.java # step "charge" fails; handler throws "payment failed" with the step error as cause Telemetry3ResultSelect.java # step "fetch-user"; override transform keeps only userId in the record + Telemetry4FullTreeMap.java # map "process-items" over the event; iterations item-N; step greet-N; FULL_TREE detail TelemetryConformanceConfig.java # shared log-group guard and plugin config; every handler calls it src/test/java/software/amazon/lambda/durable/conformance/telemetry/ - TelemetryConformanceConfigTest.java # guard rejects null/blank; telemetry settings match the runner; telemetry-3 transform and content section + TelemetryConformanceConfigTest.java # guard rejects null/blank; telemetry settings match the runner; telemetry-3 transform and content section; telemetry-4 full-tree settings ``` The handlers use the real SDK API only. They construct no record and call no exporter method. A missing or wrong @@ -41,7 +43,8 @@ record is the plugin's defect. That defect is the signal the suite measures. The handler configuration is: one `CloudWatchLogsExporter`, emit mode `ON_COMPLETE`, sampling rate 1, operation detail `TOP_LEVEL`, and content input and output enabled. telemetry-3 differs in the content section only: input and output are -disabled, and one `OperationOverride.withResult("fetch-user", ...)` transform selects `userId` from the step result. +disabled, and one `OperationOverride.withResult("fetch-user", ...)` transform selects `userId` from the step result. telemetry-4 differs in the operation detail only: `FULL_TREE`, with input and output +enabled and no overrides. ## Template contract diff --git a/conformance-tests-telemetry/pom.xml b/conformance-tests-telemetry/pom.xml index 37f671e11..835e6f323 100644 --- a/conformance-tests-telemetry/pom.xml +++ b/conformance-tests-telemetry/pom.xml @@ -21,7 +21,7 @@ AWS Lambda Durable Execution SDK Telemetry Conformance Tests Java SDK handlers and SAM template for the Durable Execution Telemetry conformance - suite (telemetry-1, telemetry-2, telemetry-3). + suite (telemetry-1, telemetry-2, telemetry-3, telemetry-4). diff --git a/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/Telemetry4FullTreeMap.java b/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/Telemetry4FullTreeMap.java new file mode 100644 index 000000000..8c1dfce99 --- /dev/null +++ b/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/Telemetry4FullTreeMap.java @@ -0,0 +1,48 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 +package software.amazon.lambda.durable.conformance.telemetry; + +import java.util.List; +import software.amazon.lambda.durable.DurableConfig; +import software.amazon.lambda.durable.DurableContext; +import software.amazon.lambda.durable.DurableHandler; +import software.amazon.lambda.durable.config.MapConfig; + +/** + * Full-tree operation detail for requirement telemetry-4. + * + *

The map {@code process-items} runs one iteration per item with max concurrency 1. The item namer names each + * iteration {@code item-}. Each iteration runs one step {@code greet-}. The plugin runs with full-tree + * operation detail. So the record keeps the map, both iteration contexts, and both steps, one key per name. + * + *

The handler uses the event as the item list. The runner sends {@code [1, 2]}. The handler constructs no record and + * calls no exporter method. The plugin builds and exports the record. + */ +public final class Telemetry4FullTreeMap extends DurableHandler, List> { + + // Class initialization fails when the variable is unset. See TelemetryConformanceConfig.requireLogGroupName. + private static final String LOG_GROUP_NAME = + TelemetryConformanceConfig.requireLogGroupName(System.getenv(TelemetryConformanceConfig.LOG_GROUP_ENV)); + + @Override + protected DurableConfig createConfiguration() { + return TelemetryConformanceConfig.durableConfig( + TelemetryConformanceConfig.fullTreeMapTelemetryConfig(LOG_GROUP_NAME)); + } + + @Override + public List handleRequest(List input, DurableContext context) { + var config = MapConfig.builder() + .maxConcurrency(1) + .itemNamer((item, index) -> "item-" + item) + .build(); + return context.map( + TelemetryConformanceConfig.FULL_TREE_MAP_NAME, + input, + String.class, + (item, index, ctx) -> + ctx.step("greet-" + item, String.class, stepCtx -> "Hello, " + item + "!"), + config) + .results(); + } +} diff --git a/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfig.java b/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfig.java index a6c9d0988..b6ba080e4 100644 --- a/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfig.java +++ b/conformance-tests-telemetry/src/main/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfig.java @@ -27,6 +27,9 @@ final class TelemetryConformanceConfig { /** Name of the telemetry-3 step. The override and the step call must use the same string. */ static final String RESULT_SELECT_STEP_NAME = "fetch-user"; + /** Name of the telemetry-4 map. The handler's map call uses this string. */ + static final String FULL_TREE_MAP_NAME = "process-items"; + private TelemetryConformanceConfig() {} /** @@ -74,17 +77,53 @@ static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName) { * @return the plugin settings with the shared fields fixed and the given content */ static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName, ContentConfig content) { + return telemetryConfig(logGroupName, DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL, content); + } + + /** + * Builds the telemetry plugin settings with a caller-supplied operation detail and content section. + * + *

This overload holds the settings every handler shares: one CloudWatch Logs exporter, emit on completion, and a + * sampling rate of 1. The operation detail and content differ per requirement. telemetry-1 to telemetry-3 use + * top-level detail. telemetry-4 uses full-tree detail. So both are parameters. + * + * @param logGroupName the log group the exporter writes to + * @param operationDetail which operations the record keeps + * @param content the content section for the requirement the handler covers + * @return the plugin settings with the shared fields fixed + */ + static DurableExecutionTelemetryConfig telemetryConfig( + String logGroupName, + DurableExecutionTelemetryConfig.OperationDetail operationDetail, + ContentConfig content) { return DurableExecutionTelemetryConfig.builder() .addExporter(CloudWatchLogsExporter.builder() .logGroupName(logGroupName) .build()) .emitMode(DurableExecutionTelemetryConfig.EmitMode.ON_COMPLETE) .samplingRate(1.0) - .operationDetail(DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL) + .operationDetail(operationDetail) .content(content) .build(); } + /** + * Builds the telemetry-4 settings: the shared exporter and modes, full-tree operation detail, input and output + * included, and no overrides. + * + *

Full-tree detail keeps the map iteration contexts and the steps inside them. telemetry-4 requires all five + * operations in {@code operationsByName}, so no filter and no override may remove one. + * + * @param logGroupName the log group the exporter writes to + * @return the plugin settings the telemetry-4 handler uses + */ + static DurableExecutionTelemetryConfig fullTreeMapTelemetryConfig(String logGroupName) { + return telemetryConfig( + logGroupName, + DurableExecutionTelemetryConfig.OperationDetail.FULL_TREE, + ContentConfig.builder().input(true).output(true).build()); + } + /** * Builds the telemetry-3 settings: the shared exporter and modes, no input, no output, and one result override on * {@link #RESULT_SELECT_STEP_NAME} that applies {@link #selectUserId(Object)}. diff --git a/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java b/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java index 39198b194..7bd2be190 100644 --- a/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java +++ b/conformance-tests-telemetry/src/test/java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static software.amazon.lambda.durable.telemetry.DurableExecutionTelemetryConfig.EmitMode.ON_COMPLETE; +import static software.amazon.lambda.durable.telemetry.DurableExecutionTelemetryConfig.OperationDetail.FULL_TREE; import static software.amazon.lambda.durable.telemetry.DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL; import java.util.Map; @@ -103,4 +104,32 @@ void resultSelectTelemetryConfigOverridesTheStepResultWithTheSelectingTransform( assertNotNull(override.result()); assertEquals(Map.of("userId", "u-123"), override.result().apply(PARSED_FETCH_USER_RESULT)); } + + @Test + void fullTreeMapTelemetryConfigKeepsTheSharedSettings() { + var config = TelemetryConformanceConfig.fullTreeMapTelemetryConfig(LOG_GROUP); + assertEquals(1, config.exporters().size()); + assertInstanceOf(CloudWatchLogsExporter.class, config.exporters().get(0)); + assertEquals(ON_COMPLETE, config.emitMode()); + assertEquals(1.0, config.samplingRate()); + } + + @Test + void fullTreeMapTelemetryConfigUsesFullTreeDetailWithInputOutputAndNoOverrides() { + var config = TelemetryConformanceConfig.fullTreeMapTelemetryConfig(LOG_GROUP); + assertEquals(FULL_TREE, config.operationDetail()); + assertTrue(config.content().includeInput()); + assertTrue(config.content().includeOutput()); + assertTrue(config.content().overrides().isEmpty()); + } + + @Test + void otherConfigsStillUseTopLevelDetail() { + assertEquals( + TOP_LEVEL, + TelemetryConformanceConfig.telemetryConfig(LOG_GROUP).operationDetail()); + assertEquals( + TOP_LEVEL, + TelemetryConformanceConfig.resultSelectTelemetryConfig(LOG_GROUP).operationDetail()); + } } diff --git a/conformance-tests-telemetry/template.yaml b/conformance-tests-telemetry/template.yaml index aa0b7aab4..085efdfe7 100644 --- a/conformance-tests-telemetry/template.yaml +++ b/conformance-tests-telemetry/template.yaml @@ -65,3 +65,14 @@ Resources: CodeUri: . Handler: software.amazon.lambda.durable.conformance.telemetry.Telemetry3ResultSelect Role: !Ref LambdaExecutionRoleArn + + Telemetry4FullTreeMap: + Type: AWS::Serverless::Function + DependsOn: TelemetryLogGroup + TestingMetadata: + TestDescription: + - telemetry-4 + Properties: + CodeUri: . + Handler: software.amazon.lambda.durable.conformance.telemetry.Telemetry4FullTreeMap + Role: !Ref LambdaExecutionRoleArn