Skip to content
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
12 changes: 12 additions & 0 deletions deploy/erigon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
# First Erigon release that defines ``--caplin.discovery.quicport`` (v3.7.1).
_CAPLIN_QUIC_MIN = (3, 7, 1)

# Erigon v3.8.1 and current main default ``--metrics.port`` to 6061
# (``diagnostics/metrics.DefaultConfig.Port``, registered as ``utils.MetricsPortFlag``).
# ``--pprof`` stays on 127.0.0.1:6060. ``/debug/metrics/prometheus`` is registered
# only on the metrics mux, and pprof handlers join that mux only when the two
# listen addresses are identical. Pin metrics to the pprof address so
# ``manage/client_monitoring.py`` (port 6060, path ``/debug/metrics/prometheus``)
# scrapes a live endpoint. Leave ``--metrics.addr`` and ``--pprof.*`` unset so
# both stay on the 127.0.0.1:6060 defaults.
_METRICS_PORT_ARG = "--metrics.port=6060"


def caplin_quic_flag_supported(version: str) -> bool:
"""Return True when the unit should pin ``--caplin.discovery.quicport``.
Expand Down Expand Up @@ -88,6 +98,7 @@ def generate_erigon_service(eth_network: str, el_p2p_port: str, el_rpc_port: str
f"--maxpeers={el_max_peer_count}",
"--http.api=web3,eth,net,engine",
"--metrics",
_METRICS_PORT_ARG,
"--pprof",
"--prune.mode=minimal",
"--private.api.addr=127.0.0.1:9091",
Expand Down Expand Up @@ -165,6 +176,7 @@ def generate_erigon_standalone_service(eth_network: str, el_p2p_port: str, el_rp
f"--maxpeers={el_max_peer_count}",
"--http.api=web3,eth,net,engine",
"--metrics",
_METRICS_PORT_ARG,
"--pprof",
"--prune.mode=minimal",
"--private.api.addr=127.0.0.1:9091",
Expand Down
44 changes: 44 additions & 0 deletions tests/test_service_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
generate_erigon_service,
generate_erigon_standalone_service,
)
from manage.client_monitoring import detect_clients, metrics_port_from_unit, scrape_job_yaml
from deploy.teku import generate_teku_bn_service, generate_teku_vc_service
from deploy.lodestar import generate_lodestar_bn_service, generate_lodestar_vc_service
from deploy.nimbus import generate_nimbus_bn_service, generate_nimbus_vc_service
Expand Down Expand Up @@ -458,6 +459,35 @@ def test_ephemery_custom_network(self):
# Erigon service tests
# ═══════════════════════════════════════════════

def assert_erigon_metrics_port_matches_scrape(unit: str) -> None:
"""Fail unless the unit sets the metrics port ``client_monitoring`` scrapes.

``metrics_port_from_unit`` falls back to the catalog default when the flag
is absent. That fallback is the bug: Erigon then listens on 6061 while the
scrape target stays 6060. A default of 0 makes a missing flag fail here.
``--pprof`` is left on its 127.0.0.1:6060 default so both listeners share
one server and ``/debug/metrics/prometheus`` is actually served there.
"""
explicit_port = metrics_port_from_unit(unit, 0)
found = detect_clients(unit, None, None)
assert len(found) == 1
client, scraped_port = found[0]
assert client.key == "erigon"
assert client.metrics_path == "/debug/metrics/prometheus"
assert explicit_port == client.default_port
assert scraped_port == explicit_port
job = scrape_job_yaml(client, scraped_port)
assert f"localhost:{explicit_port}" in job
assert f"metrics_path: {client.metrics_path}" in job
assert "--metrics.port=6060" in unit
assert "--metrics \\" in unit
assert "--pprof \\" in unit
assert "--pprof.port" not in unit
assert "--pprof.addr" not in unit
assert "--metrics.addr" not in unit
assert "--http.api=web3,eth,net,engine" in unit


class TestErigonService:
"""Test Erigon+Caplin integrated service file generation."""

Expand Down Expand Up @@ -518,6 +548,14 @@ def test_no_mev(self):
assert "--caplin.mev-relay-url" not in result
assert "Requires=mevboost.service" not in result

def test_metrics_port_matches_monitoring_scrape(self):
result = generate_erigon_service(
"mainnet", EL_P2P_PORT, EL_RPC_PORT, EL_MAX_PEER_COUNT,
JWTSECRET_PATH, CL_P2P_PORT, CL_REST_PORT, CL_MAX_PEER_COUNT,
SYNC_URL
)
assert_erigon_metrics_port_matches_scrape(result)


# ═══════════════════════════════════════════════
# Erigon Standalone (no Caplin) service tests
Expand Down Expand Up @@ -600,6 +638,12 @@ def test_different_from_integrated(self):
assert "Erigon Execution Layer Client" in standalone
assert "Erigon-Caplin Integrated" in integrated

def test_metrics_port_matches_monitoring_scrape(self):
result = generate_erigon_standalone_service(
"mainnet", EL_P2P_PORT, EL_RPC_PORT, EL_MAX_PEER_COUNT, JWTSECRET_PATH
)
assert_erigon_metrics_port_matches_scrape(result)


# ═══════════════════════════════════════════════
# Teku service tests
Expand Down
Loading