From b492e7e23f5e2719ca1fe85954cf716db4b8f321 Mon Sep 17 00:00:00 2001 From: Alejandro Avagnina Date: Mon, 8 Jul 2024 10:20:27 -0300 Subject: [PATCH] chore: prime-node / vector-node / readiness probe --- bootstrap/configs/prime-testnet/config.json | 109 ++++++++++++++++++ bootstrap/configs/prime-testnet/topology.json | 14 +++ bootstrap/feature/config.tf | 10 ++ bootstrap/feature/readiness.sh | 33 ++++++ bootstrap/instance/node.tf | 54 ++++++++- 5 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 bootstrap/configs/prime-testnet/config.json create mode 100644 bootstrap/configs/prime-testnet/topology.json create mode 100644 bootstrap/feature/config.tf create mode 100644 bootstrap/feature/readiness.sh diff --git a/bootstrap/configs/prime-testnet/config.json b/bootstrap/configs/prime-testnet/config.json new file mode 100644 index 0000000..828312e --- /dev/null +++ b/bootstrap/configs/prime-testnet/config.json @@ -0,0 +1,109 @@ +{ + "ByronGenesisFile": "/genesis/byron/genesis.json", + "ShelleyGenesisFile": "/genesis/shelley/genesis.json", + "AlonzoGenesisFile": "/genesis/shelley/genesis.alonzo.json", + "ConwayGenesisFile": "/genesis/shelley/genesis.conway.json", + "ByronGenesisHash": "acd3e7c4cc071ae176fa253e654f0dd4e759892b16e958d8bd3c393f5c6c66d2", + "ShelleyGenesisHash": "0b67b0cb16e973478888efb1c7f69fca8e80489369afed94624a588e94a94f2b", + "AlonzoGenesisHash": "0f715ff78fcab739c6cb2cc1073eb87d0ffe3514218bfa0337d416f6fbaf7886", + "ConwayGenesisHash": "d43d3f38e01848bddf67e66fe29fbd236aca252de58c7f2c1904c67107c17842", + "SocketPath": "db/node.socket", + "PBftSignatureThreshold": 0.6, + "MaxConcurrencyBulkSync": 1, + "MaxConcurrencyDeadline": 2, + "Protocol": "Cardano", + "RequiresNetworkMagic": "RequiresMagic", + "LastKnownBlockVersion-Major": 6, + "LastKnownBlockVersion-Minor": 0, + "LastKnownBlockVersion-Alt": 0, + "TurnOnLogging": true, + "TurnOnLogMetrics": true, + "minSeverity": "Debug", + "TracingVerbosity": "NormalVerbosity", + "setupBackends": ["KatipBK"], + "defaultBackends": ["KatipBK"], + "hasEKG": 12788, + "hasPrometheus": [ + "0.0.0.0", + 12798 + ], + "setupScribes": [ + { + "scKind": "StdoutSK", + "scName": "stdout", + "scFormat": "ScText" + } + ], + "defaultScribes": [ + ["StdoutSK", "stdout"] + ], + "rotation": { + "rpLogLimitBytes": 5000000, + "rpKeepFilesNum": 3, + "rpMaxAgeHours": 24 + }, + "TraceBlockFetchClient": false, + "TraceBlockFetchDecisions": false, + "TraceBlockFetchProtocol": false, + "TraceBlockFetchProtocolSerialised": false, + "TraceBlockFetchServer": false, + "TraceBlockchainTime": false, + "TraceChainDb": true, + "TraceChainSyncClient": false, + "TraceChainSyncBlockServer": false, + "TraceChainSyncHeaderServer": false, + "TraceChainSyncProtocol": false, + "TraceDNSResolver": true, + "TraceDNSSubscription": true, + "TraceErrorPolicy": true, + "TraceLocalErrorPolicy": true, + "TraceForge": true, + "TraceHandshake": false, + "TraceIpSubscription": true, + "TraceLocalRootPeers": true, + "TracePublicRootPeers": true, + "TracePeerSelection": true, + "TraceDebugPeerSelection": false, + "TracePeerSelectionActions": true, + "TraceConnectionManager": true, + "TraceServer": true, + "TraceLocalConnectionManager": false, + "TraceLocalServer": false, + "TraceLocalChainSyncProtocol": false, + "TraceLocalHandshake": false, + "TraceLocalTxSubmissionProtocol": false, + "TraceLocalTxSubmissionServer": false, + "TraceMempool": true, + "TraceMux": false, + "TraceTxInbound": false, + "TraceTxOutbound": false, + "TraceTxSubmissionProtocol": false, + "options": { + "mapBackends": { + "cardano.node.metrics": ["EKGViewBK"] + }, + "mapScribes": { + "cardano.node.metrics": ["FileSK::logs/mainnet.log"] + }, + "mapSeverity": { + "cardano.node.ChainDB": "Notice", + "cardano.node.DnsSubscription": "Debug" + } + }, + "TestShelleyHardForkAtEpoch": 0, + "TestAllegraHardForkAtEpoch": 0, + "TestMaryHardForkAtEpoch": 0, + "TestAlonzoHardForkAtEpoch": 0, + "TestBabbageHardForkAtEpoch": 0, + "ExperimentalProtocolsEnabled": true, + "EnableP2P": true, + "TargetNumberOfRootPeers": 20, + "TargetNumberOfKnownPeers": 20, + "TargetNumberOfEstablishedPeers": 10, + "TargetNumberOfActivePeers": 10, + "TraceInboundGovernorCounters": true, + "TraceConnectionManagerTransitions": true, + "TraceLedgerPeers": true, + "TracePeerSelectionCounters": true, + "TracePeerStateActions": true +} diff --git a/bootstrap/configs/prime-testnet/topology.json b/bootstrap/configs/prime-testnet/topology.json new file mode 100644 index 0000000..264ad1e --- /dev/null +++ b/bootstrap/configs/prime-testnet/topology.json @@ -0,0 +1,14 @@ +{ + "localRoots": [ + ], + "publicRoots" : [ + { "accessPoints": [ + { "address": "relay-0.prime.testnet.apexfusion.org", "port": 5521 }, + { "address": "relay-1.prime.testnet.apexfusion.org", "port": 5521 } + ], + "advertise": true, + "valency": 1 + } + ], + "useLedgerAfterSlot": 0 +} diff --git a/bootstrap/feature/config.tf b/bootstrap/feature/config.tf new file mode 100644 index 0000000..709b135 --- /dev/null +++ b/bootstrap/feature/config.tf @@ -0,0 +1,10 @@ +resource "kubernetes_config_map" "node-readiness" { + metadata { + namespace = var.namespace + name = "node-readiness" + } + + data = { + "readiness.sh" = "${file("${path.module}/readiness.sh")}" + } +} diff --git a/bootstrap/feature/readiness.sh b/bootstrap/feature/readiness.sh new file mode 100644 index 0000000..e3fb4a4 --- /dev/null +++ b/bootstrap/feature/readiness.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if ! command -v jq &> /dev/null; then + echo "Error: jq is not installed. Please install jq to use this script." + exit 1 +fi + +if ! command -v cardano-cli &> /dev/null; then + echo "Error: cardano-cli is not installed. Please install cardano-cli to use this script." + exit 1 +fi + +if ! command -v bc &> /dev/null; then + echo "Error: bc is not installed. Please install bc to use this script." + exit 1 +fi + +if [ "$CARDANO_NODE_NETWORK_ID" == "764824073" ]; then + JSON_DATA=$(cardano-cli query tip --mainnet) +else + JSON_DATA=$(cardano-cli query tip --testnet-magic "$CARDANO_NODE_NETWORK_ID") +fi + +SYNC_PROGRESS=$(echo "$JSON_DATA" | jq -r '.syncProgress') +MIN_EXPECTED_SYNC_PROGRESS="99.00" +MAX_EXPECTED_SYNC_PROGRESS="100.00" + +if (( $(echo "$SYNC_PROGRESS >= $MIN_EXPECTED_SYNC_PROGRESS" | bc -l) )) && (( $(echo "$SYNC_PROGRESS <= $MAX_EXPECTED_SYNC_PROGRESS" | bc -l) )); then + echo "syncProgress is within the acceptable range of 99 to 100" +else + echo "Error: syncProgress is not within the acceptable range of 99 to 100" + exit 1 +fi diff --git a/bootstrap/instance/node.tf b/bootstrap/instance/node.tf index 0a88455..a0737dc 100644 --- a/bootstrap/instance/node.tf +++ b/bootstrap/instance/node.tf @@ -21,7 +21,7 @@ locals { "--port", "3000" ] - arguments = var.is_custom == true ? local.custom_arguments : local.default_arguments + arguments = var.network == "vector-testnet" ? [] : var.is_custom == true ? local.custom_arguments : local.default_arguments n2n_port_name = contains(["mainnet", "preview", "preprod"], var.network) && var.release == "stable" ? "n2n-${var.network}" : "n2n" } @@ -157,6 +157,14 @@ resource "kubernetes_stateful_set_v1" "node" { } } + volume { + name = "node-readiness" + config_map { + name = "node-readiness" + default_mode = "0500" + } + } + container { image = "${var.node_image}:${var.node_image_tag}" name = "main" @@ -173,6 +181,33 @@ resource "kubernetes_stateful_set_v1" "node" { value = var.restore } + env { + name = "CARDANO_NODE_SOCKET_PATH" + value = "/ipc/node.socket" + } + + env { + name = "CARDANO_NODE_NETWORK_ID" + value = var.magic + } + + dynamic "env" { + for_each = var.network == "vector-testnet" ? toset([1]) : toset([]) + + content { + name = "PORT" + value = "3000" + } + } + + dynamic "env" { + for_each = var.network == "vector-testnet" ? toset([1]) : toset([]) + content { + name = "NETWORK" + value = "testnet" + } + } + resources { limits = var.node_resources.limits requests = var.node_resources.requests @@ -198,6 +233,11 @@ resource "kubernetes_stateful_set_v1" "node" { name = "ipc" } + volume_mount { + mount_path = "/probes" + name = "node-readiness" + } + dynamic "volume_mount" { for_each = var.is_custom == true ? toset([1]) : toset([]) @@ -207,10 +247,14 @@ resource "kubernetes_stateful_set_v1" "node" { } } - readiness_probe { - initial_delay_seconds = 20 - exec { - command = ["test", "-S", "/ipc/node.socket"] + dynamic "readiness_probe" { + for_each = var.network != "vector-testnet" ? toset([1]) : toset([]) + + content { + initial_delay_seconds = 20 + exec { + command = ["/probes/readiness.sh"] + } } } }