Skip to content

Commit

Permalink
refactor(papyrus_storage)!: delte dump_declared_classes utils (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
DvirYo-starkware authored Dec 9, 2024
1 parent 0321278 commit f9a0fb1
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 366 deletions.
3 changes: 2 additions & 1 deletion crates/papyrus_node/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use papyrus_p2p_sync::{Protocol, BUFFER_SIZE};
use papyrus_protobuf::consensus::{ProposalPart, StreamMessage};
#[cfg(feature = "rpc")]
use papyrus_rpc::run_server;
use papyrus_storage::{open_storage, update_storage_metrics, StorageReader, StorageWriter};
use papyrus_storage::storage_metrics::update_storage_metrics;
use papyrus_storage::{open_storage, StorageReader, StorageWriter};
use papyrus_sync::sources::base_layer::{BaseLayerSourceError, EthereumBaseLayerSource};
use papyrus_sync::sources::central::{CentralError, CentralSource, CentralSourceConfig};
use papyrus_sync::sources::pending::PendingSource;
Expand Down
5 changes: 0 additions & 5 deletions crates/papyrus_storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ description = "A storage implementation for a Starknet node."
document_calls = ["lazy_static"]
testing = ["tempfile"]

[[bin]]
name = "dump_declared_classes"
path = "src/bin/dump_declared_classes.rs"
required-features = ["clap"]

[[bin]]
name = "storage_benchmark"
path = "src/bin/storage_benchmark.rs"
Expand Down
41 changes: 0 additions & 41 deletions crates/papyrus_storage/src/bin/README.md

This file was deleted.

79 changes: 0 additions & 79 deletions crates/papyrus_storage/src/bin/dump_declared_classes.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/papyrus_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub mod class;
pub mod compiled_class;
#[cfg(feature = "document_calls")]
pub mod document_calls;
pub mod utils;
pub mod storage_metrics;
// TODO(yair): Make the compression_utils module pub(crate) or extract it from the crate.
#[doc(hidden)]
pub mod compression_utils;
Expand Down Expand Up @@ -150,7 +150,6 @@ use crate::db::{
use crate::header::StorageBlockHeader;
use crate::mmap_file::MMapFileStats;
use crate::state::data::IndexedDeprecatedContractClass;
pub use crate::utils::update_storage_metrics;
use crate::version::{VersionStorageReader, VersionStorageWriter};

// For more details on the storage version, see the module documentation.
Expand Down
31 changes: 31 additions & 0 deletions crates/papyrus_storage/src/storage_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! module for metrics utilities.
#[cfg(test)]
#[path = "storage_metrics_test.rs"]
mod storage_metrics_test;

use metrics::{absolute_counter, gauge};
use tracing::debug;

use crate::{StorageReader, StorageResult};

// TODO(dvir): add storage metrics names to this module.

// TODO(dvir): consider adding storage size metrics.
// TODO(dvir): relocate all the storage metrics in one module and export them (also in other
// crates).
/// Updates storage metrics about the state of the storage.
#[allow(clippy::as_conversions)]
pub fn update_storage_metrics(reader: &StorageReader) -> StorageResult<()> {
debug!("updating storage metrics");
gauge!("storage_free_pages_number", reader.db_reader.get_free_pages()? as f64);
let info = reader.db_reader.get_db_info()?;
absolute_counter!(
"storage_last_page_number",
u64::try_from(info.last_pgno()).expect("usize should fit in u64")
);
absolute_counter!(
"storage_last_transaction_index",
u64::try_from(info.last_txnid()).expect("usize should fit in u64")
);
Ok(())
}
44 changes: 44 additions & 0 deletions crates/papyrus_storage/src/storage_metrics_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use metrics_exporter_prometheus::PrometheusBuilder;
use papyrus_test_utils::prometheus_is_contained;
use prometheus_parse::Value::{Counter, Gauge};

use super::update_storage_metrics;
use crate::test_utils::get_test_storage;

#[test]
fn update_storage_metrics_test() {
let ((reader, _writer), _temp_dir) = get_test_storage();
let handle = PrometheusBuilder::new().install_recorder().unwrap();

assert!(prometheus_is_contained(handle.render(), "storage_free_pages_number", &[]).is_none());
assert!(prometheus_is_contained(handle.render(), "storage_last_page_number", &[]).is_none());
assert!(
prometheus_is_contained(handle.render(), "storage_last_transaction_index", &[]).is_none()
);

update_storage_metrics(&reader).unwrap();

let Gauge(free_pages) =
prometheus_is_contained(handle.render(), "storage_free_pages_number", &[]).unwrap()
else {
panic!("storage_free_pages_number is not a Gauge")
};
// TODO(dvir): add an upper limit when the bug in the binding freelist function will be fixed.
assert!(0f64 < free_pages);

let Counter(last_page) =
prometheus_is_contained(handle.render(), "storage_last_page_number", &[]).unwrap()
else {
panic!("storage_last_page_number is not a Counter")
};
assert!(0f64 < last_page);
assert!(last_page < 1000f64);

let Counter(last_transaction) =
prometheus_is_contained(handle.render(), "storage_last_transaction_index", &[]).unwrap()
else {
panic!("storage_last_transaction_index is not a Counter")
};
assert!(0f64 < last_transaction);
assert!(last_transaction < 100f64);
}
110 changes: 0 additions & 110 deletions crates/papyrus_storage/src/utils.rs

This file was deleted.

Loading

0 comments on commit f9a0fb1

Please sign in to comment.