From 7ab452258e57bb19663018797dd141651648e8b1 Mon Sep 17 00:00:00 2001 From: Javier Viola <363911+pepoviola@users.noreply.github.com> Date: Tue, 21 Jan 2025 12:44:55 -0300 Subject: [PATCH] send status as part of the metrics to prometheus (#1941) * send status as part of the metrics to prometheus * lint --- .../orchestrator/src/test-runner/index.ts | 15 +++++++++------ javascript/packages/utils/src/zombieMetrics.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/javascript/packages/orchestrator/src/test-runner/index.ts b/javascript/packages/orchestrator/src/test-runner/index.ts index 102996380..6682ed22b 100644 --- a/javascript/packages/orchestrator/src/test-runner/index.ts +++ b/javascript/packages/orchestrator/src/test-runner/index.ts @@ -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); @@ -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 @@ -227,6 +228,8 @@ export async function run( } } } + // submit metric + if (inCI) await registerTotalElapsedTimeSecs(elapsedSecs, success); return; }); diff --git a/javascript/packages/utils/src/zombieMetrics.ts b/javascript/packages/utils/src/zombieMetrics.ts index 52f20788a..189a288d3 100644 --- a/javascript/packages/utils/src/zombieMetrics.ts +++ b/javascript/packages/utils/src/zombieMetrics.ts @@ -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",