From 46b3d8603051c5de06502fe122c23dad2be1489e Mon Sep 17 00:00:00 2001 From: 0xb10c Date: Thu, 11 Apr 2024 15:19:52 +0200 Subject: [PATCH 1/2] add: addrman-observer support --- MANIFEST.in | 1 + src/templates/addrman_observer_config.toml | 8 +++++++ src/warnet/services.py | 9 ++++++++ src/warnet/warnet.py | 27 +++++++++++++++++++--- test/data/services.graphml | 4 ++-- test/graph_test.py | 9 ++++++++ 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/templates/addrman_observer_config.toml diff --git a/MANIFEST.in b/MANIFEST.in index 508588d66..59767adcb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include src/schema/*.json include src/templates/bitcoin.conf include src/templates/fork_observer_config.toml +include src/templates/addrman_observer_config.toml include src/templates/addrman.patch include src/templates/isroutable.patch graft src/templates/k8s diff --git a/src/templates/addrman_observer_config.toml b/src/templates/addrman_observer_config.toml new file mode 100644 index 000000000..4bfcdb79b --- /dev/null +++ b/src/templates/addrman_observer_config.toml @@ -0,0 +1,8 @@ +# addrman-observer base configuration file + +# path to the location of the static www files +www_path = "./www" + +# webserver listen address +address = "0.0.0.0:3882" + diff --git a/src/warnet/services.py b/src/warnet/services.py index 95009a6f9..24327e812 100644 --- a/src/warnet/services.py +++ b/src/warnet/services.py @@ -1,4 +1,5 @@ FO_CONF_NAME = "fork_observer_config.toml" +AO_CONF_NAME = "addrman_observer_config.toml" GRAFANA_PROVISIONING = "grafana-provisioning" PROM_CONF_NAME = "prometheus.yml" @@ -33,6 +34,14 @@ "container_port": "2323", "config_files": [f"{FO_CONF_NAME}:/app/config.toml"], }, + "addrmanobserver": { + "backends": ["compose"], + "image": "b10c/addrman-observer:latest", + "container_name_suffix": "addrman-observer", + "warnet_port": "23005", + "container_port": "3882", + "config_files": [f"{AO_CONF_NAME}:/app/config.toml"], + }, "grafana": { "backends": ["compose"], "image": "grafana/grafana:latest", diff --git a/src/warnet/warnet.py b/src/warnet/warnet.py index e2cce88fd..a1ea78386 100644 --- a/src/warnet/warnet.py +++ b/src/warnet/warnet.py @@ -12,7 +12,7 @@ import yaml from backends import ComposeBackend, KubernetesBackend from templates import TEMPLATES -from warnet.services import FO_CONF_NAME, GRAFANA_PROVISIONING, PROM_CONF_NAME +from warnet.services import AO_CONF_NAME, FO_CONF_NAME, GRAFANA_PROVISIONING, PROM_CONF_NAME from warnet.tank import Tank from warnet.utils import gen_config_dir, load_schema, validate_graph_schema @@ -181,8 +181,10 @@ def generate_deployment(self): self.container_interface.generate_deployment_file(self) if "forkobserver" in self.services: self.write_fork_observer_config() + if "addrmanobserver" in self.services: + self.write_addrman_observer_config() if "grafana" in self.services: - self.write_grafna_config() + self.write_grafana_config() if "prometheus" in self.services: self.write_prometheus_config() @@ -205,8 +207,27 @@ def write_fork_observer_config(self): """ ) logger.info(f"Wrote file: {dst}") + + def write_addrman_observer_config(self): + src = TEMPLATES / AO_CONF_NAME + dst = self.config_dir / AO_CONF_NAME + shutil.copy(src, dst) + with open(dst, "a") as f: + for tank in self.tanks: + f.write( + f""" + [[nodes]] + id = {tank.index} + name = "node-{tank.index}" + rpc_host = "{tank.ipv4}" + rpc_port = {tank.rpc_port} + rpc_user = "{tank.rpc_user}" + rpc_password = "{tank.rpc_password}" + """ + ) + logger.info(f"Wrote file: {dst}") - def write_grafna_config(self): + def write_grafana_config(self): src = TEMPLATES / GRAFANA_PROVISIONING dst = self.config_dir / GRAFANA_PROVISIONING shutil.copytree(src, dst, dirs_exist_ok=True) diff --git a/test/data/services.graphml b/test/data/services.graphml index 41d53bd80..b92125bbc 100644 --- a/test/data/services.graphml +++ b/test/data/services.graphml @@ -15,7 +15,7 @@ - cadvisor forkobserver grafana nodeexporter prometheus + cadvisor forkobserver addrmanobserver grafana nodeexporter prometheus 26.0 -uacomment=w0 -debug=validation @@ -23,4 +23,4 @@ lnd - \ No newline at end of file + diff --git a/test/graph_test.py b/test/graph_test.py index 1aee675d9..3b9eb562a 100755 --- a/test/graph_test.py +++ b/test/graph_test.py @@ -70,6 +70,15 @@ else: raise Exception("forkobserver not OK") + node_id = 0 + ao_res = requests.get(f"http://localhost:23005/{node_id}") + assert ao_res.status_code == 200 + addrman = ao_res.json() + if "new" in addrman and "tried" in addrman: + print("forkobserver OK") + else: + raise Exception("addrmanobserver not OK") + grafana_res = requests.get("http://localhost:23002/api/datasources/uid/prometheusdatasource/health") assert grafana_res.status_code == 200 health = grafana_res.json() From 63336db9032feb8e015390c4d1ce45bddffe38d8 Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Tue, 4 Jun 2024 13:40:41 -0400 Subject: [PATCH 2/2] nit --- test/graph_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/graph_test.py b/test/graph_test.py index 3b9eb562a..84e0a8286 100755 --- a/test/graph_test.py +++ b/test/graph_test.py @@ -75,7 +75,7 @@ assert ao_res.status_code == 200 addrman = ao_res.json() if "new" in addrman and "tried" in addrman: - print("forkobserver OK") + print("addrmanobserver OK") else: raise Exception("addrmanobserver not OK")