Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils): internal metrics #1762

Merged
merged 5 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"@zombienet/dsl-parser-wrapper": "^0.1.10",
"@zombienet/orchestrator": "^0.0.81",
"@zombienet/utils": "^0.0.24",
"@zombienet/utils": "^0.0.25",
"cli-progress": "^3.12.0",
"commander": "^11.1.0",
"debug": "^4.3.4",
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/orchestrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@polkadot/api": "^10.12.4",
"@polkadot/keyring": "^12.6.2",
"@polkadot/util-crypto": "^12.6.1",
"@zombienet/utils": "^0.0.24",
"@zombienet/utils": "^0.0.25",
"chai": "^4.3.10",
"debug": "^4.3.4",
"execa": "^5.1.1",
Expand Down
22 changes: 2 additions & 20 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
series,
setLogType,
sleep,
registerSpawnElapsedTimeSecs,
} from "@zombienet/utils";
import fs from "fs";
import tmp from "tmp-promise";
Expand Down Expand Up @@ -541,26 +542,7 @@ export async function start(
const spawnEnd = performance.now();
const spawnElapsedSecs = Math.round((spawnEnd - spawnStart) / 1000);
debug(`\t 🕰 [Spawn] elapsed time: ${spawnElapsedSecs} secs`);

if (
options?.inCI &&
process.env["PUSHGATEWAY_URL"] &&
process.env["CI_JOB_NAME"]
) {
const jobId = process.env["CI_JOB_ID"];
const jobName = process.env["CI_JOB_NAME"];
const projectName = process.env["CI_PROJECT_NAME"] || "";
const metricName = "zombie_network_ready_secs";
const help = `# HELP ${metricName} Elapsed time to spawn the network in seconds`;
const type = `# TYPE ${metricName} gauge`;
const metricString = `${metricName}{job_id="${jobId}", job_name="${jobName}", project_name="${projectName}"} ${spawnElapsedSecs}`;
const body = [help, type, metricString, "\n"].join("\n");
debug!(`Sending metric with content:\n ${body}`);
await fetch(process.env["PUSHGATEWAY_URL"], {
method: "POST",
body,
});
}
if (options?.inCI) await registerSpawnElapsedTimeSecs(spawnElapsedSecs);

// clean cache before dump the info.
network.cleanMetricsCache();
Expand Down
8 changes: 8 additions & 0 deletions javascript/packages/orchestrator/src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
setLogType,
sleep,
LogType,
registerTotalElapsedTimeSecs,
} from "@zombienet/utils";
import fs from "fs";
import Mocha from "mocha";
Expand Down Expand Up @@ -40,6 +41,7 @@ export async function run(
dir: string | undefined,
force: boolean = false,
) {
const testStart = performance.now();
logType && setLogType(logType);
let network: Network;
const backchannelMap: BackchannelMap = {};
Expand Down Expand Up @@ -131,6 +133,12 @@ export async function run(
suite.afterAll("teardown", async function () {
this.timeout(180 * 1000);
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);

const logsPath = await network.dumpLogs(false);
const tests = this.test?.parent?.tests;

Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zombienet/utils",
"version": "0.0.24",
"version": "0.0.25",
"description": "Useful utilities for ZombieNet Framework",
"main": "dist/index.js",
"author": "Parity Technologies <[email protected]>",
Expand Down
1 change: 1 addition & 0 deletions javascript/packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./net";
export * from "./nunjucksRelativeLoader";
export * from "./promiseSeries";
export * from "./tableCli";
export * from "./zombieMetrics";
42 changes: 42 additions & 0 deletions javascript/packages/utils/src/zombieMetrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function canSend() {
return process.env["PUSHGATEWAY_URL"] && process.env["CI_JOB_NAME"];
}

function getFromCI() {
return [
process.env["CI_JOB_ID"],
process.env["CI_JOB_NAME"],
process.env["CI_PROJECT_NAME"] || "",
process.env["PUSHGATEWAY_URL"],
];
}

export async function registerSpawnElapsedTimeSecs(elapsed: number) {
if (canSend()) {
const [jobId, jobName, projectName, pushGatewayUrl] = getFromCI();
const metricName = "zombie_network_ready_secs";
const help = `# HELP ${metricName} Elapsed time to spawn the network in seconds`;
const type = `# TYPE ${metricName} gauge`;
const metricString = `${metricName}{job_id="${jobId}", job_name="${jobName}", project_name="${projectName}"} ${elapsed}`;
const body = [help, type, metricString, "\n"].join("\n");
await fetch(pushGatewayUrl!, {
method: "POST",
body,
});
}
}

export async function registerTotalElapsedTimeSecs(elapsed: number) {
if (canSend()) {
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 body = [help, type, metricString, "\n"].join("\n");
await fetch(pushGatewayUrl!, {
method: "POST",
body,
});
}
}
Loading