diff --git a/Cargo.lock b/Cargo.lock index fa1842b..90ba0f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3144,7 +3144,6 @@ dependencies = [ "futures", "hdrs", "hyper", - "lazy_static", "log", "once_cell", "poem", diff --git a/Cargo.toml b/Cargo.toml index fab17a5..14db9e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,6 @@ serde = { version = "1", features = ["derive"] } async-channel = "1.8.0" croaring = "0.8.1" prometheus = { version = "0.13", features = ["process", "push"] } -lazy_static = "1.4" crc32fast = "1.3.2" fs2 = "0.4.3" url = "2.4.0" diff --git a/src/http/mod.rs b/src/http/mod.rs index 66d02eb..b9a3188 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -26,12 +26,10 @@ use crate::http::http_service::PoemHTTPServer; use crate::http::jeprof::JeProfHandler; use crate::http::metrics::MetricsHTTPHandler; use crate::http::pprof::PProfHandler; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use poem::RouteMethod; -lazy_static! { - pub static ref HTTP_SERVICE: Box = new_server(); -} +pub static HTTP_SERVICE: Lazy> = Lazy::new(|| new_server()); /// Implement the own handlers for concrete components pub trait Handler { diff --git a/src/metric.rs b/src/metric.rs index 49debbd..8a7d811 100644 --- a/src/metric.rs +++ b/src/metric.rs @@ -16,7 +16,6 @@ // under the License. use crate::config::MetricsConfig; -use lazy_static::lazy_static; use log::{error, info}; use once_cell::sync::Lazy; use prometheus::{labels, Histogram, HistogramOpts, IntCounter, IntGauge, Registry}; @@ -87,60 +86,76 @@ pub static GRPC_BUFFER_REQUIRE_PROCESS_TIME: Lazy = Lazy::new(|| { histogram }); -lazy_static! { - pub static ref TOTAL_MEMORY_USED: IntCounter = - IntCounter::new("total_memory_used", "Total memory used") - .expect("metric should be created"); - pub static ref TOTAL_LOCALFILE_USED: IntCounter = - IntCounter::new("total_localfile_used", "Total localfile used") - .expect("metric should be created"); - pub static ref TOTAL_HDFS_USED: IntCounter = - IntCounter::new("total_hdfs_used", "Total hdfs used").expect("metric should be created"); - pub static ref GAUGE_MEMORY_USED: IntGauge = - IntGauge::new("memory_used", "memory used").expect("metric should be created"); - pub static ref GAUGE_MEMORY_ALLOCATED: IntGauge = - IntGauge::new("memory_allocated", "memory allocated").expect("metric should be created"); - pub static ref GAUGE_MEMORY_CAPACITY: IntGauge = - IntGauge::new("memory_capacity", "memory capacity").expect("metric should be created"); - pub static ref TOTAL_MEMORY_SPILL_OPERATION: IntCounter = - IntCounter::new("total_memory_spill", "memory capacity").expect("metric should be created"); - pub static ref TOTAL_MEMORY_SPILL_OPERATION_FAILED: IntCounter = - IntCounter::new("total_memory_spill_failed", "memory capacity") - .expect("metric should be created"); - pub static ref TOTAL_MEMORY_SPILL_TO_LOCALFILE: IntCounter = IntCounter::new( +pub static TOTAL_MEMORY_USED: Lazy = Lazy::new(|| { + IntCounter::new("total_memory_used", "Total memory used").expect("metric should be created") +}); + +pub static TOTAL_LOCALFILE_USED: Lazy = Lazy::new(|| { + IntCounter::new("total_localfile_used", "Total localfile used") + .expect("metric should be created") +}); + +pub static TOTAL_HDFS_USED: Lazy = Lazy::new(|| { + IntCounter::new("total_hdfs_used", "Total hdfs used").expect("metric should be created") +}); +pub static GAUGE_MEMORY_USED: Lazy = + Lazy::new(|| IntGauge::new("memory_used", "memory used").expect("metric should be created")); +pub static GAUGE_MEMORY_ALLOCATED: Lazy = Lazy::new(|| { + IntGauge::new("memory_allocated", "memory allocated").expect("metric should be created") +}); +pub static GAUGE_MEMORY_CAPACITY: Lazy = Lazy::new(|| { + IntGauge::new("memory_capacity", "memory capacity").expect("metric should be created") +}); +pub static TOTAL_MEMORY_SPILL_OPERATION: Lazy = Lazy::new(|| { + IntCounter::new("total_memory_spill", "memory capacity").expect("metric should be created") +}); +pub static TOTAL_MEMORY_SPILL_OPERATION_FAILED: Lazy = Lazy::new(|| { + IntCounter::new("total_memory_spill_failed", "memory capacity") + .expect("metric should be created") +}); +pub static TOTAL_MEMORY_SPILL_TO_LOCALFILE: Lazy = Lazy::new(|| { + IntCounter::new( "total_memory_spill_to_localfile", - "memory spill to localfile" + "memory spill to localfile", ) - .expect("metric should be created"); - pub static ref TOTAL_MEMORY_SPILL_TO_HDFS: IntCounter = - IntCounter::new("total_memory_spill_to_hdfs", "memory spill to hdfs") - .expect("metric should be created"); - pub static ref GAUGE_MEMORY_SPILL_OPERATION: IntGauge = - IntGauge::new("memory_spill", "memory spill").expect("metric should be created"); - pub static ref GAUGE_MEMORY_SPILL_TO_LOCALFILE: IntGauge = - IntGauge::new("memory_spill_to_localfile", "memory spill to localfile") - .expect("metric should be created"); - pub static ref GAUGE_MEMORY_SPILL_TO_HDFS: IntGauge = - IntGauge::new("memory_spill_to_hdfs", "memory spill to hdfs") - .expect("metric should be created"); - pub static ref TOTAL_APP_NUMBER: IntCounter = - IntCounter::new("total_app_number", "total_app_number").expect("metrics should be created"); - pub static ref TOTAL_PARTITION_NUMBER: IntCounter = - IntCounter::new("total_partition_number", "total_partition_number") - .expect("metrics should be created"); - pub static ref GAUGE_APP_NUMBER: IntGauge = - IntGauge::new("app_number", "app_number").expect("metrics should be created"); - pub static ref GAUGE_PARTITION_NUMBER: IntGauge = - IntGauge::new("partition_number", "partition_number").expect("metrics should be created"); - pub static ref TOTAL_REQUIRE_BUFFER_FAILED: IntCounter = - IntCounter::new("total_require_buffer_failed", "total_require_buffer_failed") - .expect("metrics should be created"); - pub static ref TOTAL_HUGE_PARTITION_REQUIRE_BUFFER_FAILED: IntCounter = IntCounter::new( + .expect("metric should be created") +}); +pub static TOTAL_MEMORY_SPILL_TO_HDFS: Lazy = Lazy::new(|| { + IntCounter::new("total_memory_spill_to_hdfs", "memory spill to hdfs") + .expect("metric should be created") +}); +pub static GAUGE_MEMORY_SPILL_OPERATION: Lazy = + Lazy::new(|| IntGauge::new("memory_spill", "memory spill").expect("metric should be created")); +pub static GAUGE_MEMORY_SPILL_TO_LOCALFILE: Lazy = Lazy::new(|| { + IntGauge::new("memory_spill_to_localfile", "memory spill to localfile") + .expect("metric should be created") +}); +pub static GAUGE_MEMORY_SPILL_TO_HDFS: Lazy = Lazy::new(|| { + IntGauge::new("memory_spill_to_hdfs", "memory spill to hdfs").expect("metric should be created") +}); +pub static TOTAL_APP_NUMBER: Lazy = Lazy::new(|| { + IntCounter::new("total_app_number", "total_app_number").expect("metrics should be created") +}); +pub static TOTAL_PARTITION_NUMBER: Lazy = Lazy::new(|| { + IntCounter::new("total_partition_number", "total_partition_number") + .expect("metrics should be created") +}); +pub static GAUGE_APP_NUMBER: Lazy = + Lazy::new(|| IntGauge::new("app_number", "app_number").expect("metrics should be created")); +pub static GAUGE_PARTITION_NUMBER: Lazy = Lazy::new(|| { + IntGauge::new("partition_number", "partition_number").expect("metrics should be created") +}); +pub static TOTAL_REQUIRE_BUFFER_FAILED: Lazy = Lazy::new(|| { + IntCounter::new("total_require_buffer_failed", "total_require_buffer_failed") + .expect("metrics should be created") +}); +pub static TOTAL_HUGE_PARTITION_REQUIRE_BUFFER_FAILED: Lazy = Lazy::new(|| { + IntCounter::new( + "total_huge_partition_require_buffer_failed", "total_huge_partition_require_buffer_failed", - "total_huge_partition_require_buffer_failed" ) - .expect("metrics should be created"); -} + .expect("metrics should be created") +}); fn register_custom_metrics() { REGISTRY