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

Add prometheus prefix solution #1001

Merged
merged 5 commits into from
May 4, 2023
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
5 changes: 5 additions & 0 deletions docs/src/network-definition-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand All @@ -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.
Expand All @@ -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.

Expand All @@ -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.
Expand All @@ -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.
Expand Down
21 changes: 17 additions & 4 deletions javascript/packages/orchestrator/src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: [],
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -259,7 +267,7 @@ export async function generateNetworkSpec(
await getCollatorNodeFromConfig(
networkSpec,
collatorConfig,
parachain.id,
parachain,
paraChainName,
para,
bootnodes,
Expand Down Expand Up @@ -293,7 +301,7 @@ export async function generateNetworkSpec(
await getCollatorNodeFromConfig(
networkSpec,
node,
parachain.id,
parachain,
paraChainName,
para,
bootnodes,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions javascript/packages/orchestrator/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -172,4 +173,5 @@ export {
UNDYING_COLLATOR_BIN,
K8S_WAIT_UNTIL_SCRIPT_SUFIX,
TOKEN_PLACEHOLDER,
DEFAULT_PROMETHEUS_PREFIX,
};
5 changes: 3 additions & 2 deletions javascript/packages/orchestrator/src/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
Expand Down
3 changes: 3 additions & 0 deletions javascript/packages/orchestrator/src/networkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class NetworkNode implements NetworkNodeInterface {
name: string;
wsUri: string;
prometheusUri: string;
prometheusPrefix: string;
multiAddress: string;
apiInstance?: ApiPromise;
spec?: object | undefined;
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions javascript/packages/orchestrator/src/spawner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const spawnNode = async (
),
nodeMultiAddress,
opts.userDefinedTypes,
node.prometheusPrefix,
);
} else {
const nodeIdentifier = `service/${podDef.metadata.name}`;
Expand All @@ -162,6 +163,7 @@ export const spawnNode = async (
),
nodeMultiAddress,
opts.userDefinedTypes,
node.prometheusPrefix,
);
}

Expand Down
6 changes: 6 additions & 0 deletions javascript/packages/orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -91,6 +93,7 @@ export interface NodeGroupConfig {
count: string | number;
resources?: Resources;
db_snapshot?: string;
prometheus_prefix?: string;
substrate_cli_args_version?: SubstrateCliArgsVersion;
}

Expand All @@ -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[];
Expand All @@ -130,6 +134,7 @@ export interface ComputedNetwork {
defaultCommand: string;
defaultArgs: string[];
defaultDbSnapshot?: string;
defaultPrometheusPrefix: string;
chain: string;
chainSpecPath?: string;
chainSpecCommand?: string;
Expand Down Expand Up @@ -168,6 +173,7 @@ export interface Node {
telemetry?: boolean;
telemetryUrl: string;
prometheus?: boolean;
prometheusPrefix?: string;
overrides: Override[];
addToBootnodes?: boolean;
resources?: Resources;
Expand Down