fix(metrics): fix missing metrics by installing prometheus before creating db env (#6659)

This commit is contained in:
Seva Zhidkov
2024-02-18 21:14:37 +00:00
committed by GitHub
parent 6d8b5d58c5
commit 79f1fa3c10
2 changed files with 8 additions and 1 deletions

View File

@ -77,8 +77,13 @@ pub async fn launch_from_config<E: RethCliExt>(
) -> eyre::Result<NodeHandle> {
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
// Register the prometheus recorder before creating the database,
// because database init needs it to register metrics.
config.install_prometheus_recorder()?;
let database = std::mem::take(&mut config.database);
let db_instance = database.init_db(config.db.log_level, config.chain.chain)?;
info!(target: "reth::cli", "Database opened");
match db_instance {
DatabaseInstance::Real { db, data_dir } => {
@ -121,7 +126,6 @@ impl<DB: Database + DatabaseMetrics + DatabaseMetadata + 'static> NodeBuilderWit
let config = self.load_config()?;
let prometheus_handle = self.config.install_prometheus_recorder()?;
info!(target: "reth::cli", "Database opened");
let mut provider_factory =
ProviderFactory::new(Arc::clone(&self.db), Arc::clone(&self.config.chain));

View File

@ -14,6 +14,9 @@ const LARGE_VALUE_THRESHOLD_BYTES: usize = 4096;
/// Caches metric handles for database environment to make sure handles are not re-created
/// on every operation.
///
/// Requires a metric recorder to be registered before creating an instance of this struct.
/// Otherwise, metric recording will no-op.
#[derive(Debug)]
pub struct DatabaseEnvMetrics {
/// Caches OperationMetrics handles for each table and operation tuple.