The step {@code fetch-user} returns {@code {userId, email, token}}. The plugin exports an operation's result only + * when an {@code OperationOverride.withResult} transform opts the operation in. The transform + * {@link TelemetryConformanceConfig#selectUserId(Object)} returns a new map that holds {@code userId} alone. So the + * record's {@code operationsByName.fetch-user.result} is exactly {@code {"userId": "u-123"}}, and {@code email} and + * {@code token} never reach CloudWatch Logs. + * + *
The content section also excludes input and output. telemetry-3 requires that the record carry no {@code input} + * and no {@code output} key. The execution result still holds all three keys, so the core {@code ExpectedResult} check + * proves the transform removed data from the record, not from the step. + * + *
The handler constructs no record and calls no exporter method. The plugin builds and exports the record.
+ */
+public final class Telemetry3ResultSelect
+ extends DurableHandler Every handler in this module exports to the same log group with the same plugin settings. The runner reads that
- * log group and compares the record to the requirement. A handler with different settings would produce a record the
- * runner cannot match. So the settings live here once and each handler calls these methods.
+ * Every handler in this module exports to the same log group. Every handler shares the exporter, emit mode, sampling
+ * rate and operation detail. The content section differs per requirement: telemetry-1 and telemetry-2 include input and
+ * output; telemetry-3 excludes them and adds one result transform. The runner reads that log group and compares the
+ * record to the requirement. A handler with different shared settings would produce a record the runner cannot match.
+ * So the shared settings live here once and each handler calls these methods.
*/
final class TelemetryConformanceConfig {
/** Environment variable that names the log group the runner reads. */
static final String LOG_GROUP_ENV = "TELEMETRY_LOG_GROUP_NAME";
+ /** 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";
+
private TelemetryConformanceConfig() {}
/**
@@ -48,9 +55,25 @@ static String requireLogGroupName(String logGroupName) {
* settings object is a plain value. So a unit test can call it with no credentials and no network.
*
* @param logGroupName the log group the exporter writes to
- * @return the plugin settings every handler in this module uses
+ * @return the plugin settings the telemetry-1 and telemetry-2 handlers use
*/
static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName) {
+ return telemetryConfig(
+ logGroupName, ContentConfig.builder().input(true).output(true).build());
+ }
+
+ /**
+ * Builds the telemetry plugin settings with a caller-supplied content section.
+ *
+ * Every handler shares the exporter, emit mode, sampling rate, and operation detail. Only the content section
+ * differs per requirement. telemetry-1 and telemetry-2 include input and output. telemetry-3 excludes both and adds
+ * a per-operation result override. So the shared settings live here and the content is a parameter.
+ *
+ * @param logGroupName the log group the exporter writes to
+ * @param content the content section for the requirement the handler covers
+ * @return the plugin settings with the shared fields fixed and the given content
+ */
+ static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName, ContentConfig content) {
return DurableExecutionTelemetryConfig.builder()
.addExporter(CloudWatchLogsExporter.builder()
.logGroupName(logGroupName)
@@ -58,10 +81,44 @@ static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName) {
.emitMode(DurableExecutionTelemetryConfig.EmitMode.ON_COMPLETE)
.samplingRate(1.0)
.operationDetail(DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL)
- .content(ContentConfig.builder().input(true).output(true).build())
+ .content(content)
.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)}.
+ *
+ * telemetry-3 requires that the record carry no {@code input} and no {@code output} key, and that
+ * {@code operationsByName.fetch-user.result} hold exactly {@code {"userId": "u-123"}}.
+ *
+ * @param logGroupName the log group the exporter writes to
+ * @return the plugin settings the telemetry-3 handler uses
+ */
+ static DurableExecutionTelemetryConfig resultSelectTelemetryConfig(String logGroupName) {
+ return telemetryConfig(
+ logGroupName,
+ ContentConfig.builder()
+ .input(false)
+ .output(false)
+ .addOverride(OperationOverride.withResult(
+ RESULT_SELECT_STEP_NAME, TelemetryConformanceConfig::selectUserId))
+ .build());
+ }
+
+ /**
+ * Keeps {@code userId} and drops every other key of a parsed step result.
+ *
+ * The plugin JSON-parses the checkpointed step result before it calls the transform. So the argument is a
+ * detached {@code Map}, not the handler's output class and not a JSON string.
+ *
+ * @param result the parsed step result: a {@code Map} with {@code userId}, {@code email}, and {@code token}
+ * @return a new single-entry map
+ */
+ static Object selectUserId(Object result) {
+ return Map.of("userId", ((Map, ?>) result).get("userId"));
+ }
+
/**
* Builds the handler configuration with the telemetry plugin from {@link #telemetryConfig(String)}.
*
@@ -72,8 +129,21 @@ static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName) {
* @return the configuration a telemetry conformance handler returns from {@code createConfiguration()}
*/
static DurableConfig durableConfig(String logGroupName) {
+ return durableConfig(telemetryConfig(logGroupName));
+ }
+
+ /**
+ * Builds the handler configuration with the telemetry plugin from the given settings.
+ *
+ * {@code DurableConfig.build()} constructs the default Lambda client, and that constructor sends one warm-up
+ * request. So this method is for the deployed handler only.
+ *
+ * @param telemetryConfig the plugin settings, from one of the {@code telemetryConfig} overloads
+ * @return the configuration a telemetry conformance handler returns from {@code createConfiguration()}
+ */
+ static DurableConfig durableConfig(DurableExecutionTelemetryConfig telemetryConfig) {
return DurableConfig.builder()
- .withPlugins(DurableExecutionTelemetry.durableExecutionTelemetry(telemetryConfig(logGroupName)))
+ .withPlugins(DurableExecutionTelemetry.durableExecutionTelemetry(telemetryConfig))
.build();
}
}
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 df757f759..39198b194 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
@@ -3,17 +3,21 @@
package software.amazon.lambda.durable.conformance.telemetry;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
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.TOP_LEVEL;
+import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
+import software.amazon.lambda.durable.telemetry.OperationOverride;
import software.amazon.lambda.durable.telemetry.exporters.CloudWatchLogsExporter;
/**
@@ -26,6 +30,9 @@
class TelemetryConformanceConfigTest {
private static final String LOG_GROUP = "/aws/lambda/durable-execution-telemetry";
+ // The shape the plugin hands to a result transform: the checkpointed step result, JSON-parsed to a Map.
+ private static final Map