feat: harden Gate 1 manifests and runbook

- add read-only make gate1-check: permissions, guardrails, dry-run, Secret keys
- set numeric runAsUser/runAsGroup (SKE non-numeric user caveat), pin cloudflared and use HTTP/2
- align ML env with PULSECAST_* and wire CONTROL_TOKEN for API/ML training proxy
- fix service worktree paths and smoke.sh executable bit
- pin k6 v2.0.0 for xk6-sse, fix closed-connection metric and initial scenario latency
- rewrite docs/deploy.md as an exact copy-paste Gate 1 checklist
This commit is contained in:
Noel Sabia committed 2026-11-14 05:10:41 +01:00
1 parent 55dfe8b616
commit 5b199f8fe3
13 files changed
+1231 -235

No files matched your search

+20 -25
View File
@@ -2,17 +2,17 @@
//
// The native k6 http module buffers the whole response, so it cannot read
// Server-Sent Events incrementally. This script uses the community
// `k6/x/sse` extension (github.com/phymbert/xk6-sse). Recent k6 releases
// resolve `k6/x/sse` automatically; otherwise build a binary with:
// `k6/x/sse` extension (github.com/phymbert/xk6-sse), which is not in the
// stock k6 binary. Build the pinned binary once:
// make k6-build
//
// Run:
// API_URL=https://api.pulse.noelsabia.dev k6 run k6/sse.js
// API_URL=https://api.pulse.noelsabia.dev ./k6/k6-sse run k6/sse.js
// make load
//
// Recorded metrics:
// sse_connections_opened counter, expected >= SSE_VUS (120)
// sse_connections_active gauge, peak should reach 120
// sse_connections_closed counter, expected to equal connections_opened
// sse_open_success rate of VUs that opened a stream
// sse_event_latency p95 server-timestamp-to-client latency, ms
// sse_scenario_latency same, scenario events only (if any occur)
@@ -24,7 +24,7 @@
import http from 'k6/http';
import sse from 'k6/x/sse';
import { check } from 'k6';
import { Counter, Gauge, Rate, Trend } from 'k6/metrics';
import { Counter, Rate, Trend } from 'k6/metrics';
const API_URL = (__ENV.API_URL || 'https://api.pulse.noelsabia.dev').replace(/\/+$/, '');
const STREAM_URL = __ENV.SSE_URL || `${API_URL}/api/stream`;
@@ -33,7 +33,7 @@ const HOLD_PINGS = Math.max(1, Number(__ENV.SSE_HOLD_PINGS || 20));
const MAX_DURATION = __ENV.SSE_MAX_DURATION || '6m';
const connectionsOpened = new Counter('sse_connections_opened');
const connectionsActive = new Gauge('sse_connections_active');
const connectionsClosed = new Counter('sse_connections_closed');
const openSuccess = new Rate('sse_open_success');
const connectionErrors = new Counter('sse_connection_errors');
const eventsReceived = new Counter('sse_events_received');
@@ -73,23 +73,10 @@ export function setup() {
export default function () {
let opened = false;
let active = false;
let closedByUs = false;
let firstScenario = true;
let pings = 0;
const markActive = () => {
if (!active) {
active = true;
connectionsActive.add(1);
}
};
const markInactive = () => {
if (active) {
active = false;
connectionsActive.add(-1);
}
};
const params = {
method: 'GET',
headers: {
@@ -104,7 +91,6 @@ export default function () {
const res = sse.open(STREAM_URL, params, function (client) {
client.on('open', function () {
opened = true;
markActive();
connectionsOpened.add(1);
});
@@ -123,9 +109,18 @@ export default function () {
}
// The contract puts the emit time in `t` (ping) or `at` (scenario).
// The first scenario event on connect replays the current state and
// carries the original state-change timestamp, not the send time, so
// exclude it per VU. Only scenario changes broadcast during the run
// are valid samples.
const initialScenario = name === 'scenario' && firstScenario;
if (name === 'scenario') {
firstScenario = false;
}
// Latency is server timestamp -> client receipt, in milliseconds.
const stamp = payload && (payload.t || payload.at);
if (stamp) {
if (stamp && !initialScenario) {
const emitted = Date.parse(stamp);
if (!Number.isNaN(emitted)) {
const lag = now - emitted;
@@ -142,7 +137,6 @@ export default function () {
pings += 1;
if (pings >= HOLD_PINGS && !closedByUs) {
closedByUs = true;
markInactive();
client.close();
}
}
@@ -153,10 +147,12 @@ export default function () {
connectionErrors.add(1);
console.error(`SSE error: ${e && e.error ? e.error() : e}`);
}
markInactive();
});
});
if (opened) {
connectionsClosed.add(1);
}
check(res, {
'sse status 200': (r) => r && r.status === 200,
'sse content-type': (r) =>
@@ -168,5 +164,4 @@ export default function () {
connectionErrors.add(1);
}
openSuccess.add(opened);
markInactive();
}