Repository navigation
feat(telemetry): add telemetry-2 failure handler #876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
740bcb4
feat(telemetry): add telemetry-2 failure handler
hln33 3d4eba3
docs(telemetry): telemetry-2 asserts error presence; pin the shared w…
hln33 ecb5e34
refactor(telemetry): share the handler setup and test the log-group g…
hln33 0ccc30f
test(telemetry): keep the config unit test off the Lambda client
hln33 d5dc725
style(telemetry): static-import the enum constants in the config test
hln33 0bb88f5
fix(telemetry): catch StepFailedException in Telemetry2Failure
hln33 e8a5b91
fix(telemetry): catch the rebuilt RuntimeException in Telemetry2Failure
hln33 a862370
ci(telemetry): pin the suite to the #179 merge commit
hln33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...src/main/java/software/amazon/lambda/durable/conformance/telemetry/Telemetry2Failure.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package software.amazon.lambda.durable.conformance.telemetry; | ||
|
|
||
| import software.amazon.lambda.durable.DurableConfig; | ||
| import software.amazon.lambda.durable.DurableContext; | ||
| import software.amazon.lambda.durable.DurableHandler; | ||
| import software.amazon.lambda.durable.config.StepConfig; | ||
| import software.amazon.lambda.durable.retry.RetryStrategies; | ||
|
|
||
| /** | ||
| * Failed single-step scenario for requirement telemetry-2. | ||
| * | ||
| * <p>The step {@code charge} throws {@code card declined}. The retry strategy declines, so the step fails on its first | ||
| * attempt. The handler catches the step error and throws {@code payment failed} with the step error as its cause. So | ||
| * the execution fails and the exported record carries an {@code error} on the execution and on | ||
| * {@code operationsByName.charge}. Error names and cause depth differ per SDK by design, so telemetry-2 asserts only | ||
| * that each error is an object. It pins the messages {@code card declined} and {@code payment failed} through the core | ||
| * execution-result and history sections. Do not change them. | ||
| * | ||
| * <p>The handler configures the telemetry plugin exactly as {@link Telemetry1Success}. It constructs no record and | ||
| * calls no exporter method. The plugin builds and exports the record. | ||
| */ | ||
| public final class Telemetry2Failure extends DurableHandler<Telemetry2Failure.Input, Void> { | ||
|
|
||
| // 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(LOG_GROUP_NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public Void handleRequest(Input input, DurableContext context) { | ||
| try { | ||
| context.step( | ||
| "charge", | ||
| Void.class, | ||
| step -> { | ||
| throw new RuntimeException("card declined"); | ||
| }, | ||
| StepConfig.builder() | ||
| .retryStrategy(RetryStrategies.Presets.NO_RETRY) | ||
| .build()); | ||
| } catch (RuntimeException stepError) { | ||
| // The SDK rebuilds the step's original exception from the checkpoint and rethrows it, so the | ||
| // step surfaces as RuntimeException("card declined"). StepFailedException is only the fallback | ||
| // when that rebuild fails. Catching StepFailedException would let "card declined" escape. | ||
| throw new RuntimeException("payment failed", stepError); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** Event payload: {"value": 41}. */ | ||
| public static final class Input { | ||
| public int value; | ||
|
|
||
| public Input() {} | ||
| } | ||
| } | ||
79 changes: 79 additions & 0 deletions
79
...java/software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package software.amazon.lambda.durable.conformance.telemetry; | ||
|
|
||
| import software.amazon.lambda.durable.DurableConfig; | ||
| import software.amazon.lambda.durable.telemetry.ContentConfig; | ||
| import software.amazon.lambda.durable.telemetry.DurableExecutionTelemetry; | ||
| import software.amazon.lambda.durable.telemetry.DurableExecutionTelemetryConfig; | ||
| import software.amazon.lambda.durable.telemetry.exporters.CloudWatchLogsExporter; | ||
|
|
||
| /** | ||
| * Shared plugin setup for the telemetry conformance handlers. | ||
| * | ||
| * <p>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. | ||
| */ | ||
| final class TelemetryConformanceConfig { | ||
|
|
||
| /** Environment variable that names the log group the runner reads. */ | ||
| static final String LOG_GROUP_ENV = "TELEMETRY_LOG_GROUP_NAME"; | ||
|
|
||
| private TelemetryConformanceConfig() {} | ||
|
|
||
| /** | ||
| * Validates the configured log group name. | ||
| * | ||
| * <p>The deployed function must export to the log group the runner reads. A missing name would produce a function | ||
| * that exports nowhere, and the runner would time out instead of reporting a configuration error. So this method | ||
| * rejects a null or blank name, and the caller fails class initialization. | ||
| * | ||
| * @param logGroupName the value of {@link #LOG_GROUP_ENV}, possibly null | ||
| * @return the same value when it is set and not blank | ||
| * @throws IllegalStateException when the value is null or blank | ||
| */ | ||
| static String requireLogGroupName(String logGroupName) { | ||
| if (logGroupName == null || logGroupName.isBlank()) { | ||
| throw new IllegalStateException(LOG_GROUP_ENV + " must be set"); | ||
| } | ||
| return logGroupName; | ||
| } | ||
|
|
||
| /** | ||
| * Builds the telemetry plugin settings: one CloudWatch Logs exporter for the given log group, emit on completion, | ||
| * sample every execution, top-level operation detail, input and output included. | ||
| * | ||
| * <p>This method constructs no client. The exporter creates its CloudWatch Logs client on first export, and the | ||
| * 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 | ||
| */ | ||
| static DurableExecutionTelemetryConfig telemetryConfig(String logGroupName) { | ||
| return DurableExecutionTelemetryConfig.builder() | ||
| .addExporter(CloudWatchLogsExporter.builder() | ||
| .logGroupName(logGroupName) | ||
| .build()) | ||
| .emitMode(DurableExecutionTelemetryConfig.EmitMode.ON_COMPLETE) | ||
| .samplingRate(1.0) | ||
| .operationDetail(DurableExecutionTelemetryConfig.OperationDetail.TOP_LEVEL) | ||
| .content(ContentConfig.builder().input(true).output(true).build()) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the handler configuration with the telemetry plugin from {@link #telemetryConfig(String)}. | ||
| * | ||
| * <p>{@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. Tests check {@link #telemetryConfig(String)} instead. | ||
| * | ||
| * @param logGroupName the log group the exporter writes to | ||
| * @return the configuration a telemetry conformance handler returns from {@code createConfiguration()} | ||
| */ | ||
| static DurableConfig durableConfig(String logGroupName) { | ||
| return DurableConfig.builder() | ||
| .withPlugins(DurableExecutionTelemetry.durableExecutionTelemetry(telemetryConfig(logGroupName))) | ||
| .build(); | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
.../software/amazon/lambda/durable/conformance/telemetry/TelemetryConformanceConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| package software.amazon.lambda.durable.conformance.telemetry; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
| 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 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.exporters.CloudWatchLogsExporter; | ||
|
|
||
| /** | ||
| * Tests the shared handler setup through the helper with explicit values. | ||
| * | ||
| * <p>The handlers read the log group name in a static initializer, so the guard is tested here, not through the | ||
| * environment. {@code durableConfig} builds a {@code DurableConfig}, whose constructor creates the default Lambda | ||
| * client and sends a warm-up request. So these tests check {@code telemetryConfig}, which constructs no client. | ||
| */ | ||
| class TelemetryConformanceConfigTest { | ||
|
|
||
| private static final String LOG_GROUP = "/aws/lambda/durable-execution-telemetry"; | ||
|
|
||
| @ParameterizedTest | ||
| @NullSource | ||
| @ValueSource(strings = {"", " ", "\t"}) | ||
| void requireLogGroupNameRejectsMissingValue(String value) { | ||
| var e = assertThrows(IllegalStateException.class, () -> TelemetryConformanceConfig.requireLogGroupName(value)); | ||
| assertEquals("TELEMETRY_LOG_GROUP_NAME must be set", e.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void requireLogGroupNameReturnsSetValue() { | ||
| assertSame(LOG_GROUP, TelemetryConformanceConfig.requireLogGroupName(LOG_GROUP)); | ||
| } | ||
|
|
||
| @Test | ||
| void telemetryConfigUsesOneCloudWatchLogsExporter() { | ||
| var config = TelemetryConformanceConfig.telemetryConfig(LOG_GROUP); | ||
| assertEquals(1, config.exporters().size()); | ||
| // The exporter exposes no log group accessor, so the name is not asserted here. The handler passes its | ||
| // static LOG_GROUP_NAME straight through, and the deployed run matches no record if the name is wrong. | ||
| assertInstanceOf(CloudWatchLogsExporter.class, config.exporters().get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| void telemetryConfigMatchesTheRunnerExpectations() { | ||
| var config = TelemetryConformanceConfig.telemetryConfig(LOG_GROUP); | ||
| // The runner reads one record per execution with its input and output. These four settings produce that. | ||
| assertEquals(ON_COMPLETE, config.emitMode()); | ||
| assertEquals(1.0, config.samplingRate()); | ||
| assertEquals(TOP_LEVEL, config.operationDetail()); | ||
| assertTrue(config.content().includeInput()); | ||
| assertTrue(config.content().includeOutput()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.