Replace lazy_static! with LazyLock (#6189)

* Replace `lazy_static` with `LazyLock`.

* Merge branch 'unstable' into remove-lazy-static

# Conflicts:
#	beacon_node/lighthouse_network/src/peer_manager/mod.rs

* Lint fixes.

* Merge branch 'unstable' into remove-lazy-static

# Conflicts:
#	beacon_node/beacon_chain/src/metrics.rs

* Moar lint fixes.

* Update rust version to 1.80.0.

* Merge branch 'unstable' into remove-lazy-static
This commit is contained in:
Jimmy Chen
2024-07-29 21:42:31 +10:00
committed by GitHub
parent 00038dae81
commit 96b00ef66c
85 changed files with 3512 additions and 2370 deletions

View File

@@ -19,7 +19,6 @@ types = { workspace = true }
state_processing = { workspace = true }
slog = { workspace = true }
serde = { workspace = true }
lazy_static = { workspace = true }
lighthouse_metrics = { workspace = true }
lru = { workspace = true }
sloggers = { workspace = true }

View File

@@ -1,110 +1,156 @@
pub use lighthouse_metrics::{set_gauge, try_create_int_gauge, *};
use directory::size_of_dir;
use lazy_static::lazy_static;
use std::path::Path;
use std::sync::LazyLock;
lazy_static! {
/*
* General
*/
pub static ref DISK_DB_SIZE: Result<IntGauge> =
try_create_int_gauge("store_disk_db_size", "Size of the hot on-disk database (bytes)");
pub static ref FREEZER_DB_SIZE: Result<IntGauge> =
try_create_int_gauge("store_freezer_db_size", "Size of the on-disk freezer database (bytes)");
pub static ref DISK_DB_WRITE_BYTES: Result<IntCounterVec> = try_create_int_counter_vec(
/*
* General
*/
pub static DISK_DB_SIZE: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
try_create_int_gauge(
"store_disk_db_size",
"Size of the hot on-disk database (bytes)",
)
});
pub static FREEZER_DB_SIZE: LazyLock<Result<IntGauge>> = LazyLock::new(|| {
try_create_int_gauge(
"store_freezer_db_size",
"Size of the on-disk freezer database (bytes)",
)
});
pub static DISK_DB_WRITE_BYTES: LazyLock<Result<IntCounterVec>> = LazyLock::new(|| {
try_create_int_counter_vec(
"store_disk_db_write_bytes_total",
"Number of bytes attempted to be written to the hot on-disk DB",
&["col"],
);
pub static ref DISK_DB_READ_BYTES: Result<IntCounterVec> = try_create_int_counter_vec(
)
});
pub static DISK_DB_READ_BYTES: LazyLock<Result<IntCounterVec>> = LazyLock::new(|| {
try_create_int_counter_vec(
"store_disk_db_read_bytes_total",
"Number of bytes read from the hot on-disk DB",
&["col"],
);
pub static ref DISK_DB_READ_COUNT: Result<IntCounterVec> = try_create_int_counter_vec(
)
});
pub static DISK_DB_READ_COUNT: LazyLock<Result<IntCounterVec>> = LazyLock::new(|| {
try_create_int_counter_vec(
"store_disk_db_read_count_total",
"Total number of reads to the hot on-disk DB",
&["col"],
);
pub static ref DISK_DB_WRITE_COUNT: Result<IntCounterVec> = try_create_int_counter_vec(
)
});
pub static DISK_DB_WRITE_COUNT: LazyLock<Result<IntCounterVec>> = LazyLock::new(|| {
try_create_int_counter_vec(
"store_disk_db_write_count_total",
"Total number of writes to the hot on-disk DB",
&["col"],
);
pub static ref DISK_DB_READ_TIMES: Result<Histogram> = try_create_histogram(
)
});
pub static DISK_DB_READ_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram(
"store_disk_db_read_seconds",
"Time taken to write bytes to store."
);
pub static ref DISK_DB_WRITE_TIMES: Result<Histogram> = try_create_histogram(
"Time taken to write bytes to store.",
)
});
pub static DISK_DB_WRITE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram(
"store_disk_db_write_seconds",
"Time taken to write bytes to store."
);
pub static ref DISK_DB_EXISTS_COUNT: Result<IntCounterVec> = try_create_int_counter_vec(
"Time taken to write bytes to store.",
)
});
pub static DISK_DB_EXISTS_COUNT: LazyLock<Result<IntCounterVec>> = LazyLock::new(|| {
try_create_int_counter_vec(
"store_disk_db_exists_count_total",
"Total number of checks if a key is in the hot on-disk DB",
&["col"],
);
pub static ref DISK_DB_DELETE_COUNT: Result<IntCounterVec> = try_create_int_counter_vec(
)
});
pub static DISK_DB_DELETE_COUNT: LazyLock<Result<IntCounterVec>> = LazyLock::new(|| {
try_create_int_counter_vec(
"store_disk_db_delete_count_total",
"Total number of deletions from the hot on-disk DB",
&["col"],
);
/*
* Beacon State
*/
pub static ref BEACON_STATE_GET_COUNT: Result<IntCounter> = try_create_int_counter(
)
});
/*
* Beacon State
*/
pub static BEACON_STATE_GET_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_state_get_total",
"Total number of beacon states requested from the store (cache or DB)"
);
pub static ref BEACON_STATE_HOT_GET_COUNT: Result<IntCounter> = try_create_int_counter(
"Total number of beacon states requested from the store (cache or DB)",
)
});
pub static BEACON_STATE_HOT_GET_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_state_hot_get_total",
"Total number of hot beacon states requested from the store (cache or DB)"
);
pub static ref BEACON_STATE_READ_TIMES: Result<Histogram> = try_create_histogram(
"Total number of hot beacon states requested from the store (cache or DB)",
)
});
pub static BEACON_STATE_READ_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram(
"store_beacon_state_read_seconds",
"Total time required to read a BeaconState from the database"
);
pub static ref BEACON_STATE_READ_OVERHEAD_TIMES: Result<Histogram> = try_create_histogram(
"Total time required to read a BeaconState from the database",
)
});
pub static BEACON_STATE_READ_OVERHEAD_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram(
"store_beacon_state_read_overhead_seconds",
"Overhead on reading a beacon state from the DB (e.g., decoding)"
);
pub static ref BEACON_STATE_READ_COUNT: Result<IntCounter> = try_create_int_counter(
"Overhead on reading a beacon state from the DB (e.g., decoding)",
)
});
pub static BEACON_STATE_READ_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_state_read_total",
"Total number of beacon state reads from the DB"
);
pub static ref BEACON_STATE_READ_BYTES: Result<IntCounter> = try_create_int_counter(
"Total number of beacon state reads from the DB",
)
});
pub static BEACON_STATE_READ_BYTES: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_state_read_bytes_total",
"Total number of beacon state bytes read from the DB"
);
pub static ref BEACON_STATE_WRITE_OVERHEAD_TIMES: Result<Histogram> = try_create_histogram(
"Total number of beacon state bytes read from the DB",
)
});
pub static BEACON_STATE_WRITE_OVERHEAD_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
try_create_histogram(
"store_beacon_state_write_overhead_seconds",
"Overhead on writing a beacon state to the DB (e.g., encoding)"
);
pub static ref BEACON_STATE_WRITE_COUNT: Result<IntCounter> = try_create_int_counter(
"Overhead on writing a beacon state to the DB (e.g., encoding)",
)
});
pub static BEACON_STATE_WRITE_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_state_write_total",
"Total number of beacon state writes the DB"
);
pub static ref BEACON_STATE_WRITE_BYTES: Result<IntCounter> = try_create_int_counter(
"Total number of beacon state writes the DB",
)
});
pub static BEACON_STATE_WRITE_BYTES: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_state_write_bytes_total",
"Total number of beacon state bytes written to the DB"
);
/*
* Beacon Block
*/
pub static ref BEACON_BLOCK_GET_COUNT: Result<IntCounter> = try_create_int_counter(
"Total number of beacon state bytes written to the DB",
)
});
/*
* Beacon Block
*/
pub static BEACON_BLOCK_GET_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_block_get_total",
"Total number of beacon blocks requested from the store (cache or DB)"
);
pub static ref BEACON_BLOCK_CACHE_HIT_COUNT: Result<IntCounter> = try_create_int_counter(
"Total number of beacon blocks requested from the store (cache or DB)",
)
});
pub static BEACON_BLOCK_CACHE_HIT_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_block_cache_hit_total",
"Number of hits to the store's block cache"
);
pub static ref BEACON_BLOBS_CACHE_HIT_COUNT: Result<IntCounter> = try_create_int_counter(
"Number of hits to the store's block cache",
)
});
pub static BEACON_BLOBS_CACHE_HIT_COUNT: LazyLock<Result<IntCounter>> = LazyLock::new(|| {
try_create_int_counter(
"store_beacon_blobs_cache_hit_total",
"Number of hits to the store's blob cache"
);
}
"Number of hits to the store's blob cache",
)
});
/// Updates the global metrics registry with store-related information.
pub fn scrape_for_metrics(db_path: &Path, freezer_db_path: &Path) {