Skip to content

Commit

Permalink
chore: push spawning time metric (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepoviola authored Apr 1, 2024
1 parent 4ace85e commit 8b134ea
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { spawnNode } from "./spawner";
import { setSubstrateCliArgsVersion } from "./substrateCliArgsHelper";
import { ComputedNetwork, LaunchConfig } from "./configTypes";
import { Node, Parachain } from "./sharedTypes";
import { performance } from "perf_hooks";

const debug = require("debug")("zombie");

Expand All @@ -74,7 +75,8 @@ export async function start(
launchConfig: LaunchConfig,
options?: OrcOptionsInterface,
) {
console.time("zombie_spawn");
const spawnStart = performance.now();

const opts = {
...{
monitor: false,
Expand Down Expand Up @@ -535,7 +537,29 @@ export async function start(
debug(
`\t 🚀 LAUNCH COMPLETE under namespace ${decorators.green(namespace)} 🚀`,
);
console.timeEnd("zombie_spawn");

const spawnEnd = performance.now();
const spawnElapsedSecs = Math.round((spawnEnd - spawnStart) / 1000);
debug(`\t 🕰 [Spawn] elapsed time: ${spawnElapsedSecs} secs`);

if (options?.inCI && 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(
"http://zombienet-prometheus-pushgateway.managed-monitoring:9091/metrics/job/zombie-metrics",
{
method: "POST",
body,
},
);
}

// clean cache before dump the info.
network.cleanMetricsCache();
Expand Down

0 comments on commit 8b134ea

Please sign in to comment.