Implement Phase 0b base project against the frozen test contract
All seven services (gateway, ledger, fraud, sanctions, insights, notifier, audit), db/schema.sql plus optional_indexes.sql, scripts/seed.py and smoke.py, the gateway-served frontend, and docker-compose.yml. Plain-text stdlib logging and a weak manual X-Request-Id only -- no observability yet, by design, per test_no_observability.py. Implements all 13 named chaos-flag pathologies from docs/PATHOLOGIES.md behind Redis-backed runtime flags. make smoke and make test-contract pass; make test-baseline and make test-pathology pass except for a handful of load-sensitive tests documented in tests/README.md rather than papered over.
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
const accountSelect = document.getElementById("account-select");
|
||||
const txForm = document.getElementById("tx-form");
|
||||
const resultJson = document.getElementById("result-json");
|
||||
const resultRtt = document.getElementById("result-rtt");
|
||||
const resultRequestId = document.getElementById("result-request-id");
|
||||
const burstButton = document.getElementById("burst-button");
|
||||
const burstN = document.getElementById("burst-n");
|
||||
const burstTableBody = document.querySelector("#burst-table tbody");
|
||||
const chaosFlagsDiv = document.getElementById("chaos-flags");
|
||||
const healthStrip = document.getElementById("health-strip");
|
||||
|
||||
async function loadAccounts() {
|
||||
const resp = await fetch("/api/accounts");
|
||||
const accounts = await resp.json();
|
||||
accountSelect.innerHTML = accounts
|
||||
.slice(0, 200)
|
||||
.map((a) => `<option value="${a.id}">${a.holder_name} (${a.currency})</option>`)
|
||||
.join("");
|
||||
}
|
||||
|
||||
txForm.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const payload = {
|
||||
account_id: accountSelect.value,
|
||||
kind: document.querySelector('input[name="kind"]:checked').value,
|
||||
amount_minor: Number(document.getElementById("amount-input").value),
|
||||
currency: "EUR",
|
||||
merchant_name: document.getElementById("merchant-input").value,
|
||||
};
|
||||
const start = performance.now();
|
||||
const resp = await fetch("/api/transactions", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const rtt = performance.now() - start;
|
||||
const body = await resp.json();
|
||||
resultRtt.textContent = rtt.toFixed(1);
|
||||
resultRequestId.textContent = body.request_id || "--";
|
||||
resultJson.textContent = JSON.stringify(body, null, 2);
|
||||
});
|
||||
|
||||
function percentile(sorted, p) {
|
||||
if (sorted.length === 0) return 0;
|
||||
const rank = Math.max(1, Math.min(sorted.length, Math.ceil(p * sorted.length)));
|
||||
return sorted[rank - 1];
|
||||
}
|
||||
|
||||
burstButton.addEventListener("click", async () => {
|
||||
const n = Number(burstN.value);
|
||||
const accounts = Array.from(accountSelect.options).map((o) => o.value);
|
||||
burstTableBody.innerHTML = `<tr><td colspan="8">running ${n} requests...</td></tr>`;
|
||||
|
||||
const latencies = [];
|
||||
let success = 0;
|
||||
let errors = 0;
|
||||
|
||||
await Promise.all(
|
||||
Array.from({ length: n }, async () => {
|
||||
const accountId = accounts[Math.floor(Math.random() * accounts.length)];
|
||||
const start = performance.now();
|
||||
try {
|
||||
const resp = await fetch("/api/transactions", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
account_id: accountId,
|
||||
kind: "purchase",
|
||||
amount_minor: 500,
|
||||
currency: "EUR",
|
||||
merchant_name: "Load Burst",
|
||||
}),
|
||||
});
|
||||
latencies.push(performance.now() - start);
|
||||
if (resp.ok) success += 1;
|
||||
else errors += 1;
|
||||
} catch (e) {
|
||||
latencies.push(performance.now() - start);
|
||||
errors += 1;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
latencies.sort((a, b) => a - b);
|
||||
const mean = latencies.reduce((a, b) => a + b, 0) / latencies.length;
|
||||
const row = [
|
||||
latencies.length,
|
||||
success,
|
||||
errors,
|
||||
latencies[0].toFixed(1),
|
||||
mean.toFixed(1),
|
||||
percentile(latencies, 0.5).toFixed(1),
|
||||
percentile(latencies, 0.95).toFixed(1),
|
||||
latencies[latencies.length - 1].toFixed(1),
|
||||
];
|
||||
burstTableBody.innerHTML = `<tr>${row.map((v) => `<td>${v}</td>`).join("")}</tr>`;
|
||||
});
|
||||
|
||||
async function loadChaos() {
|
||||
const resp = await fetch("/api/admin/chaos");
|
||||
const { flags } = await resp.json();
|
||||
chaosFlagsDiv.innerHTML = Object.entries(flags)
|
||||
.map(
|
||||
([flag, enabled]) => `
|
||||
<label>
|
||||
<input type="checkbox" data-flag="${flag}" ${enabled ? "checked" : ""}>
|
||||
${flag}
|
||||
</label>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
chaosFlagsDiv.querySelectorAll("input[type=checkbox]").forEach((el) => {
|
||||
el.addEventListener("change", async () => {
|
||||
await fetch("/api/admin/chaos", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ flag: el.dataset.flag, enabled: el.checked }),
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll("#chaos-profiles button").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
await fetch("/api/admin/chaos/profile", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ profile: btn.dataset.profile }),
|
||||
});
|
||||
await loadChaos();
|
||||
});
|
||||
});
|
||||
|
||||
async function pollHealth() {
|
||||
try {
|
||||
const resp = await fetch("/api/health/all");
|
||||
const { services } = await resp.json();
|
||||
healthStrip.innerHTML = Object.entries(services)
|
||||
.map(([name, status]) => `<span class="dot ${status === "ok" ? "green" : "red"}">${name}</span>`)
|
||||
.join("");
|
||||
} catch (e) {
|
||||
// ignore transient polling failures
|
||||
}
|
||||
}
|
||||
|
||||
loadAccounts();
|
||||
loadChaos();
|
||||
pollHealth();
|
||||
setInterval(pollHealth, 5000);
|
||||
@@ -0,0 +1,80 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ledgerline</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Ledgerline</h1>
|
||||
<p class="tagline">a deliberately imperfect payments backend</p>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section id="submit-panel">
|
||||
<h2>Submit a transaction</h2>
|
||||
<form id="tx-form">
|
||||
<label>Account
|
||||
<select id="account-select"></select>
|
||||
</label>
|
||||
<label>Amount (minor units)
|
||||
<input type="number" id="amount-input" value="1000" min="0">
|
||||
</label>
|
||||
<label>Merchant
|
||||
<input type="text" id="merchant-input" value="Corner Store">
|
||||
</label>
|
||||
<fieldset>
|
||||
<legend>Kind</legend>
|
||||
<label><input type="radio" name="kind" value="deposit" checked> deposit</label>
|
||||
<label><input type="radio" name="kind" value="withdrawal"> withdrawal</label>
|
||||
<label><input type="radio" name="kind" value="purchase"> purchase</label>
|
||||
</fieldset>
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section id="result-panel">
|
||||
<h2>Result</h2>
|
||||
<p>Round-trip: <span id="result-rtt">--</span> ms · request_id: <code id="result-request-id">--</code></p>
|
||||
<pre id="result-json">(nothing yet)</pre>
|
||||
</section>
|
||||
|
||||
<section id="load-panel">
|
||||
<h2>Load burst</h2>
|
||||
<label>N
|
||||
<select id="burst-n">
|
||||
<option value="10">10</option>
|
||||
<option value="50">50</option>
|
||||
<option value="200">200</option>
|
||||
</select>
|
||||
</label>
|
||||
<button id="burst-button">Fire burst</button>
|
||||
<table id="burst-table">
|
||||
<thead>
|
||||
<tr><th>count</th><th>success</th><th>errors</th><th>min</th><th>mean</th><th>p50</th><th>p95</th><th>max</th></tr>
|
||||
</thead>
|
||||
<tbody><tr><td colspan="8">no burst run yet</td></tr></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section id="chaos-panel">
|
||||
<h2>Chaos</h2>
|
||||
<div id="chaos-flags"></div>
|
||||
<div id="chaos-profiles">
|
||||
<button data-profile="clean">clean</button>
|
||||
<button data-profile="light">light</button>
|
||||
<button data-profile="nightmare">nightmare</button>
|
||||
<button data-profile="random">random</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="health-panel">
|
||||
<h2>Service health</h2>
|
||||
<div id="health-strip"></div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="/static/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,184 @@
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #0f1117;
|
||||
--panel: #171a23;
|
||||
--border: #2a2e3a;
|
||||
--text: #d8dce6;
|
||||
--muted: #7b8296;
|
||||
--accent: #5fd0a8;
|
||||
--danger: #e0685f;
|
||||
--mono: "SF Mono", "Fira Code", Consolas, monospace;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: var(--mono);
|
||||
margin: 0;
|
||||
padding: 0 1.5rem 3rem;
|
||||
}
|
||||
|
||||
header {
|
||||
padding: 2rem 0 1rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
header h1 {
|
||||
margin: 0;
|
||||
font-size: 1.6rem;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.tagline {
|
||||
color: var(--muted);
|
||||
margin: 0.25rem 0 0;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
main {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||
gap: 1.5rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
section {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
padding: 1rem 1.25rem;
|
||||
}
|
||||
|
||||
section h2 {
|
||||
margin-top: 0;
|
||||
font-size: 1rem;
|
||||
color: var(--accent);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.6rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
input, select, button {
|
||||
font-family: var(--mono);
|
||||
background: #0c0e13;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 0.4rem 0.5rem;
|
||||
margin-top: 0.2rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
margin-bottom: 0.6rem;
|
||||
}
|
||||
|
||||
fieldset label {
|
||||
display: inline-block;
|
||||
width: auto;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
background: var(--accent);
|
||||
color: #0c0e13;
|
||||
font-weight: 600;
|
||||
border: none;
|
||||
margin-top: 0.5rem;
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
#chaos-profiles {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
#chaos-profiles button {
|
||||
width: auto;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
pre#result-json {
|
||||
background: #0c0e13;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
padding: 0.75rem;
|
||||
overflow-x: auto;
|
||||
font-size: 0.8rem;
|
||||
max-height: 260px;
|
||||
}
|
||||
|
||||
code {
|
||||
background: #0c0e13;
|
||||
padding: 0.1rem 0.3rem;
|
||||
border-radius: 3px;
|
||||
user-select: all;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 0.75rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid var(--border);
|
||||
padding: 0.35rem 0.5rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
th:first-child, td:first-child {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#chaos-flags label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
#chaos-flags input {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#health-strip {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.dot {
|
||||
border-radius: 999px;
|
||||
padding: 0.25rem 0.6rem;
|
||||
font-size: 0.75rem;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.dot.green {
|
||||
color: var(--accent);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.dot.red {
|
||||
color: var(--danger);
|
||||
border-color: var(--danger);
|
||||
}
|
||||
Reference in New Issue
Block a user