forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { local, run, compose } from "./runtime";
|
||||
const error = JSON.parse(
|
||||
await readFile(resolve(local, "diagnostics/preflight-error.json"), "utf8"),
|
||||
);
|
||||
const allowed = [
|
||||
"COMMAND_FAILED_curl_22",
|
||||
"COMMAND_FAILED_curl_7",
|
||||
"COMMAND_FAILED_curl_35",
|
||||
"READINESS_TIMEOUT_API1",
|
||||
"READINESS_TIMEOUT_API2",
|
||||
"PUBLIC_READINESS_FAILED",
|
||||
"INVALID_SERVICE_NETWORK",
|
||||
"INVALID_SERVICE_ID",
|
||||
"MATRIX_POSITIVE_API1-GATEWAY",
|
||||
"MATRIX_POSITIVE_API2-GATEWAY",
|
||||
"NEGATIVE_FAILED_FOR_UNEXPECTED_REASON",
|
||||
];
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
cause: allowed.includes(error.message) ? error.message : "OTHER_PRIVATE",
|
||||
}),
|
||||
);
|
||||
for (const service of ["api1", "api2", "worker"]) {
|
||||
const ids = await compose(["ps", "-a", "-q", service]);
|
||||
for (const id of ids.out.trim().split(/\s+/).filter(Boolean)) {
|
||||
const state = JSON.parse((await run(["docker", "inspect", id])).out)[0];
|
||||
const logs = await run(["docker", "logs", id], { allowFailure: true }),
|
||||
events: Record<string, number> = {};
|
||||
for (const line of (logs.out + "\n" + logs.err).split("\n")) {
|
||||
try {
|
||||
const event = JSON.parse(line).event;
|
||||
if (["secret_freshness_failed"].includes(event))
|
||||
events[event] = (events[event] ?? 0) + 1;
|
||||
} catch {}
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
service,
|
||||
running: state.State.Running,
|
||||
exit: state.State.ExitCode,
|
||||
restarts: state.RestartCount,
|
||||
events,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user