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

@@ -17,6 +17,5 @@ lighthouse_version = { workspace = true }
lighthouse_metrics = { workspace = true }
slog = { workspace = true }
store = { workspace = true }
lazy_static = { workspace = true }
regex = { workspace = true }
sensitive_url = { workspace = true }

View File

@@ -1,9 +1,9 @@
use super::types::{BeaconProcessMetrics, ValidatorProcessMetrics};
use lazy_static::lazy_static;
use lighthouse_metrics::{MetricFamily, MetricType};
use serde_json::json;
use std::collections::HashMap;
use std::path::Path;
use std::sync::LazyLock;
/// Represents a metric that needs to be fetched from lighthouse metrics registry
/// and sent to the remote monitoring service.
@@ -126,19 +126,20 @@ pub enum JsonType {
Boolean,
}
lazy_static! {
/// HashMap representing the `BEACON_PROCESS_METRICS`.
pub static ref BEACON_METRICS_MAP: HashMap<String, JsonMetric> = BEACON_PROCESS_METRICS
/// HashMap representing the `BEACON_PROCESS_METRICS`.
pub static BEACON_METRICS_MAP: LazyLock<HashMap<String, JsonMetric>> = LazyLock::new(|| {
BEACON_PROCESS_METRICS
.iter()
.map(|metric| (metric.lighthouse_metric_name.to_string(), metric.clone()))
.collect();
/// HashMap representing the `VALIDATOR_PROCESS_METRICS`.
pub static ref VALIDATOR_METRICS_MAP: HashMap<String,JsonMetric> =
VALIDATOR_PROCESS_METRICS
.collect()
});
/// HashMap representing the `VALIDATOR_PROCESS_METRICS`.
pub static VALIDATOR_METRICS_MAP: LazyLock<HashMap<String, JsonMetric>> = LazyLock::new(|| {
VALIDATOR_PROCESS_METRICS
.iter()
.map(|metric| (metric.lighthouse_metric_name.to_string(), metric.clone()))
.collect();
}
.collect()
});
/// Returns the value from a Counter/Gauge `MetricType` assuming that it has no associated labels
/// else it returns `None`.