mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 13:54:44 +00:00
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:
@@ -1,4 +1,3 @@
|
||||
use lazy_static::lazy_static;
|
||||
use lighthouse_metrics::{
|
||||
inc_counter, try_create_int_counter, IntCounter, Result as MetricsResult,
|
||||
};
|
||||
@@ -6,6 +5,7 @@ use slog::Logger;
|
||||
use slog_term::Decorator;
|
||||
use std::io::{Result, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::LazyLock;
|
||||
use std::time::{Duration, Instant};
|
||||
use tracing_appender::non_blocking::NonBlocking;
|
||||
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
||||
@@ -25,16 +25,14 @@ pub use tracing_metrics_layer::MetricsLayer;
|
||||
/// The minimum interval between log messages indicating that a queue is full.
|
||||
const LOG_DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30);
|
||||
|
||||
lazy_static! {
|
||||
pub static ref INFOS_TOTAL: MetricsResult<IntCounter> =
|
||||
try_create_int_counter("info_total", "Count of infos logged");
|
||||
pub static ref WARNS_TOTAL: MetricsResult<IntCounter> =
|
||||
try_create_int_counter("warn_total", "Count of warns logged");
|
||||
pub static ref ERRORS_TOTAL: MetricsResult<IntCounter> =
|
||||
try_create_int_counter("error_total", "Count of errors logged");
|
||||
pub static ref CRITS_TOTAL: MetricsResult<IntCounter> =
|
||||
try_create_int_counter("crit_total", "Count of crits logged");
|
||||
}
|
||||
pub static INFOS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
||||
LazyLock::new(|| try_create_int_counter("info_total", "Count of infos logged"));
|
||||
pub static WARNS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
||||
LazyLock::new(|| try_create_int_counter("warn_total", "Count of warns logged"));
|
||||
pub static ERRORS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
||||
LazyLock::new(|| try_create_int_counter("error_total", "Count of errors logged"));
|
||||
pub static CRITS_TOTAL: LazyLock<MetricsResult<IntCounter>> =
|
||||
LazyLock::new(|| try_create_int_counter("crit_total", "Count of crits logged"));
|
||||
|
||||
pub struct AlignedTermDecorator<D: Decorator> {
|
||||
wrapped: D,
|
||||
|
||||
@@ -1,32 +1,36 @@
|
||||
//! Exposes [`MetricsLayer`]: A tracing layer that registers metrics of logging events.
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use lighthouse_metrics as metrics;
|
||||
use std::sync::LazyLock;
|
||||
use tracing_log::NormalizeEvent;
|
||||
|
||||
lazy_static! {
|
||||
/// Count of `INFO` logs registered per enabled dependency.
|
||||
pub static ref DEP_INFOS_TOTAL: metrics::Result<metrics::IntCounterVec> =
|
||||
/// Count of `INFO` logs registered per enabled dependency.
|
||||
pub static DEP_INFOS_TOTAL: LazyLock<metrics::Result<metrics::IntCounterVec>> =
|
||||
LazyLock::new(|| {
|
||||
metrics::try_create_int_counter_vec(
|
||||
"dep_info_total",
|
||||
"Count of infos logged per enabled dependency",
|
||||
&["target"]
|
||||
);
|
||||
/// Count of `WARN` logs registered per enabled dependency.
|
||||
pub static ref DEP_WARNS_TOTAL: metrics::Result<metrics::IntCounterVec> =
|
||||
&["target"],
|
||||
)
|
||||
});
|
||||
/// Count of `WARN` logs registered per enabled dependency.
|
||||
pub static DEP_WARNS_TOTAL: LazyLock<metrics::Result<metrics::IntCounterVec>> =
|
||||
LazyLock::new(|| {
|
||||
metrics::try_create_int_counter_vec(
|
||||
"dep_warn_total",
|
||||
"Count of warns logged per enabled dependency",
|
||||
&["target"]
|
||||
);
|
||||
/// Count of `ERROR` logs registered per enabled dependency.
|
||||
pub static ref DEP_ERRORS_TOTAL: metrics::Result<metrics::IntCounterVec> =
|
||||
&["target"],
|
||||
)
|
||||
});
|
||||
/// Count of `ERROR` logs registered per enabled dependency.
|
||||
pub static DEP_ERRORS_TOTAL: LazyLock<metrics::Result<metrics::IntCounterVec>> =
|
||||
LazyLock::new(|| {
|
||||
metrics::try_create_int_counter_vec(
|
||||
"dep_error_total",
|
||||
"Count of errors logged per enabled dependency",
|
||||
&["target"]
|
||||
);
|
||||
}
|
||||
&["target"],
|
||||
)
|
||||
});
|
||||
|
||||
/// Layer that registers Prometheus metrics for `INFO`, `WARN` and `ERROR` logs emitted per dependency.
|
||||
/// Dependencies are enabled via the `RUST_LOG` env flag.
|
||||
|
||||
Reference in New Issue
Block a user