diff --git a/docs/src/network-definition-spec.md b/docs/src/network-definition-spec.md index bde4daf7c..efaf600dc 100644 --- a/docs/src/network-definition-spec.md +++ b/docs/src/network-definition-spec.md @@ -33,6 +33,7 @@ The network config can be provided both in `json` or `toml` format and each sect - `local_path`: string; - `remote_name`: string; - `default_resources`: (Object) **Only** available in `kubernetes`, represent the resources `limits`/`reservations` needed by the nodes by default. +- `default_prometheus_prefix`: A parameter for customizing the metric's prefix. If parameter is placed in `relaychain` level, it will be "passed" to all `relaychain` nodes. Defaults to 'substrate'. - `random_nominators_count`: (number, optional), if is set _and the stacking pallet is enabled_ zombienet will generate `x` nominators and will be injected in the genesis. - `max_nominations`: (number, default 24), the max allowed number of nominations by a nominator. This should match the value set in the runtime (e.g Kusama is 24 and Polkadot 16). - `nodes`: @@ -55,6 +56,7 @@ The network config can be provided both in `json` or `toml` format and each sect - `ws_port`: (number), WS port to use.; - `rpc_port`: (number) RPC port to use; - `prometheus_port`: (number) Prometheus port to use; + - `prometheus_prefix`: A parameter for customizing the metric's prefix for the specific node. Will apply only to this node; Defaults to 'substrate'. - `node_groups`: - `*name`: (String) Group name, used for naming the nodes (e.g name-1) - `*count` (Number), Number of `nodes` to launch for this group. @@ -65,6 +67,7 @@ The network config can be provided both in `json` or `toml` format and each sect - name: (String) name of the `env` var. - value: (String| number) Value of the env var. - `overrides`: Array of `overrides` definitions. + - `prometheus_prefix`: A parameter for customizing the metric's prefix for the specific node. Will apply to all the nodes of the group; Defaults to 'substrate'. - `resources`: (Object) **Only** available in `kubernetes`, represent the resources `limits`/`reservations` needed by the node. - `substrate_cli_args_version`: (0|1) By default zombienet will evaluate your binary and set the correct version, but that produce an small overhead that could be skipped if you set directly with this key. @@ -79,6 +82,7 @@ The network config can be provided both in `json` or `toml` format and each sect - `genesis_wasm_generator`: (String) Command to generate the wasm file. - `genesis_state_path`: (String) Path to the state file to use. - `genesis_state_generator`: (String) Command to generate the state file. + - `prometheus_prefix`: A parameter for customizing the metric's prefix for the specific node. Will apply only to all parachain nodes/collators; Defaults to 'substrate'. - `collator`: - `*name`: (String) Name of the collator. @@ -92,6 +96,7 @@ The network config can be provided both in `json` or `toml` format and each sect - value: (String| number) Value of the env var. - `collator_groups`: + - `*name`: (String) Name of the collator. - `*count`: (Number) Number of `collators` to launch for this group. - `image`: (String) Image to use. diff --git a/javascript/packages/orchestrator/src/configGenerator.ts b/javascript/packages/orchestrator/src/configGenerator.ts index b383c41cc..5cbf92744 100644 --- a/javascript/packages/orchestrator/src/configGenerator.ts +++ b/javascript/packages/orchestrator/src/configGenerator.ts @@ -21,6 +21,7 @@ import { DEFAULT_IMAGE, DEFAULT_MAX_NOMINATIONS, DEFAULT_PORTS, + DEFAULT_PROMETHEUS_PREFIX, DEFAULT_WASM_GENERATE_SUBCOMMAND, GENESIS_STATE_FILENAME, GENESIS_WASM_FILENAME, @@ -125,6 +126,9 @@ export async function generateNetworkSpec( chain: config.relaychain.chain || DEFAULT_CHAIN, overrides: globalOverrides, defaultResources: config.relaychain.default_resources, + defaultPrometheusPrefix: + config.relaychain.default_prometheus_prefix || + DEFAULT_PROMETHEUS_PREFIX, }, parachains: [], }; @@ -206,10 +210,14 @@ export async function generateNetworkSpec( resources: nodeGroup.resources || networkSpec.relaychain.defaultResources, db_snapshot: nodeGroup.db_snapshot, + prometheus_prefix: + nodeGroup.prometheus_prefix || + networkSpec.relaychain.defaultPrometheusPrefix, substrate_cli_args_version: nodeGroup.substrate_cli_args_version || networkSpec.relaychain.default_substrate_cli_args_version, }; + const nodeSetup = await getNodeFromConfig( networkSpec, node, @@ -259,7 +267,7 @@ export async function generateNetworkSpec( await getCollatorNodeFromConfig( networkSpec, collatorConfig, - parachain.id, + parachain, paraChainName, para, bootnodes, @@ -293,7 +301,7 @@ export async function generateNetworkSpec( await getCollatorNodeFromConfig( networkSpec, node, - parachain.id, + parachain, paraChainName, para, bootnodes, @@ -492,7 +500,7 @@ async function getLocalOverridePath( async function getCollatorNodeFromConfig( networkSpec: any, collatorConfig: NodeConfig, - para_id: number, + parachain: ParachainConfig, chain: string, // relay-chain para: PARA, bootnodes: string[], // parachain bootnodes @@ -536,12 +544,15 @@ async function getCollatorNodeFromConfig( prometheus: prometheusExternal(networkSpec), overrides: [], zombieRole: cumulusBased ? ZombieRole.CumulusCollator : ZombieRole.Collator, - parachainId: para_id, + parachainId: parachain.id, dbSnapshot: collatorConfig.db_snapshot, imagePullPolicy: networkSpec.settings.image_pull_policy || "Always", ...ports, externalPorts, p2pCertHash: collatorConfig.p2p_cert_hash, + prometheusPrefix: + parachain.prometheus_prefix || + networkSpec.relaychain.defaultPrometheusPrefix, }; return node; @@ -619,6 +630,8 @@ async function getNodeFromConfig( ...ports, externalPorts, p2pCertHash: node.p2p_cert_hash, + prometheusPrefix: + node.prometheus_prefix || networkSpec.relaychain.defaultPrometheusPrefix, }; if (group) nodeSetup.group = group; diff --git a/javascript/packages/orchestrator/src/constants.ts b/javascript/packages/orchestrator/src/constants.ts index 88015763c..57972d170 100644 --- a/javascript/packages/orchestrator/src/constants.ts +++ b/javascript/packages/orchestrator/src/constants.ts @@ -47,6 +47,7 @@ const UNDYING_COLLATOR_BIN = "undying-collator"; const DEFAULT_CUMULUS_COLLATOR_BIN = "polkadot-parachain"; const DEFAULT_COLLATOR_IMAGE = "parity/polkadot-parachain:latest"; const DEFAULT_MAX_NOMINATIONS = 24; // kusama value is 24 +const DEFAULT_PROMETHEUS_PREFIX = "substrate"; const FINISH_MAGIC_FILE = "/tmp/finished.txt"; const GENESIS_STATE_FILENAME = "genesis-state"; const GENESIS_WASM_FILENAME = "genesis-wasm"; @@ -172,4 +173,5 @@ export { UNDYING_COLLATOR_BIN, K8S_WAIT_UNTIL_SCRIPT_SUFIX, TOKEN_PLACEHOLDER, + DEFAULT_PROMETHEUS_PREFIX, }; diff --git a/javascript/packages/orchestrator/src/metrics/index.ts b/javascript/packages/orchestrator/src/metrics/index.ts index 52021d737..6142fb812 100644 --- a/javascript/packages/orchestrator/src/metrics/index.ts +++ b/javascript/packages/orchestrator/src/metrics/index.ts @@ -1,5 +1,6 @@ const debug = require("debug")("zombie::metrics"); import { decorators, TimeoutAbortController } from "@zombienet/utils"; +import { DEFAULT_PROMETHEUS_PREFIX } from "../constants"; import { parseLine } from "./parseLine"; // metrics can have namespace @@ -127,8 +128,8 @@ export function getMetricName(metricName: string): string { return metricNameTouse; } -export function getProcessStartTimeKey() { - return "substrate_process_start_time_seconds"; +export function getProcessStartTimeKey(prefix = DEFAULT_PROMETHEUS_PREFIX) { + return `${prefix}_process_start_time_seconds`; } function _extractMetrics(text: string): Metrics { diff --git a/javascript/packages/orchestrator/src/network-helpers/verifier.ts b/javascript/packages/orchestrator/src/network-helpers/verifier.ts index e780c6adb..6e79c67a5 100644 --- a/javascript/packages/orchestrator/src/network-helpers/verifier.ts +++ b/javascript/packages/orchestrator/src/network-helpers/verifier.ts @@ -8,8 +8,8 @@ const debug = require("debug")("zombie::helper::verifier"); export const nodeChecker = async (node: NetworkNode) => { const metricToQuery = node.para - ? decorate(node.para, [getProcessStartTimeKey])[0]() - : getProcessStartTimeKey(); + ? decorate(node.para, [getProcessStartTimeKey])[0](node.prometheusPrefix) + : getProcessStartTimeKey(node.prometheusPrefix); debug( `\t checking node: ${node.name} with prometheusUri: ${node.prometheusUri} - key: ${metricToQuery}`, ); diff --git a/javascript/packages/orchestrator/src/networkNode.ts b/javascript/packages/orchestrator/src/networkNode.ts index 9681f2278..18c15df09 100644 --- a/javascript/packages/orchestrator/src/networkNode.ts +++ b/javascript/packages/orchestrator/src/networkNode.ts @@ -33,6 +33,7 @@ export class NetworkNode implements NetworkNodeInterface { name: string; wsUri: string; prometheusUri: string; + prometheusPrefix: string; multiAddress: string; apiInstance?: ApiPromise; spec?: object | undefined; @@ -48,11 +49,13 @@ export class NetworkNode implements NetworkNodeInterface { prometheusUri: string, multiAddress: string, userDefinedTypes: any = null, + prometheusPrefix = "substrate", ) { this.name = name; this.wsUri = wsUri; this.prometheusUri = prometheusUri; this.multiAddress = multiAddress; + this.prometheusPrefix = prometheusPrefix; if (userDefinedTypes) this.userDefinedTypes = userDefinedTypes; } diff --git a/javascript/packages/orchestrator/src/spawner.ts b/javascript/packages/orchestrator/src/spawner.ts index 6be19f948..43d849212 100644 --- a/javascript/packages/orchestrator/src/spawner.ts +++ b/javascript/packages/orchestrator/src/spawner.ts @@ -136,6 +136,7 @@ export const spawnNode = async ( ), nodeMultiAddress, opts.userDefinedTypes, + node.prometheusPrefix, ); } else { const nodeIdentifier = `service/${podDef.metadata.name}`; @@ -162,6 +163,7 @@ export const spawnNode = async ( ), nodeMultiAddress, opts.userDefinedTypes, + node.prometheusPrefix, ); } diff --git a/javascript/packages/orchestrator/src/types.ts b/javascript/packages/orchestrator/src/types.ts index 7c9688e7e..d126bf23d 100644 --- a/javascript/packages/orchestrator/src/types.ts +++ b/javascript/packages/orchestrator/src/types.ts @@ -44,6 +44,7 @@ export interface RelayChainConfig { default_image?: string; default_resources?: Resources; default_db_snapshot?: string; + default_prometheus_prefix?: string; default_substrate_cli_args_version?: SubstrateCliArgsVersion; chain: string; chain_spec_path?: string; @@ -75,6 +76,7 @@ export interface NodeConfig { ws_port?: number; rpc_port?: number; prometheus_port?: number; + prometheus_prefix?: string; p2p_port?: number; db_snapshot?: string; p2p_cert_hash?: string; // libp2p certhash to use with webrtc transport. @@ -91,6 +93,7 @@ export interface NodeGroupConfig { count: string | number; resources?: Resources; db_snapshot?: string; + prometheus_prefix?: string; substrate_cli_args_version?: SubstrateCliArgsVersion; } @@ -108,6 +111,7 @@ export interface ParachainConfig { chain_spec_path?: string; cumulus_based?: boolean; bootnodes?: string[]; + prometheus_prefix?: string; // backward compatibility collator?: NodeConfig; collators?: NodeConfig[]; @@ -130,6 +134,7 @@ export interface ComputedNetwork { defaultCommand: string; defaultArgs: string[]; defaultDbSnapshot?: string; + defaultPrometheusPrefix: string; chain: string; chainSpecPath?: string; chainSpecCommand?: string; @@ -168,6 +173,7 @@ export interface Node { telemetry?: boolean; telemetryUrl: string; prometheus?: boolean; + prometheusPrefix?: string; overrides: Override[]; addToBootnodes?: boolean; resources?: Resources;