feat: add stagedsync headers metrics (#498)

* add dockerfile for reth

* Add docker compose for prometheus

* Add some metrics

* Add p2p connection errors metric

* Add dependency caching for dockerfile

This reduces image build times by ~50% after the first one.

Uses cargo-chef inside the image.
More info in: https://morioh.com/p/987a2bda4526

* Add --metrics flag to docker-compose config file

* add Cargo.lock

* Move docker-compose.yml to docker directory

* Apply formatting

* Remove docker folder

* Remove .dockerignore file

* Add 'reth' prefix to metric names

* Add headers errors and request time metrics

* Modularize metrics exporter functionality and describe metrics

* Format files

* Add metrics documentation in metrics.md

* Fix metrics doc title

* Commit changes after rebase

* Solve conflict

* Modularize metrics describers

* Add stages_metrics_describer

* Rearrange header error metrics

* Add update_headers_metrics function

* Add one-line docs to describers

* Remove commented line

* Refactor metrics describer

* Update metrics doc

* Fix import

* Add header metrics struct

* add new metrics format in the headers execute method

* Add default implementation for HeaderMetrics

* Fix typo

* Fix another typo

* Fix more typos

* Move new HeaderMetrics meathod to default

* Solve conflicts

* Fix test

Co-authored-by: Tomás <tomas.gruner@lambdaclass.com>
This commit is contained in:
Mariano A. Nicolini
2022-12-22 11:45:57 -03:00
committed by GitHub
parent 7ce22fd186
commit b12939db47
10 changed files with 161 additions and 46 deletions

View File

@ -36,6 +36,7 @@ dirs-next = "2.0.0"
confy = "0.5"
# rpc/metrics
metrics = "0.20.1"
metrics-exporter-prometheus = { version = "0.11.0", features = ["http-listener"] }
metrics-util = "0.14.0"

View File

@ -11,5 +11,6 @@ pub mod config;
pub mod db;
pub mod dirs;
pub mod node;
pub mod prometheus_exporter;
pub mod test_eth_chain;
pub mod util;

View File

@ -4,12 +4,10 @@
use crate::{
config::Config,
dirs::{ConfigPath, DbPath},
prometheus_exporter,
util::chainspec::{chain_spec_value_parser, ChainSpecification, Genesis},
};
use clap::{crate_version, Parser};
use eyre::WrapErr;
use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::layers::{PrefixLayer, Stack};
use reth_consensus::BeaconConsensus;
use reth_db::{
cursor::DbCursorRO,
@ -27,8 +25,10 @@ use reth_network::{
};
use reth_primitives::{Account, Header, H256};
use reth_provider::{db_provider::ProviderImpl, BlockProvider, HeaderProvider};
use reth_stages::stages::{
bodies::BodyStage, headers::HeaderStage, sender_recovery::SenderRecoveryStage,
use reth_stages::{
stages::{bodies::BodyStage, headers::HeaderStage, sender_recovery::SenderRecoveryStage},
stages_metrics::HeaderMetrics,
stages_metrics_describer,
};
use std::{net::SocketAddr, path::Path, sync::Arc};
use tracing::{debug, info};
@ -93,15 +93,8 @@ impl Command {
if let Some(listen_addr) = self.metrics {
info!("Starting metrics endpoint at {}", listen_addr);
let (recorder, exporter) = PrometheusBuilder::new()
.with_http_listener(listen_addr)
.build()
.wrap_err("Could not build Prometheus endpoint.")?;
tokio::task::spawn(exporter);
Stack::new(recorder)
.push(PrefixLayer::new("reth"))
.install()
.wrap_err("Couldn't set metrics recorder.")?;
prometheus_exporter::initialize(listen_addr)?;
stages_metrics_describer::describe();
}
let chain_id = self.chain.consensus.chain_id;
@ -125,6 +118,7 @@ impl Command {
client: fetch_client.clone(),
network_handle: network.clone(),
commit_threshold: config.stages.headers.commit_threshold,
metrics: HeaderMetrics::default(),
})
.push(BodyStage {
downloader: Arc::new(

View File

@ -0,0 +1,20 @@
//! Prometheus exporter
use eyre::WrapErr;
use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_util::layers::{PrefixLayer, Stack};
use std::net::SocketAddr;
pub(crate) fn initialize(listen_addr: SocketAddr) -> eyre::Result<()> {
let (recorder, exporter) = PrometheusBuilder::new()
.with_http_listener(listen_addr)
.build()
.wrap_err("Could not build Prometheus endpoint.")?;
tokio::task::spawn(exporter);
Stack::new(recorder)
.push(PrefixLayer::new("reth"))
.install()
.wrap_err("Couldn't set metrics recorder.")?;
Ok(())
}