Skip to content

Commit

Permalink
fix(metrics): fix missing metrics by installing prometheus before cre…
Browse files Browse the repository at this point in the history
…ating db env (#6659)
  • Loading branch information
sevazhidkov authored Feb 18, 2024
1 parent 6d8b5d5 commit 79f1fa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/reth/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions crates/storage/db/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 79f1fa3

Please sign in to comment.