Skip to content

Commit

Permalink
iUse once_cell to replace lazy_static macro (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
pegasas authored Aug 20, 2023
1 parent 5659ba3 commit 97c7522
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 57 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PoemHTTPServer> = new_server();
}
pub static HTTP_SERVICE: Lazy<Box<PoemHTTPServer>> = Lazy::new(|| new_server());

/// Implement the own handlers for concrete components
pub trait Handler {
Expand Down
117 changes: 66 additions & 51 deletions src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -87,60 +86,76 @@ pub static GRPC_BUFFER_REQUIRE_PROCESS_TIME: Lazy<Histogram> = 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<IntCounter> = Lazy::new(|| {
IntCounter::new("total_memory_used", "Total memory used").expect("metric should be created")
});

pub static TOTAL_LOCALFILE_USED: Lazy<IntCounter> = Lazy::new(|| {
IntCounter::new("total_localfile_used", "Total localfile used")
.expect("metric should be created")
});

pub static TOTAL_HDFS_USED: Lazy<IntCounter> = Lazy::new(|| {
IntCounter::new("total_hdfs_used", "Total hdfs used").expect("metric should be created")
});
pub static GAUGE_MEMORY_USED: Lazy<IntGauge> =
Lazy::new(|| IntGauge::new("memory_used", "memory used").expect("metric should be created"));
pub static GAUGE_MEMORY_ALLOCATED: Lazy<IntGauge> = Lazy::new(|| {
IntGauge::new("memory_allocated", "memory allocated").expect("metric should be created")
});
pub static GAUGE_MEMORY_CAPACITY: Lazy<IntGauge> = Lazy::new(|| {
IntGauge::new("memory_capacity", "memory capacity").expect("metric should be created")
});
pub static TOTAL_MEMORY_SPILL_OPERATION: Lazy<IntCounter> = Lazy::new(|| {
IntCounter::new("total_memory_spill", "memory capacity").expect("metric should be created")
});
pub static TOTAL_MEMORY_SPILL_OPERATION_FAILED: Lazy<IntCounter> = Lazy::new(|| {
IntCounter::new("total_memory_spill_failed", "memory capacity")
.expect("metric should be created")
});
pub static TOTAL_MEMORY_SPILL_TO_LOCALFILE: Lazy<IntCounter> = 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<IntCounter> = 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<IntGauge> =
Lazy::new(|| IntGauge::new("memory_spill", "memory spill").expect("metric should be created"));
pub static GAUGE_MEMORY_SPILL_TO_LOCALFILE: Lazy<IntGauge> = 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<IntGauge> = Lazy::new(|| {
IntGauge::new("memory_spill_to_hdfs", "memory spill to hdfs").expect("metric should be created")
});
pub static TOTAL_APP_NUMBER: Lazy<IntCounter> = Lazy::new(|| {
IntCounter::new("total_app_number", "total_app_number").expect("metrics should be created")
});
pub static TOTAL_PARTITION_NUMBER: Lazy<IntCounter> = Lazy::new(|| {
IntCounter::new("total_partition_number", "total_partition_number")
.expect("metrics should be created")
});
pub static GAUGE_APP_NUMBER: Lazy<IntGauge> =
Lazy::new(|| IntGauge::new("app_number", "app_number").expect("metrics should be created"));
pub static GAUGE_PARTITION_NUMBER: Lazy<IntGauge> = Lazy::new(|| {
IntGauge::new("partition_number", "partition_number").expect("metrics should be created")
});
pub static TOTAL_REQUIRE_BUFFER_FAILED: Lazy<IntCounter> = 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<IntCounter> = 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
Expand Down

0 comments on commit 97c7522

Please sign in to comment.