Skip to content

Commit

Permalink
send status as part of the metrics to prometheus (#1941)
Browse files Browse the repository at this point in the history
* send status as part of the metrics to prometheus

* lint
  • Loading branch information
pepoviola authored Jan 21, 2025
1 parent 2103782 commit 7ab4522
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions javascript/packages/orchestrator/src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ export async function run(

suite.afterAll("teardown", async function () {
this.timeout(180 * 1000);
// report metric
const testEnd = performance.now();
const elapsedSecs = Math.round((testEnd - testStart) / 1000);
debug(`\t 🕰 [Test] elapsed time: ${elapsedSecs} secs`);
let success: boolean = false;
if (network && !network.wasRunning) {
// report metric
const testEnd = performance.now();
const elapsedSecs = Math.round((testEnd - testStart) / 1000);
debug(`\t 🕰 [Test] elapsed time: ${elapsedSecs} secs`);
if (inCI) await registerTotalElapsedTimeSecs(elapsedSecs);

let logsPath;
try {
logsPath = await network.dumpLogs(false);
Expand All @@ -157,6 +156,8 @@ export async function run(
console.log(
`\n\n\t${decorators.red("❌ One or more of your test failed...")}`,
);
} else {
success = true;
}

// All test passed, just remove the network
Expand Down Expand Up @@ -227,6 +228,8 @@ export async function run(
}
}
}
// submit metric
if (inCI) await registerTotalElapsedTimeSecs(elapsedSecs, success);
return;
});

Expand Down
8 changes: 6 additions & 2 deletions javascript/packages/utils/src/zombieMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ export async function registerSpawnElapsedTimeSecs(elapsed: number) {
}
}

export async function registerTotalElapsedTimeSecs(elapsed: number) {
export async function registerTotalElapsedTimeSecs(
elapsed: number,
success: boolean,
) {
if (canSend()) {
const status = success ? "pass" : "fail";
const [jobId, jobName, projectName, pushGatewayUrl] = getFromCI();
const metricName = "zombie_test_complete_secs";
const help = `# HELP ${metricName} Elapsed time to complete the test job in seconds (including spawning, but not teardown)`;
const type = `# TYPE ${metricName} gauge`;
const metricString = `${metricName}{job_id="${jobId}", job_name="${jobName}", project_name="${projectName}"} ${elapsed}`;
const metricString = `${metricName}{job_id="${jobId}", job_name="${jobName}", project_name="${projectName}"}, status="${status}" ${elapsed}`;
const body = [help, type, metricString, "\n"].join("\n");
await fetch(pushGatewayUrl!, {
method: "POST",
Expand Down

0 comments on commit 7ab4522

Please sign in to comment.