Skip to content

Commit

Permalink
test: enable metrics for the sim tests (#5583)
Browse files Browse the repository at this point in the history
* Enable metrics for the sim tests

* Add _URL prefix to env variable
  • Loading branch information
nazarhussain authored May 31, 2023
1 parent 888c599 commit 2811142
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/cli/test/utils/simulation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ You can run any of npm task prefixed with `test:sim:*`. There are different scen
| Lighthouse | LIGHTHOUSE_DOCKER_IMAGE | Similar to other clients use it to set Lighouse docker image. Make use you use `-dev` suffixed image tags as these are the only one supporting `minimal` preset. |
| Lighthouse | LIGHTHOUSE_BINARY_PATH | Use local compiled binary. Make sure it's compiled with the `minimal` spec enabled. |

### Enable Metics for the sim tests

To enable metrics for the SIM tests you can set `SIM_METRIC_SERVER_URL` environment variable with the host and port e.g. `127.0.0.1:4000`.

## Architecture

Based on the parameters passed to `SimulationEnvironment.initWithDefaults` the following directory structure is created by the `SimulationEnvironment` and passed relevant directories to the individual client generators. For understanding we call this process as bootstrapping.
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/test/utils/simulation/cl_clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export async function createCLNode<C extends CLClient>(
engineUrls: options.engineUrls ?? [],
};

const metricServer = process.env.SIM_METRIC_SERVER_URL;
if (metricServer) {
const server = new URL(metricServer.startsWith("http") ? metricServer : `http://${metricServer}`);
opts.metrics = {
host: server.hostname,
port: parseInt(server.port as string),
};
}

await createCLNodePaths(opts.paths);
await createKeystores(opts.paths, opts.keys);
await writeFile(opts.paths.jwtsecretFilePath, SHARED_JWT_SECRET);
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/test/utils/simulation/cl_clients/lighthouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateLighthouseBeaconNode: CLClientGenerator<CLClient.Lighthouse

const isDocker = process.env.LIGHTHOUSE_DOCKER_IMAGE !== undefined;

const {address, id, config, keys, nodeIndex} = opts;
const {address, id, config, keys, nodeIndex, metrics} = opts;
const {engineUrls, engineMock, clientOptions} = opts;
const {
cl: {httpPort, port, keymanagerPort},
Expand Down Expand Up @@ -68,6 +68,12 @@ export const generateLighthouseBeaconNode: CLClientGenerator<CLClient.Lighthouse
cliParams["execution-endpoint"] = [...engineUrls].join(",");
}

if (metrics) {
cliParams["metrics-allow-origin"] = "*";
cliParams["metrics-port"] = metrics.port;
cliParams["metrics-address"] = metrics.host;
}

const beaconNodeJob: JobOptions = {
id,
type: isDocker ? RunnerType.Docker : RunnerType.ChildProcess,
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/test/utils/simulation/cl_clients/lodestar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {CLClient, CLClientGenerator, CLClientGeneratorOptions, JobOptions, Runne
import {getNodePorts} from "../utils/ports.js";

export const generateLodestarBeaconNode: CLClientGenerator<CLClient.Lodestar> = (opts, runner) => {
const {address, id, config, keys, genesisTime, engineUrls, engineMock, clientOptions, nodeIndex} = opts;
const {address, id, config, keys, genesisTime, engineUrls, engineMock, clientOptions, nodeIndex, metrics} = opts;
const {
paths: {jwtsecretFilePath, rootDir, genesisFilePath, logFilePath},
} = opts;
Expand All @@ -39,7 +39,6 @@ export const generateLodestarBeaconNode: CLClientGenerator<CLClient.Lodestar> =
"network.rateLimitMultiplier": 0,
listenAddress: "0.0.0.0",
port: ports.cl.port,
metrics: false,
bootnodes: [],
logPrefix: id,
logFormatGenesisTime: `${genesisTime}`,
Expand All @@ -61,6 +60,14 @@ export const generateLodestarBeaconNode: CLClientGenerator<CLClient.Lodestar> =
rcConfig["execution.urls"] = [...engineUrls];
}

if (metrics) {
rcConfig.metrics = true;
rcConfig["metrics.port"] = metrics.port;
rcConfig["metrics.address"] = metrics.host;
} else {
rcConfig.metrics = false;
}

const validatorClientsJobs: JobOptions[] = [];
if (keys.type !== "no-keys") {
validatorClientsJobs.push(
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/test/utils/simulation/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export interface CLClientGeneratorOptions<C extends CLClient = CLClient> {
engineUrls: string[];
engineMock: boolean;
clientOptions: CLClientsOptions[C];
metrics?: {
host: string;
port: number;
};
}

export interface ELGeneratorGenesisOptions<E extends ELClient = ELClient> {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/utils/simulation/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Runner implements IRunner {
await job.start();

this.emitter.emit("started", jobOption.id);
console.log(`Started "${jobOption.id}"...`);
console.log(`Started "${jobOption.id}" logFile=${jobOption.logs.stdoutFilePath}...`);

if (childrenJob) await childrenJob.start();
});
Expand Down

0 comments on commit 2811142

Please sign in to comment.