From 16b963dfba6b4c8713f600d0124e215459997007 Mon Sep 17 00:00:00 2001 From: Alejandro Avagnina Date: Thu, 1 Aug 2024 15:06:42 -0300 Subject: [PATCH] chore: update bootstrap for vector testnet and blinklabs images --- bootstrap/cell/main.tf | 8 + bootstrap/cell/variables.tf | 7 + bootstrap/configs/vector-testnet/config.json | 157 ++++++------ .../vector-testnet/db-sync-config.json | 234 ++++++++++-------- bootstrap/instance/dbsync.tf | 110 ++++++-- bootstrap/instance/main.tf | 29 +++ bootstrap/variables.tf | 8 +- 7 files changed, 353 insertions(+), 200 deletions(-) diff --git a/bootstrap/cell/main.tf b/bootstrap/cell/main.tf index eb3369f..19bf2ba 100644 --- a/bootstrap/cell/main.tf +++ b/bootstrap/cell/main.tf @@ -3,6 +3,7 @@ // network). locals { postgres_host = "postgres-dbsync-v3-${var.salt}" + dbsync_image = "ghcr.io/demeter-run/dbsync" db_volume_claim = coalesce(var.db_volume_claim, "pvc-${var.salt}") postgres_config_name = coalesce(var.postgres_config_name, "postgres-config-${var.salt}") } @@ -48,11 +49,18 @@ module "dbsync_instances" { namespace = var.namespace network = each.value.network salt = coalesce(each.value.salt, var.salt) + dbsync_image = coalesce(each.value.dbsync_image, local.dbsync_image) dbsync_image_tag = each.value.dbsync_image_tag node_n2n_tcp_endpoint = each.value.node_n2n_tcp_endpoint release = each.value.release topology_zone = coalesce(each.value.topology_zone, var.topology_zone) sync_status = each.value.sync_status + compute_arch = coalesce(each.value.compute_arch, "arm64") + compute_profile = coalesce(each.value.compute_profile, "mem-intensive") + availability_sla = coalesce(each.value.availability_sla, "consistent") + empty_args = coalesce(each.value.empty_args, false) + custom_config = coalesce(each.value.custom_config, true) + network_env_var = coalesce(each.value.network_env_var, false) enable_postgrest = each.value.enable_postgrest postgres_database = "dbsync-${each.value.network}" diff --git a/bootstrap/cell/variables.tf b/bootstrap/cell/variables.tf index 61fa7d6..2598085 100644 --- a/bootstrap/cell/variables.tf +++ b/bootstrap/cell/variables.tf @@ -89,12 +89,19 @@ variable "instances" { type = map(object({ salt = optional(string) network = string + dbsync_image = optional(string) dbsync_image_tag = string node_n2n_tcp_endpoint = string release = string sync_status = string enable_postgrest = bool + availability_sla = optional(string) + compute_profile = optional(string) + compute_arch = optional(string) topology_zone = optional(string) + empty_args = optional(bool, false) + custom_config = optional(bool, true) + network_env_var = optional(string, false) dbsync_resources = optional(object({ requests = map(string) limits = map(string) diff --git a/bootstrap/configs/vector-testnet/config.json b/bootstrap/configs/vector-testnet/config.json index 6136690..d300f21 100644 --- a/bootstrap/configs/vector-testnet/config.json +++ b/bootstrap/configs/vector-testnet/config.json @@ -1,107 +1,112 @@ { - "ByronGenesisFile": "/genesis/vector-testnet/byron.json", - "ShelleyGenesisFile": "/genesis/vector-testnet/shelley.json", - "AlonzoGenesisFile": "/genesis/vector-testnet/alonzo.json", - "ConwayGenesisFile": "/genesis/vector-testnet/conway.json", - "SocketPath": "db/node.socket", - "PBftSignatureThreshold": 0.6, - "MaxConcurrencyBulkSync": 1, - "MaxConcurrencyDeadline": 2, - "Protocol": "Cardano", - "RequiresNetworkMagic": "RequiresMagic", + "AlonzoGenesisFile": "/genesis/alonzo-genesis.json", + "AlonzoGenesisHash": "694a30a4be097b10989dde200b273c52df0c4d2e2981cee3537bed7122302291", + "ByronGenesisFile": "/genesis/byron-genesis.json", + "ByronGenesisHash": "765ffc6574cd68ee743479e7cc2855d9f4066dda5d65fe56b9762e03d193ed0b", + "ConwayGenesisFile": "/genesis/conway-genesis.json", + "ConwayGenesisHash": "2629ff28ff9539312851b626212dc45be41784c450ab396c0b1da40b2429b78e", + "EnableP2P": false, + "ExperimentalProtocolsEnabled": true, + "LastKnownBlockVersion-Alt": 0, "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": "FileSK", - "scName": "logs/mainnet.log", - "scFormat": "ScText" - }, - { - "scKind": "StdoutSK", - "scName": "stdout", - "scFormat": "ScText" - } - ], - "defaultScribes": [ - ["FileSK", "logs/mainnet.log"], - ["StdoutSK", "stdout"] - ], - "rotation": { - "rpLogLimitBytes": 5000000, - "rpKeepFilesNum": 3, - "rpMaxAgeHours": 24 - }, + "Protocol": "Cardano", + "RequiresNetworkMagic": "RequiresMagic", + "ShelleyGenesisFile": "/genesis/shelley-genesis.json", + "ShelleyGenesisHash": "8189bc6863f6ac448fca1e08c4e8ade54b05b7b0cfcd3b84a7932324ef782a98", + "TargetNumberOfActivePeers": 20, + "TargetNumberOfEstablishedPeers": 50, + "TargetNumberOfKnownPeers": 100, + "TargetNumberOfRootPeers": 100, + "TestAllegraHardForkAtEpoch": 0, + "TestAlonzoHardForkAtEpoch": 0, + "TestBabbageHardForkAtEpoch": 0, + "TestMaryHardForkAtEpoch": 0, + "TestShelleyHardForkAtEpoch": 0, + "TraceAcceptPolicy": true, "TraceBlockFetchClient": false, "TraceBlockFetchDecisions": false, "TraceBlockFetchProtocol": false, "TraceBlockFetchProtocolSerialised": false, "TraceBlockFetchServer": false, - "TraceBlockchainTime": false, "TraceChainDb": true, - "TraceChainSyncClient": false, "TraceChainSyncBlockServer": false, + "TraceChainSyncClient": false, "TraceChainSyncHeaderServer": false, "TraceChainSyncProtocol": false, + "TraceConnectionManager": true, "TraceDNSResolver": true, "TraceDNSSubscription": true, + "TraceDiffusionInitialization": true, "TraceErrorPolicy": true, - "TraceLocalErrorPolicy": true, "TraceForge": true, - "TraceHandshake": false, + "TraceHandshake": true, + "TraceInboundGovernor": true, "TraceIpSubscription": true, - "TraceLocalRootPeers": true, - "TracePublicRootPeers": true, - "TracePeerSelection": true, - "TraceDebugPeerSelection": false, - "TracePeerSelectionActions": true, - "TraceConnectionManager": true, - "TraceServer": true, - "TraceLocalConnectionManager": false, - "TraceLocalServer": false, + "TraceLedgerPeers": true, "TraceLocalChainSyncProtocol": false, - "TraceLocalHandshake": false, + "TraceLocalConnectionManager": true, + "TraceLocalErrorPolicy": true, + "TraceLocalHandshake": true, + "TraceLocalRootPeers": true, "TraceLocalTxSubmissionProtocol": false, "TraceLocalTxSubmissionServer": false, "TraceMempool": true, "TraceMux": false, + "TracePeerSelection": true, + "TracePeerSelectionActions": true, + "TracePublicRootPeers": true, + "TraceServer": true, "TraceTxInbound": false, "TraceTxOutbound": false, "TraceTxSubmissionProtocol": false, + "TracingVerbosity": "NormalVerbosity", + "TurnOnLogMetrics": true, + "TurnOnLogging": true, + "defaultBackends": [ + "KatipBK" + ], + "defaultScribes": [ + [ + "StdoutSK", + "stdout" + ] + ], + "hasEKG": 12788, + "hasPrometheus": [ + "0.0.0.0", + 12798 + ], + "minSeverity": "Debug", "options": { "mapBackends": { - "cardano.node.metrics": ["EKGViewBK"] + "cardano.node.metrics": [ + "EKGViewBK" + ], + "cardano.node.resources": [ + "EKGViewBK" + ] }, - "mapScribes": { - "cardano.node.metrics": ["FileSK::logs/mainnet.log"] - }, - "mapSeverity": { - "cardano.node.ChainDB": "Notice", - "cardano.node.DnsSubscription": "Debug" + "mapSubtrace": { + "cardano.node.metrics": { + "subtrace": "Neutral" + } } }, - "TestShelleyHardForkAtEpoch": 0, - "TestAllegraHardForkAtEpoch": 0, - "TestMaryHardForkAtEpoch": 0, - "TestAlonzoHardForkAtEpoch": 0, - "TestBabbageHardForkAtEpoch": 0, - "ExperimentalProtocolsEnabled": true, - "ApplicationName":"cardano-sl", - "ApplicationVersion":0, - "ByronGenesisHash":"abc5e260bf7c5d7008eab849705fc0eae911b638dd6687b1f10cef2e2bc8a713", - "ShelleyGenesisHash":"fb2ca1cc879a9a7600103c2170c9d58e366cd77e17edf39a0e7bc1504f573e88", - "AlonzoGenesisHash":"1cd94b66eade0670885744a858accdb2c3249e43e247db2c66b158050ec6a3e4", - "ConwayGenesisHash":"d43d3f38e01848bddf67e66fe29fbd236aca252de58c7f2c1904c67107c17842" + "rotation": { + "rpKeepFilesNum": 10, + "rpLogLimitBytes": 5000000, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "KatipBK" + ], + "setupScribes": [ + { + "scFormat": "ScText", + "scKind": "StdoutSK", + "scName": "stdout", + "scRotation": null + } + ] } diff --git a/bootstrap/configs/vector-testnet/db-sync-config.json b/bootstrap/configs/vector-testnet/db-sync-config.json index e63da69..c5e296a 100644 --- a/bootstrap/configs/vector-testnet/db-sync-config.json +++ b/bootstrap/configs/vector-testnet/db-sync-config.json @@ -1,116 +1,134 @@ { - "EnableLogMetrics":false, - "EnableLogging":true, - "NetworkName":"testnet", - "NodeConfigFile":"config.json", - "PrometheusPort":8080, - "RequiresNetworkMagic":"RequiresMagic", - "defaultBackends":[ + "NetworkName": "mainnet", + "EnableLogMetrics": false, + "EnableLogging": true, + "NodeConfigFile": "config.json", + "minSeverity": "Info", + "rotation": { + "rpLogLimitBytes": 5000000, + "rpKeepFilesNum": 10, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "AggregationBK", + "KatipBK" + ], + "defaultBackends": [ "KatipBK" - ], - "defaultScribes":[ + ], + "setupScribes": [ + { + "scKind": "StdoutSK", + "scName": "stdout", + "scFormat": "ScText", + "scRotation": null + } + ], + "defaultScribes": [ [ - "StdoutSK", - "stdout" + "StdoutSK", + "stdout" ] - ], - "minSeverity":"Info", - "options":{ - "cfokey":{ - "value":"Release-1.0.0" - }, - "mapBackends":{ - - }, - "mapSeverity":{ - "db-sync-node":"Info", - "db-sync-node.Mux":"Error", - "db-sync-node.Subscription":"Error" + ], + "options": { + "cfokey": { + "value": "Release-1.0.0" }, - "mapSubtrace":{ - "#ekgview":{ - "contents":[ - [ - { - "contents":"cardano.epoch-validation.benchmark", - "tag":"Contains" - }, - [ - { - "contents":".monoclock.basic.", - "tag":"Contains" - } - ] - ], - [ - { - "contents":"cardano.epoch-validation.benchmark", - "tag":"Contains" - }, - [ - { - "contents":"diff.RTS.cpuNs.timed.", - "tag":"Contains" - } - ] - ], - [ - { - "contents":"#ekgview.#aggregation.cardano.epoch-validation.benchmark", - "tag":"StartsWith" - }, - [ - { - "contents":"diff.RTS.gcNum.timed.", - "tag":"Contains" - } - ] - ] + "mapSubtrace": { + "benchmark": { + "contents": [ + "GhcRtsStats", + "MonotonicClock" + ], + "subtrace": "ObservableTrace" + }, + "#ekgview": { + "contents": [ + [ + { + "tag": "Contains", + "contents": "cardano.epoch-validation.benchmark" + }, + [ + { + "tag": "Contains", + "contents": ".monoclock.basic." + } + ] ], - "subtrace":"FilterTrace" - }, - "#messagecounters.aggregation":{ - "subtrace":"NoTrace" - }, - "#messagecounters.ekgview":{ - "subtrace":"NoTrace" - }, - "#messagecounters.katip":{ - "subtrace":"NoTrace" - }, - "#messagecounters.monitoring":{ - "subtrace":"NoTrace" - }, - "#messagecounters.switchboard":{ - "subtrace":"NoTrace" - }, - "benchmark":{ - "contents":[ - "GhcRtsStats", - "MonotonicClock" + [ + { + "tag": "Contains", + "contents": "cardano.epoch-validation.benchmark" + }, + [ + { + "tag": "Contains", + "contents": "diff.RTS.cpuNs.timed." + } + ] ], - "subtrace":"ObservableTrace" - }, - "cardano.epoch-validation.utxo-stats":{ - "subtrace":"NoTrace" - } - } - }, - "rotation":{ - "rpKeepFilesNum":10, - "rpLogLimitBytes":5000000, - "rpMaxAgeHours":24 - }, - "setupBackends":[ - "AggregationBK", - "KatipBK" - ], - "setupScribes":[ - { - "scFormat":"ScText", - "scKind":"StdoutSK", - "scName":"stdout", - "scRotation":null + [ + { + "tag": "StartsWith", + "contents": "#ekgview.#aggregation.cardano.epoch-validation.benchmark" + }, + [ + { + "tag": "Contains", + "contents": "diff.RTS.gcNum.timed." + } + ] + ] + ], + "subtrace": "FilterTrace" + }, + "cardano.epoch-validation.utxo-stats": { + "subtrace": "NoTrace" + }, + "#messagecounters.aggregation": { + "subtrace": "NoTrace" + }, + "#messagecounters.ekgview": { + "subtrace": "NoTrace" + }, + "#messagecounters.switchboard": { + "subtrace": "NoTrace" + }, + "#messagecounters.katip": { + "subtrace": "NoTrace" + }, + "#messagecounters.monitoring": { + "subtrace": "NoTrace" + }, + "cardano.#messagecounters.aggregation": { + "subtrace": "NoTrace" + }, + "cardano.#messagecounters.ekgview": { + "subtrace": "NoTrace" + }, + "cardano.#messagecounters.switchboard": { + "subtrace": "NoTrace" + }, + "cardano.#messagecounters.katip": { + "subtrace": "NoTrace" + }, + "cardano.#messagecounters.monitoring": { + "subtrace": "NoTrace" + } + }, + "mapBackends": { + "cardano.epoch-validation.benchmark": [ + "AggregationBK" + ], + "#aggregation.cardano.epoch-validation.benchmark": [ + "EKGViewBK" + ] + }, + "mapSeverity": { + "db-sync-node.Subscription": "Error", + "db-sync-node.Mux": "Error", + "db-sync-node": "Info" } - ] -} \ No newline at end of file + } + } \ No newline at end of file diff --git a/bootstrap/instance/dbsync.tf b/bootstrap/instance/dbsync.tf index 1aba754..2d70e9c 100644 --- a/bootstrap/instance/dbsync.tf +++ b/bootstrap/instance/dbsync.tf @@ -75,6 +75,56 @@ resource "kubernetes_deployment_v1" "db_sync" { } } + dynamic "init_container" { + for_each = var.network == "vector-testnet" ? toset([1]) : toset([]) + + content { + name = "init-pgpass" + + image = "busybox" + + command = [ + "sh", "-c", <<-EOT + echo "$(echo $POSTGRES_HOST):$(echo $POSTGRES_PORT):$(echo $POSTGRES_DB):$(echo $POSTGRES_USER):$(echo $POSTGRES_PASSWORD)" > /etc/pgpass/pgpass + chmod 600 /etc/pgpass/pgpass + EOT + ] + env { + name = "POSTGRES_USER" + value = "postgres" + } + + env { + name = "POSTGRES_PASSWORD" + value_from { + secret_key_ref { + key = "password" + name = var.postgres_secret_name + } + } + } + + env { + name = "POSTGRES_DB" + value = var.postgres_database + } + + env { + name = "POSTGRES_HOST" + value = var.postgres_instance_name + } + + env { + name = "POSTGRES_PORT" + value = "5432" + } + volume_mount { + name = "pgpass-volume" + mount_path = "/etc/pgpass" + } + } + } + container { args = [ "-d", @@ -95,16 +145,16 @@ resource "kubernetes_deployment_v1" "db_sync" { container { name = "dbsync" - image = "ghcr.io/demeter-run/dbsync:${var.dbsync_image_tag}" + image = "${var.dbsync_image}:${var.dbsync_image_tag}" resources { limits = var.dbsync_resources.limits requests = var.dbsync_resources.requests } - args = [ + args = var.empty_args ? [] : [ "--config /etc/dbsync/db-sync-config.json", - "--socket-path /node-ipc/node.socket" + "--socket-path /node-ipc/node.socket", ] env { @@ -144,12 +194,23 @@ resource "kubernetes_deployment_v1" "db_sync" { env { name = "NETWORK" - value = "" + value = var.network_env_var ? var.network : "" } - volume_mount { - mount_path = "/etc/dbsync" - name = "config" + dynamic "env" { + for_each = var.network == "vector-testnet" ? toset([1]) : toset([]) + content { + name = "PGPASSFILE" + value = "/etc/pgpass/pgpass" + } + } + + dynamic "volume_mount" { + for_each = var.custom_config ? toset([1]) : toset([]) + content { + name = "config" + mount_path = "/etc/dbsync" + } } volume_mount { @@ -162,16 +223,26 @@ resource "kubernetes_deployment_v1" "db_sync" { name = "state" } + dynamic "volume_mount" { + for_each = var.network == "vector-testnet" ? toset([1]) : toset([]) + content { + name = "pgpass-volume" + mount_path = "/etc/pgpass" + } + } + port { container_port = 8080 name = "metrics" } } - - volume { - name = "config" - config_map { - name = local.config_map_name + dynamic "volume" { + for_each = var.custom_config ? toset([1]) : toset([0]) + content { + name = "config" + config_map { + name = local.config_map_name + } } } @@ -187,6 +258,15 @@ resource "kubernetes_deployment_v1" "db_sync" { } } + dynamic "volume" { + for_each = var.network == "vector-testnet" ? toset([1]) : toset([]) + content { + name = "pgpass-volume" + empty_dir {} + } + } + + toleration { key = "demeter.run/workload" operator = "Equal" @@ -198,21 +278,21 @@ resource "kubernetes_deployment_v1" "db_sync" { effect = "NoSchedule" key = "demeter.run/compute-profile" operator = "Equal" - value = "mem-intensive" + value = var.compute_profile } toleration { effect = "NoSchedule" key = "demeter.run/compute-arch" operator = "Equal" - value = "arm64" + value = var.compute_arch } toleration { effect = "NoSchedule" key = "demeter.run/availability-sla" operator = "Equal" - value = "consistent" + value = var.availability_sla } } } diff --git a/bootstrap/instance/main.tf b/bootstrap/instance/main.tf index d16e197..64c5920 100644 --- a/bootstrap/instance/main.tf +++ b/bootstrap/instance/main.tf @@ -8,6 +8,11 @@ terraform { variable "namespace" {} + +variable "dbsync_image" { + type = string + default = "ghcr.io/demeter-run/dbsync" +} variable "dbsync_image_tag" { default = "132ffd0007054bfadd17b23ed608529447833b99" } @@ -84,6 +89,30 @@ variable "postgres_secret_name" { type = string } +variable "compute_arch" { + default = "arm64" +} + +variable "compute_profile" { + default = "mem-intensive" +} + +variable "availability_sla" { + default = "consistent" +} + +variable "empty_args" { + default = false +} + +variable "custom_config" { + default = true +} + +variable "network_env_var" { + default = false +} + module "configs" { source = "../configs" network = var.network diff --git a/bootstrap/variables.tf b/bootstrap/variables.tf index f5a8e06..820abc1 100644 --- a/bootstrap/variables.tf +++ b/bootstrap/variables.tf @@ -114,12 +114,18 @@ variable "cells" { instances = map(object({ salt = optional(string) network = string + dbsync_image = optional(string) dbsync_image_tag = string node_n2n_tcp_endpoint = string release = string sync_status = string enable_postgrest = bool - topology_zone = optional(string) + compute_arch = optional(string) + compute_profile = optional(string) + empty_args = optional(bool, false) + custom_config = optional(bool, true) + network_env_var = optional(string, false) + topology_zone = optional(string) dbsync_resources = optional(object({ requests = map(string) limits = map(string)