From 6dc0ccea5838b56026157c20282099d4b56f34e2 Mon Sep 17 00:00:00 2001 From: hemz10 Date: Mon, 20 Nov 2023 12:55:04 +0530 Subject: [PATCH 1/3] test: add workflow to run smoke test --- .github/workflows/smoke.yaml | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/smoke.yaml diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml new file mode 100644 index 0000000..7d6082e --- /dev/null +++ b/.github/workflows/smoke.yaml @@ -0,0 +1,37 @@ +name: smoke-test +on: + workflow_dispatch: + +jobs: + smoke-test: + name: smoke test on all parachains + runs-on: "ubuntu-latest" + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Installing Kurtosis CLI if not found in cache + run: | + if [ ! -f "/usr/bin/kurtosis" ]; then + echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list + sudo apt update + sudo apt install kurtosis-cli + which kurtosis + fi + + - name: Cache Kurtosis CLI + uses: actions/cache@v2 + with: + path: | + /usr/bin/kurtosis + key: kurtosis-${{ runner.os }} + restore-keys: | + kurtosis- + + - name: Starting the Kurtosis engine + run: kurtosis engine start + + - name: Run parachain + run: | + kurtosis run . --args-file ./local.json --enclave polkadot \ No newline at end of file From 3b6df3395c5a3cf4954e1dbb5413363a371c4a1a Mon Sep 17 00:00:00 2001 From: hemz10 Date: Mon, 20 Nov 2023 12:55:43 +0530 Subject: [PATCH 2/3] test: comment parachain run command to test cache kurtosis --- .github/workflows/smoke.yaml | 6 +++--- local.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/smoke.yaml b/.github/workflows/smoke.yaml index 7d6082e..387d273 100644 --- a/.github/workflows/smoke.yaml +++ b/.github/workflows/smoke.yaml @@ -32,6 +32,6 @@ jobs: - name: Starting the Kurtosis engine run: kurtosis engine start - - name: Run parachain - run: | - kurtosis run . --args-file ./local.json --enclave polkadot \ No newline at end of file + # - name: Run parachain + # run: | + # kurtosis run . --args-file ./local.json --enclave polkadot \ No newline at end of file diff --git a/local.json b/local.json index c2020a6..0a55f73 100644 --- a/local.json +++ b/local.json @@ -1,7 +1,7 @@ { - "chain-type": "local", + "chain-type": "mainnet", "relaychain": { - "name": "polkadot", + "name": "kusama", "nodes": [ { "name": "alice", @@ -17,7 +17,7 @@ }, "para": { - "bifrost": { + "acala": { "nodes": [ { "name": "alice", From 580c075683062761bfcde758fd491a80a758b4cd Mon Sep 17 00:00:00 2001 From: SHANiTH K K <59169878+shanithkk@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:40:47 +0530 Subject: [PATCH 3/3] feat: implement prometheus and grafana for polkadot package (#84) * feat: implement prometheus setup for polkadot package * chore: fix issue with the parachain spawning * chore: code clean up --------- Co-authored-by: Shreyas S Bhat <35568964+shreyasbhat0@users.noreply.github.com> --- main.star | 11 ++++-- package_io/build-spec.star | 35 +++++++++++++++++++ parachain/parachain.star | 25 ++++++++----- parachain/static_files/configs/prometheus.yml | 14 ++++++++ parachain/static_files/javascript/onboard.js | 6 ---- relaychain/relay-chain.star | 14 +++++--- 6 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 parachain/static_files/configs/prometheus.yml diff --git a/main.star b/main.star index 4f741ee..75cc843 100644 --- a/main.star +++ b/main.star @@ -1,14 +1,17 @@ parachain = import_module("./parachain/parachain.star") relay_chain = import_module("./relaychain/relay-chain.star") +package = import_module("./package_io/build-spec.star") def run(plan, args): plan.upload_files(src = "./parachain/static_files/configs", name = "configs") - service_details = {"relaychains": {}, "parachains": {}} + service_details = {"relaychains": {}, "parachains": {}, "prometheus": {}} + if args["chain-type"] == "local": relay_chain_details = relay_chain.start_relay_chains_local(plan, args) service_details["relaychains"] = relay_chain_details - parachain.start_nodes(plan, args, relay_chain_details["relay_service_alice"].ip_address) + parchain_details = parachain.start_nodes(plan, args, relay_chain_details["relay_service_alice"].ip_address) + service_details["parachains"] = parchain_details else: if len(args["relaychain"]) != 0: @@ -18,4 +21,8 @@ def run(plan, args): parachain_info = parachain.run_testnet_mainnet(plan, args, paras) service_details["parachains"] = parachain_info + ip = "{0}:{1}".format(relay_chain_details["relay_service_alice"].ip_address, relay_chain_details["relay_service_alice"].ports["prometheus"].number) + prometheus = package.prometheus(plan, args, ip) + service_details["prometheus"] = prometheus + return service_details diff --git a/package_io/build-spec.star b/package_io/build-spec.star index e7b325a..538a7c4 100644 --- a/package_io/build-spec.star +++ b/package_io/build-spec.star @@ -26,3 +26,38 @@ def create_edit_and_build_spec(plan, service_name, image, chain_name, command, b plan.remove_service(service_name) return service + +relay_chain = import_module("./constant.star") + +def prometheus(plan, args, ip): + create_service_for_build_spec(plan, "prometheus-curl", "badouralix/curl-jq", None) + command = ["sh", "-c", "cp /app/prometheus.yml /tmp/ && sed -i 's/172.16.0.3:9615/{0}/' /tmp/prometheus.yml && /bin/prometheus --config.file=/tmp/prometheus.yml".format(ip)] + prometheus = prometheus_grafana_service(plan, "prometheus", "prom/prometheus:latest", 9090, ip, command, None) + command = ["/run.sh"] + prometheus_grafana_service(plan, "grafana", "grafana/grafana-dev:10.3.0-147071", 3000, ip, command, None) + + return prometheus + +def prometheus_grafana_service(plan, service_name, image, port, ip, command, build_file = None): + files = { + "/app": "configs", + } + if build_file != None: + files["/build"] = build_file + + service = plan.add_service( + name = service_name, + config = ServiceConfig( + image = image, + files = files, + ports = { + "polkadot": PortSpec(port, transport_protocol = "TCP"), + }, + public_ports = { + "polkadot": PortSpec(port, transport_protocol = "TCP"), + }, + entrypoint = command, + ), + ) + + return service diff --git a/parachain/parachain.star b/parachain/parachain.star index d1a175f..fa9a200 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -12,7 +12,7 @@ def spawn_parachain(plan, chain_name, image, command, build_file): files["/build"] = build_file parachain_node = plan.add_service( - name = "start-{}-node".format(chain_name), + name = "start-{}-local-node".format(chain_name), config = ServiceConfig( image = image, files = files, @@ -25,7 +25,7 @@ def spawn_parachain(plan, chain_name, image, command, build_file): return parachain_node -def start_local_parachain_node(plan, parachain, para_id): +def start_local_parachain_node(plan, args, parachain, para_id): parachain_details = parachain_list.parachain_images[parachain] image = parachain_details["image"] binary = parachain_details["entrypoint"] @@ -38,16 +38,25 @@ def start_local_parachain_node(plan, parachain, para_id): "-c", "{0} --chain=/build/{1}-raw.json --ws-external --rpc-external --rpc-cors=all --name={1} --collator --rpc-methods=unsafe --force-authoring --execution=wasm --alice -- --chain=/app/raw-polkadot.json --execution=wasm".format(binary, chain_name), ] + parachain_details = {} + for node in args["para"][parachain]["nodes"]: + parachain_detail = spawn_parachain(plan, "{}-{}".format(chain_name, node["name"]), image, exec_comexec_commandmand, build_file = raw_service.name) + parachain_details[node["name"]] = parachain_detail - spawn_parachain(plan, chain_name, image, exec_comexec_commandmand, build_file = raw_service.name) + plan.print(parachain_details) + return parachain_details def start_nodes(plan, args, relay_chain_ip): parachains = args["para"] + parachain_details = {} for parachain in parachains: + parachain_details[parachain] = {} para_id = register_para_slot.register_para_id(plan, relay_chain_ip) - start_local_parachain_node(plan, parachain, para_id) + parachain_details[parachain] = start_local_parachain_node(plan, args, parachain, para_id) register_para_slot.onboard_genesis_state_and_wasm(plan, para_id, parachain, relay_chain_ip) + return parachain_details + def run_testnet_mainnet(plan, args, parachain): if args["chain-type"] == "testnet": main_chain = "rococo" @@ -100,19 +109,19 @@ def run_testnet_mainnet(plan, args, parachain): if parachain in constant.CHAIN_COMMAND: command = command + ["--", "--chain={0}".format(main_chain)] - + if parachain == "kilt-spiritnet" and args["chain-type"] == "testnet": - command = command + ["--", "--chain=/node/dev-specs/kilt-parachain/peregrine-relay.json"] + command = command + ["--", "--chain=/node/dev-specs/kilt-parachain/peregrine-relay.json"] if parachain in constant.BINARY_COMMAND_CHAINS: binary = parachain_details["entrypoint"] command = [binary] + command - node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}".format(parachain, node["name"]), command) + node_details = node_setup.run_testnet_node_with_entrypoint(plan, image, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), command) parachain_info[parachain]["parachain_" + node["name"]] = node_details else: - node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}".format(parachain, node["name"]), command) + node_details = node_setup.run_testnet_node_with_command(plan, image, "{0}-{1}-{2}".format(parachain, node["name"], args["chain-type"]), command) parachain_info[parachain]["parachain_" + node["name"]] = node_details return parachain_info diff --git a/parachain/static_files/configs/prometheus.yml b/parachain/static_files/configs/prometheus.yml new file mode 100644 index 0000000..e4616c1 --- /dev/null +++ b/parachain/static_files/configs/prometheus.yml @@ -0,0 +1,14 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s + + +scrape_configs: + - job_name: "prometheus" + scrape_interval: 5s + static_configs: + - targets: ["localhost:9090"] + - job_name: "substrate_node" + scrape_interval: 5s + static_configs: + - targets: ["172.16.0.3:9615"] \ No newline at end of file diff --git a/parachain/static_files/javascript/onboard.js b/parachain/static_files/javascript/onboard.js index 32fdf2a..167f3a3 100644 --- a/parachain/static_files/javascript/onboard.js +++ b/parachain/static_files/javascript/onboard.js @@ -4,7 +4,6 @@ const fs = require("fs"); const run = async () => { try { console.log("Parsing Args ..."); - // 0 & 1 are command context const endpoint = process.argv[2]; const seed = process.argv[3]; const id = process.argv[4]; @@ -42,14 +41,9 @@ const run = async () => { parachain: true, }; - console.log(paraGenesisArgs); let genesis = api.createType("ParaGenesisArgs", paraGenesisArgs); const nonce = Number((await api.query.system.account(alice.address)).nonce); - - console.log( - `--- Submitting extrinsic to register parachain ${id}. (nonce: ${nonce}) ---` - ); const sudoCall = await api.tx.sudo .sudo(api.tx.parasSudoWrapper.sudoScheduleParaInitialize(id, genesis)) .signAndSend(alice, { nonce: nonce, era: 0 }, (result) => { diff --git a/relaychain/relay-chain.star b/relaychain/relay-chain.star index 856d6f3..28833e1 100644 --- a/relaychain/relay-chain.star +++ b/relaychain/relay-chain.star @@ -45,13 +45,15 @@ def spawn_multiple_relay(plan, count): def start_relay_chains_local(plan, args): relay_nodes = args["relaychain"]["nodes"] relay_detail = {} + prometheus_port = 9615 for node in relay_nodes: - service_details = start_relay_chain_local(plan, node["name"], node["port"]) + service_details = start_relay_chain_local(plan, node["name"], node["port"], prometheus_port) relay_detail["relay_service_" + node["name"]] = service_details + prometheus_port = prometheus_port + 1 return relay_detail -def start_relay_chain_local(plan, name, port): - exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm".format(name)] +def start_relay_chain_local(plan, name, port, prometheus_port): + exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm --prometheus-external".format(name)] service_details = plan.add_service( name = "polkadot-{0}".format(name), config = ServiceConfig( @@ -60,10 +62,12 @@ def start_relay_chain_local(plan, name, port): "/app": "configs", }, ports = { - "polkadot": PortSpec(9944, transport_protocol = "TCP"), + "ws": PortSpec(9944, transport_protocol = "TCP"), + "prometheus": PortSpec(9615, transport_protocol = "TCP"), }, public_ports = { - "polkadot": PortSpec(port, transport_protocol = "TCP"), + "ws": PortSpec(port, transport_protocol = "TCP"), + "prometheus": PortSpec(prometheus_port, transport_protocol = "TCP"), }, entrypoint = exec_command, ),