From 7eec922b79cb31e4f5b0ed2fbf286803ddd17879 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 25 Oct 2026 11:17:53 +0000 Subject: [PATCH] Pin Erigon metrics to port 6060 so Prometheus can scrape them. Erigon v3.8.1 and current main default --metrics.port to 6061 while pprof stays on 127.0.0.1:6060. The prometheus handler is served on 6060 only when those listen addresses match. EthPillar scrapes /debug/metrics/prometheus on 6060. Co-authored-by: b0a7 --- deploy/erigon.py | 12 +++++++++ tests/test_service_generators.py | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/deploy/erigon.py b/deploy/erigon.py index 5f82e0d4..db871895 100644 --- a/deploy/erigon.py +++ b/deploy/erigon.py @@ -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``. @@ -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", @@ -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", diff --git a/tests/test_service_generators.py b/tests/test_service_generators.py index 3382d80b..71dc7953 100644 --- a/tests/test_service_generators.py +++ b/tests/test_service_generators.py @@ -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 @@ -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.""" @@ -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 @@ -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