mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambdaweb): report init failures as AWS does (#5960)
* fix(lambdaweb): tell why a Web Function app failed to start as AWS does An app that exits at start with a status other than 0 now gets Runtime.ExitError, and an app that cannot find a module at import gets Runtime.ImportCodeError. A failed import writes the one ERROR event AWS writes in place of Node's stack. * fix(lambdaweb): read the init error type from a file so any exit status keeps its meaning * fix(lambdaweb): write the init error type where any user can * fix(lambdaweb): clear an init error type left in the runtime image
This commit is contained in:
1 parent
9ceedde585
commit
b6bc3032f1
6 files changed
+99
-6
No files matched your search
+36
-2
@@ -66,6 +66,8 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
const [host, port] = process.env.AWS_LAMBDA_HTTP_ENDPOINT.split(':');
|
||||
console.log('starting');
|
||||
if (process.env.MODE === 'throw') { throw new Error('init boom'); }
|
||||
if (process.env.MODE === 'exit') { process.exit(1); }
|
||||
if (process.env.MODE === 'missing') { require('no-such-module'); }
|
||||
http.createServer((req, res) => {
|
||||
if (req.url.startsWith('/log')) {
|
||||
console.info({route: 'log', main: require.main === module, argv: process.argv.slice(1)});
|
||||
@@ -504,8 +506,40 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
assertEquals("WARN", initReport.getString("level"));
|
||||
assertEquals("failure", initReport.getString("record.status"));
|
||||
assertEquals("Application.InitCodeError", initReport.getString("record.errorType"));
|
||||
assertTrue(events.stream().anyMatch(event -> event.contains("\"message\":\"starting\"")), events.toString());
|
||||
assertTrue(events.stream().anyMatch(event -> event.contains("init boom")), events.toString());
|
||||
List<JsonPath> output = events.stream().filter(event -> !isPlatformEvent(event)).map(JsonPath::from).toList();
|
||||
assertEquals(List.of("ERROR Application.InitCodeError: could not load customer code: init boom", "INFO starting"),
|
||||
output.stream().map(event -> event.getString("level") + " " + event.getString("message")).sorted()
|
||||
.toList(), events.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(180)
|
||||
void anAppThatExitsWithAnErrorAtStartGetsTheExitErrorPage() throws Exception {
|
||||
String domain = createFunction(30, 64, "WARN", "exit");
|
||||
String group = "/aws/lambda/web/" + functionName + ".local";
|
||||
given().header("Host", domain).when().get("/").then().statusCode(502)
|
||||
.header("lambda-web-error-type", "Runtime.ExitError");
|
||||
|
||||
List<String> events = awaitLogEvents(group, awaitLogStream(group),
|
||||
each -> types(each).contains("platform.initReport"));
|
||||
assertEquals("Runtime.ExitError", platformEvent(events, "platform.initReport").getString("record.errorType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(180)
|
||||
void anAppThatCannotFindAModuleGetsTheImportCodeErrorPage() throws Exception {
|
||||
String domain = createFunction(30, 64, "WARN", "missing");
|
||||
String group = "/aws/lambda/web/" + functionName + ".local";
|
||||
given().header("Host", domain).when().get("/").then().statusCode(502)
|
||||
.header("lambda-web-error-type", "Runtime.ImportCodeError");
|
||||
|
||||
List<String> events = awaitLogEvents(group, awaitLogStream(group), each -> types(each).contains(
|
||||
"platform.initReport") && each.stream().anyMatch(event -> event.contains("ImportCodeError:")));
|
||||
assertEquals("Runtime.ImportCodeError",
|
||||
platformEvent(events, "platform.initReport").getString("record.errorType"));
|
||||
assertTrue(events.stream().anyMatch(event -> event.contains("\"message\":\"Runtime.ImportCodeError: could not"
|
||||
+ " load customer code: Cannot find module 'no-such-module'\\nRequire stack:\\n- /var/task/index.js."
|
||||
+ " The entrypoint must be")), events.toString());
|
||||
}
|
||||
|
||||
private static boolean isPlatformEvent(String event) {
|
||||
|
||||
+2
@@ -23,7 +23,9 @@ class LambdaWebErrorPagesTest {
|
||||
assertEquals(236, length(LambdaWebErrorPages.ORIGIN_REQUEST_ERROR));
|
||||
assertEquals(228, length(LambdaWebErrorPages.TIMEOUT_LISTEN_ERROR));
|
||||
assertEquals(228, length(LambdaWebErrorPages.INIT_CODE_ERROR));
|
||||
assertEquals(228, length(LambdaWebErrorPages.IMPORT_CODE_ERROR));
|
||||
assertEquals(228, length(LambdaWebErrorPages.RUNTIME_EXIT));
|
||||
assertEquals(228, length(LambdaWebErrorPages.RUNTIME_EXIT_ERROR));
|
||||
assertEquals(237, length(LambdaWebErrorPages.ENDPOINT_MAX_ENV_THROTTLE));
|
||||
assertEquals(237, length(LambdaWebErrorPages.ENDPOINT_REQUEST_THROTTLE));
|
||||
assertEquals(180, LambdaWebErrorPages.MALFORMED_REQUEST_HTML.getBytes(StandardCharsets.UTF_8).length);
|
||||
|
||||
Reference in new issue
Block a user