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 params for delay in k8s #1147

Merged
merged 49 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f1ae5a3
Add params for delay in k8s
wirednkod Jun 26, 2023
bd0aac2
Add ChaosService
wirednkod Jun 27, 2023
f40abf1
Merge branch 'main' into nik-add-delay-params
wirednkod Jun 27, 2023
9839474
Merge branch 'main' of github.com:paritytech/zombienet into nik-add-d…
wirednkod Jun 27, 2023
fecdac0
Move ChaosSpec to ChaosResource file
wirednkod Jun 27, 2023
7237a0a
Merge branch 'nik-add-delay-params' of github.com:paritytech/zombiene…
wirednkod Jun 27, 2023
e5f85d5
Merge branch 'main' of github.com:paritytech/zombienet into nik-add-d…
wirednkod Jul 6, 2023
7e0fe12
tmp
wirednkod Jul 7, 2023
f543032
tmp
wirednkod Jul 7, 2023
2f6f072
Merge branch 'main' of github.com:paritytech/zombienet into nik-add-d…
wirednkod Jul 7, 2023
5434f8f
Merge branch 'main' into nik-add-delay-params
wirednkod Jul 13, 2023
7be0328
Merge branch 'main' of github.com:paritytech/zombienet into nik-add-d…
wirednkod Jul 14, 2023
f1481f6
Fix selector
wirednkod Jul 14, 2023
ee064b8
Merge branch 'nik-add-delay-params' of github.com:paritytech/zombiene…
wirednkod Jul 14, 2023
c8f7c41
Address comments
wirednkod Jul 14, 2023
c53900c
Remove logs
wirednkod Jul 28, 2023
ebe42b7
Merge branch 'main' into nik-add-delay-params
wirednkod Aug 15, 2023
2c332cb
Merge branch 'main' of github.com:paritytech/zombienet into nik-add-d…
wirednkod Aug 15, 2023
107498a
minor fix
wirednkod Aug 15, 2023
5e4511a
Merge branch 'nik-add-delay-params' of github.com:paritytech/zombiene…
wirednkod Aug 15, 2023
113c8ff
minor correctoions on chaosResource
wirednkod Aug 15, 2023
dfdd337
add delay to example
pepoviola Aug 15, 2023
804df95
add logic to set the delay config at `node` level in the networkSpec
pepoviola Aug 15, 2023
3484c51
Merge branch 'main' into nik-add-delay-params
wirednkod Aug 17, 2023
233f7a2
merge
wirednkod Aug 18, 2023
f7703c5
Merge branch 'nik-add-delay-params' of github.com:paritytech/zombiene…
wirednkod Aug 18, 2023
593eb25
Merge branch 'main' into nik-add-delay-params
pepoviola Aug 18, 2023
8e15465
merge changes
wirednkod Aug 18, 2023
b57853a
Merge branch 'nik-add-delay-params' of github.com:paritytech/zombiene…
wirednkod Aug 18, 2023
bb198b6
Merge branch 'main' of github.com:paritytech/zombienet into nik-add-d…
wirednkod Aug 21, 2023
b7f87bb
Merge branch 'main' into nik-add-delay-params
pepoviola Aug 21, 2023
48bebbc
temporary update test
wirednkod Aug 22, 2023
8721d98
Merge branch 'nik-add-delay-params' of github.com:paritytech/zombiene…
wirednkod Aug 22, 2023
2a1d7d1
refactor gen Chaos resource
pepoviola Aug 23, 2023
ae8bc69
fmt
wirednkod Aug 23, 2023
6d784b1
Fix words
wirednkod Aug 23, 2023
0919485
Fix words
wirednkod Aug 23, 2023
6ff975f
fix example chaos delay
pepoviola Aug 23, 2023
409e590
fmt
pepoviola Aug 23, 2023
b8733d1
default correlation
pepoviola Aug 25, 2023
dd6f627
add chaos test
pepoviola Aug 25, 2023
bac2f5d
Merge branch 'main' into nik-add-delay-params
wirednkod Aug 26, 2023
dc5c675
Merge branch 'main' into nik-add-delay-params
pepoviola Aug 28, 2023
fd1d55c
typo
pepoviola Aug 28, 2023
50cbfd3
Merge branch 'main' into nik-add-delay-params
wirednkod Aug 30, 2023
1a75574
refactor: inject chaos after network spawn
pepoviola Sep 1, 2023
bc28470
fmt
pepoviola Sep 1, 2023
221f08e
Merge branch 'main' into nik-add-delay-params
wirednkod Sep 1, 2023
2efa59a
remove commented code
pepoviola Sep 1, 2023
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
29 changes: 29 additions & 0 deletions examples/0004-big-network-w-delay.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[settings]
global_delay = "yes"
pepoviola marked this conversation as resolved.
Show resolved Hide resolved
timeout = 666

[relaychain]
default_image = "docker.io/parity/polkadot:latest"
default_command = "polkadot"
default_args = [ "-lparachain=debug" ]

chain = "rococo-local"

[[relaychain.node_groups]]
name = "a"
args = [ "-lparachain=debug", "--database=paritydb-experimental" ]
count = 5

[[relaychain.node_groups]]
name = "b"
count = 5

[[parachains]]
id = 100

[[parachains.collator_groups]]
count = 2
[parachains.collator_groups.collator]
name = "collator"
command = "polkadot-parachain"
image = "docker.io/parity/polkadot-parachain:latest"
11 changes: 11 additions & 0 deletions examples/0004-big-network-w-delay.zndsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Description: Big Network test
Network: ./0004-big-network-w-delay.toml
Creds: config

# metrics
a: reports node_roles is 4
b: reports sub_libp2p_is_major_syncing is 0

## test the block height - (or minus) finalised block
a: reports block height minus finalised block is lower than 10 within 20 seconds
b: reports block height - finalised block is lower than 10 within 20 seconds
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { getUniqueName } from "../../configGenerator";
import { TMP_DONE, WAIT_UNTIL_SCRIPT_SUFIX } from "../../constants";
import { Network } from "../../network";
import { Node, ZombieRole } from "../../types";
import { BootNodeResource, NodeResource, ServiceResource } from "./resources";
import { PodSpec, ServiceSpec } from "./resources/types";
import {
BootNodeResource,
ChaosResource,
NodeResource,
ServiceResource,
} from "./resources";
import { ChaosSpec, PodSpec, ServiceSpec } from "./resources/types";

export async function genBootnodeDef(
namespace: string,
Expand All @@ -22,9 +27,14 @@ export async function genNodeDef(
return nodeResource.generateSpec();
}

export function genChaosDef(podSpec: PodSpec): ChaosSpec {
const resource = new ChaosResource(podSpec);
return resource.generateSpec();
}

export function genServiceDef(podSpec: PodSpec): ServiceSpec {
const serviceResource = new ServiceResource(podSpec);
return serviceResource.generateSpec();
const resource = new ServiceResource(podSpec);
return resource.generateSpec();
}

export function replaceNetworkRef(podDef: any, network: Network) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
RunCommandResponse,
setClient,
} from "../client";
import { genServiceDef } from "./dynResourceDefinition";
import { genChaosDef, genServiceDef } from "./dynResourceDefinition";
const fs = require("fs").promises;

const debug = require("debug")("zombie::kube::client");
Expand Down Expand Up @@ -141,8 +141,8 @@ export class KubeClient extends Client {

await this.createResource(podDef, true);
if (podDef.metadata.labels["zombie-role"] !== ZombieRole.Temp) {
const serviceDef = genServiceDef(podDef);
await this.createResource(serviceDef, true);
const genFn = podDef.spec.delay ? genChaosDef : genServiceDef;
wirednkod marked this conversation as resolved.
Show resolved Hide resolved
await this.createResource(genFn(podDef));
}

await this.waitTransferContainerReady(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
JAEGER_AGENT_SERVE_CONFIGS_PORT,
JAEGER_AGENT_THRIFT_BINARY_PORT,
JAEGER_AGENT_THRIFT_COMPACT_PORT,
JAEGER_AGENT_ZIPKIN_COMPACT_PORT,
P2P_PORT,
PROMETHEUS_PORT,
RPC_HTTP_PORT,
RPC_WS_PORT,
} from "../../../constants";
import { ChaosSpec, PodSpec, ServiceSpec } from "./types";

import { BadNetworkSettings } from "../../../types";

export class ChaosResource {
constructor(private readonly podSpec: PodSpec) {}

public generateSpec() {
const ports = this.generatePorts();
const name = this.podSpec.metadata.name;
const delay = this.podSpec.spec.delay!;

if (delay.latency.slice(-2) !== "ms") {
throw Error(
"Latency value should include the 'ms' indicator (e.g. '100ms')",
);
}

if (delay?.jitter.slice(-2) !== "ms") {
throw Error(
"Jitter value should include the 'ms' indicator (e.g. '100ms')",
);
}
return this.generateChaosSpec(name, ports, delay);
}

private shouldExposeJaegerPorts(): boolean {
return this.podSpec.spec.containers.some(
(container) => container.name === "jaeger-agent",
);
}

private generatePorts(): ServiceSpec["spec"]["ports"] {
wirednkod marked this conversation as resolved.
Show resolved Hide resolved
let ports: ServiceSpec["spec"]["ports"] = [
{
name: "prometheus",
protocol: "TCP",
port: PROMETHEUS_PORT,
targetPort: PROMETHEUS_PORT,
},
{
name: "rpc-http",
protocol: "TCP",
port: RPC_HTTP_PORT,
targetPort: RPC_HTTP_PORT,
},
{
name: "rpc-ws",
protocol: "TCP",
port: RPC_WS_PORT,
targetPort: RPC_WS_PORT,
},
{
name: "p2p",
protocol: "TCP",
port: P2P_PORT,
targetPort: P2P_PORT,
},
];

if (this.shouldExposeJaegerPorts()) {
ports = ports.concat([
{
name: "jaeger-agent-zipkin-compact",
protocol: "UDP",
port: JAEGER_AGENT_ZIPKIN_COMPACT_PORT,
targetPort: JAEGER_AGENT_ZIPKIN_COMPACT_PORT,
},
{
name: "jaeger-agent-serve-configs",
protocol: "TCP",
port: JAEGER_AGENT_SERVE_CONFIGS_PORT,
targetPort: JAEGER_AGENT_SERVE_CONFIGS_PORT,
},
{
name: "jaeger-agent-thrift-compact",
protocol: "UDP",
port: JAEGER_AGENT_THRIFT_COMPACT_PORT,
targetPort: JAEGER_AGENT_THRIFT_COMPACT_PORT,
},
{
name: "jaeger-agent-thrift-binary",
protocol: "UDP",
port: JAEGER_AGENT_THRIFT_BINARY_PORT,
targetPort: JAEGER_AGENT_THRIFT_BINARY_PORT,
},
]);
}

return ports;
}

private generateChaosSpec(
name: string,
ports: ChaosSpec["spec"]["ports"],
delay: BadNetworkSettings,
): ChaosSpec {
return {
apiVersion: "chaos-mesh.org/v1alpha1",
kind: "NetworkChaos",
metadata: { name },
spec: {
selector: { pods: name },
ports,
wirednkod marked this conversation as resolved.
Show resolved Hide resolved
delay,
},
};
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { BootNodeResource } from "./bootNodeResource";
export { ChaosResource } from "./chaosResource";
export { NodeResource } from "./nodeResource";
export { ServiceResource } from "./serviceResource";
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class ServiceResource {
public generateSpec() {
const ports = this.generatePorts();
const name = this.podSpec.metadata.name;

return this.generateServiceSpec(name, ports);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { envVars, Resources, ZombieRoleLabel } from "../../../types";
import {
BadNetworkSettings,
envVars,
Resources,
ZombieRoleLabel,
} from "../../../types";

type ContainerResource = Resources["resources"];

Expand Down Expand Up @@ -53,6 +58,7 @@ export interface InnerPodSpec {
runAsUser: number;
runAsGroup: number;
};
delay?: BadNetworkSettings;
}

export interface PodSpec {
Expand Down Expand Up @@ -82,3 +88,27 @@ export interface ServiceSpec {
}[];
};
}

export interface ChaosSpec {
apiVersion: "chaos-mesh.org/v1alpha1";
kind: "NetworkChaos";
metadata: { name: string };
spec: {
selector: SelectorTypeNS | SelectorTypePods;
ports: {
name: string;
protocol: "TCP" | "UDP";
port: number;
targetPort: number;
}[];
delay: BadNetworkSettings;
};
}

interface SelectorTypeNS {
namespaces: string;
}

interface SelectorTypePods {
pods: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export async function setupChainSpec(
// 1: User provide the file (we DON'T expect the raw file)
// 2: User provide the chainSpecCommand (without the --raw option)
const client = getClient();

console.log("0000000000000 ", chainConfig);
if (chainConfig.chainSpecPath) {
// copy file to temp to use
await fsPromises.copyFile(chainConfig.chainSpecPath, chainFullPath);
Expand Down
4 changes: 4 additions & 0 deletions javascript/packages/orchestrator/src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export async function run(
? testDef.network
: path.resolve(configBasePath, testDef.network);

console.log("networkConfigFilePath", networkConfigFilePath);

const config: LaunchConfig = readNetworkConfig(networkConfigFilePath);

// set the provider
Expand Down Expand Up @@ -83,6 +85,8 @@ export async function run(
const suite = Suite.create(mocha.suite, suiteName);

suite.beforeAll("launching", async function () {
console.log("config: ", config);

const launchTimeout = config.settings?.timeout || 500;
this.timeout(launchTimeout * 1000);
try {
Expand Down
9 changes: 9 additions & 0 deletions javascript/packages/orchestrator/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface Settings {
backchannel?: boolean; // only used in k8s at the moment, spawn a backchannel instance
image_pull_policy?: "IfNotPresent" | "Never" | "Always";
local_ip?: string; // ip used for expose local services (rpc/metrics/monitors)
bad_network_global_settings?: BadNetworkSettings;
wirednkod marked this conversation as resolved.
Show resolved Hide resolved
}

export interface RelayChainConfig {
Expand All @@ -57,6 +58,7 @@ export interface RelayChainConfig {
node_groups?: NodeGroupConfig[];
total_node_in_groups?: number;
genesis?: JSON | ObjectJSON;
bad_network_settings?: BadNetworkSettings;
pepoviola marked this conversation as resolved.
Show resolved Hide resolved
}

export interface NodeConfig {
Expand Down Expand Up @@ -117,6 +119,7 @@ export interface ParachainConfig {
collators?: NodeConfig[];
collator_groups?: NodeGroupConfig[];
genesis?: JSON | ObjectJSON;
bad_network_settings?: BadNetworkSettings;
}

export interface HrmpChannelsConfig {
Expand Down Expand Up @@ -358,3 +361,9 @@ export enum SubstrateCliArgsVersion {
V0 = 0,
V1 = 1,
}

export interface BadNetworkSettings {
pepoviola marked this conversation as resolved.
Show resolved Hide resolved
latency: string;
correlation: string;
jitter: string;
}