Skip to content

Commit 60c0f24

Browse files
committed
test(e2e): sample kitchen sink rpc peak rss
1 parent ea3bb92 commit 60c0f24

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

scripts/e2e/kitchen-sink-rpc-walk.mjs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,25 @@ export async function sampleProcess(pid, options = {}) {
562562
return samplePosixProcess(pid, run);
563563
}
564564

565+
export function summarizeProcessSamples(samples) {
566+
const validSamples = samples.filter((sample) => sample && Number.isFinite(sample.rssMiB));
567+
if (validSamples.length === 0) {
568+
return null;
569+
}
570+
const peakRssSample = validSamples.reduce((peak, sample) =>
571+
sample.rssMiB > peak.rssMiB ? sample : peak,
572+
);
573+
const numericCpuSamples = validSamples
574+
.map((sample) => sample.cpuPercent)
575+
.filter((value) => Number.isFinite(value));
576+
return {
577+
...peakRssSample,
578+
sampleCount: validSamples.length,
579+
peakCpuPercent:
580+
numericCpuSamples.length > 0 ? Math.max(...numericCpuSamples) : peakRssSample.cpuPercent,
581+
};
582+
}
583+
565584
async function samplePosixProcess(pid, run) {
566585
try {
567586
const { stdout } = await run("ps", ["-o", "rss=,pcpu=", "-p", String(pid)], {
@@ -696,9 +715,22 @@ export async function main() {
696715
assertIncludesAny(inspectProviders, EXPECTED_PROVIDERS, "plugins inspect providers");
697716

698717
const child = await startGateway(runner, port, env, logPath);
718+
const processSamples = [];
719+
const sampleGateway = async () => {
720+
const sample = await sampleProcess(child.pid);
721+
if (sample) {
722+
processSamples.push(sample);
723+
}
724+
return sample;
725+
};
726+
let sampleTimer;
699727
try {
700728
await waitForGatewayReady(child, port, logPath);
701-
const initialSample = await sampleProcess(child.pid);
729+
const initialSample = await sampleGateway();
730+
sampleTimer = setInterval(() => {
731+
void sampleGateway().catch(() => {});
732+
}, 1000);
733+
sampleTimer.unref?.();
702734
const healthz = await fetchJson(`http://127.0.0.1:${port}/healthz`);
703735
const readyz = await fetchJson(`http://127.0.0.1:${port}/readyz`);
704736
if (!healthz.ok || healthz.body?.status !== "live") {
@@ -776,8 +808,10 @@ export async function main() {
776808
);
777809
}
778810
await retryRpcCall("diagnostics.stability", {}, { runner, port, env });
779-
const finalSample = await sampleProcess(child.pid);
811+
const finalSample = await sampleGateway();
780812
assertResourceCeiling(finalSample);
813+
const peakSample = summarizeProcessSamples(processSamples);
814+
assertResourceCeiling(peakSample);
781815
assertNoErrorLogs(logPath);
782816

783817
console.log(
@@ -790,6 +824,7 @@ export async function main() {
790824
channelAccount,
791825
initialSample,
792826
finalSample,
827+
peakSample,
793828
},
794829
null,
795830
2,
@@ -800,6 +835,9 @@ export async function main() {
800835
console.error(tailFile(logPath));
801836
throw error;
802837
} finally {
838+
if (sampleTimer) {
839+
clearInterval(sampleTimer);
840+
}
803841
await stopGateway(child);
804842
}
805843
}

test/scripts/kitchen-sink-rpc-walk.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
assertResourceCeiling,
44
fetchJson,
55
sampleProcess,
6+
summarizeProcessSamples,
67
} from "../../scripts/e2e/kitchen-sink-rpc-walk.mjs";
78

89
describe("kitchen-sink RPC process sampling", () => {
@@ -76,6 +77,21 @@ describe("kitchen-sink RPC process sampling", () => {
7677
);
7778
});
7879

80+
it("summarizes peak RSS across repeated process samples", () => {
81+
expect(
82+
summarizeProcessSamples([
83+
{ rssMiB: 128, cpuPercent: 2 },
84+
{ rssMiB: 512, cpuPercent: 25 },
85+
{ rssMiB: 256, cpuPercent: 8 },
86+
]),
87+
).toEqual({
88+
rssMiB: 512,
89+
cpuPercent: 25,
90+
sampleCount: 3,
91+
peakCpuPercent: 25,
92+
});
93+
});
94+
7995
it("fails when process sampling does not capture RSS", () => {
8096
expect(() => assertResourceCeiling(null)).toThrow("gateway RSS sample was not captured");
8197
});

0 commit comments

Comments
 (0)