Skip to content

add: addrman-observer support #338

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/templates/addrman_observer_config.toml
Original file line number Diff line number Diff line change
@@ -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"

9 changes: 9 additions & 0 deletions src/warnet/services.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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",
Expand Down
27 changes: 24 additions & 3 deletions src/warnet/warnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! ;-)

if "prometheus" in self.services:
self.write_prometheus_config()

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/data/services.graphml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<key id="source_policy" attr.name="source_policy" attr.type="string" for="edge" />
<key id="target_policy" attr.name="target_policy" attr.type="string" for="edge" />
<graph edgedefault="directed">
<data key="services">cadvisor forkobserver grafana nodeexporter prometheus</data>
<data key="services">cadvisor forkobserver addrmanobserver grafana nodeexporter prometheus</data>
<node id="0">
<data key="version">26.0</data>
<data key="bitcoin_config">-uacomment=w0 -debug=validation</data>
<data key="exporter">true</data>
<data key="ln">lnd</data>
</node>
</graph>
</graphml>
</graphml>
9 changes: 9 additions & 0 deletions test/graph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("addrmanobserver 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()
Expand Down