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 2 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 @@ -32,6 +32,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.
- `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 @@ -53,6 +54,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 @@ -63,6 +65,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.

## `parachains`
Expand All @@ -76,6 +79,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 @@ -88,6 +92,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
24 changes: 20 additions & 4 deletions javascript/packages/orchestrator/src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export async function generateNetworkSpec(
parachains: [],
};

if (config.relaychain.prometheus_prefix)
networkSpec.relaychain.prometheusPrefix =
config.relaychain.prometheus_prefix;

// check all imageURLs for validity
// TODO: These checks should be agains all config items that needs check
configurationFileChecks(config);
Expand Down Expand Up @@ -207,6 +211,12 @@ export async function generateNetworkSpec(
nodeGroup.resources || networkSpec.relaychain.defaultResources,
db_snapshot: nodeGroup.db_snapshot,
};
if (nodeGroup.prometheus_prefix) {
node.prometheus_prefix = nodeGroup.prometheus_prefix;
} else if (config.relaychain.prometheus_prefix) {
node.prometheus_prefix = config.relaychain.prometheus_prefix;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this ?

Suggested change
if (nodeGroup.prometheus_prefix) {
node.prometheus_prefix = nodeGroup.prometheus_prefix;
} else if (config.relaychain.prometheus_prefix) {
node.prometheus_prefix = config.relaychain.prometheus_prefix;
}
node.prometheus_prefix = nodeGroup.prometheus_prefix || config.relaychain.prometheus_prefix;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really; cause there is a chance that none of them exist, and in that case I want to avoid adding the key "prometheus_prefix" to the object

const nodeSetup = await getNodeFromConfig(
networkSpec,
node,
Expand Down Expand Up @@ -256,7 +266,7 @@ export async function generateNetworkSpec(
await getCollatorNodeFromConfig(
networkSpec,
collatorConfig,
parachain.id,
parachain,
paraChainName,
para,
bootnodes,
Expand Down Expand Up @@ -285,7 +295,7 @@ export async function generateNetworkSpec(
await getCollatorNodeFromConfig(
networkSpec,
node,
parachain.id,
parachain,
paraChainName,
para,
bootnodes,
Expand Down Expand Up @@ -489,7 +499,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 @@ -533,14 +543,17 @@ 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,
};

if (parachain.prometheus_prefix)
node.prometheusPrefix = parachain.prometheus_prefix;

return node;
}

Expand Down Expand Up @@ -618,6 +631,9 @@ async function getNodeFromConfig(
p2pCertHash: node.p2p_cert_hash,
};

if (node.prometheus_prefix)
nodeSetup.prometheusPrefix = node.prometheus_prefix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If prometheus_prefix is some value || undefined it will stay undefined

Suggested change
if (node.prometheus_prefix)
nodeSetup.prometheusPrefix = node.prometheus_prefix;
nodeSetup.prometheusPrefix = node.prometheus_prefix;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really - prior to this if the key prometheusPrefix does not exist; With your suggestion, it will create the key and "assign" undefined to it


if (group) nodeSetup.group = group;

const dbSnapshot = node.db_snapshot
Expand Down
4 changes: 2 additions & 2 deletions javascript/packages/orchestrator/src/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export function getMetricName(metricName: string): string {
return metricNameTouse;
}

export function getProcessStartTimeKey() {
return "substrate_process_start_time_seconds";
export function getProcessStartTimeKey(prefix = "substrate") {
return `${prefix}_process_start_time_seconds`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

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
5 changes: 5 additions & 0 deletions javascript/packages/orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface RelayChainConfig {
max_nominations?: number;
nodes?: NodeConfig[];
node_groups?: NodeGroupConfig[];
prometheus_prefix?: string;
total_node_in_groups?: number;
genesis?: JSON | ObjectJSON;
}
Expand All @@ -74,6 +75,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 @@ -89,6 +91,7 @@ export interface NodeGroupConfig {
count: string | number;
resources?: Resources;
db_snapshot?: string;
prometheus_prefix?: string;
}

export interface ParachainConfig {
Expand All @@ -105,6 +108,7 @@ export interface ParachainConfig {
chain_spec_path?: string;
cumulus_based?: boolean;
bootnodes?: string[];
prometheus_prefix?: string;
// backward compatibility
collator?: NodeConfig;
collators?: NodeConfig[];
Expand Down Expand Up @@ -165,6 +169,7 @@ export interface Node {
telemetry?: boolean;
telemetryUrl: string;
prometheus?: boolean;
prometheusPrefix?: string;
overrides: Override[];
addToBootnodes?: boolean;
resources?: Resources;
Expand Down