Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add metric for storage reads of missing contracts #12317

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/primitives/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ pub enum MissingTrieValueContext {
TrieStorage,
}

impl MissingTrieValueContext {
pub fn metrics_label(&self) -> &str {
match self {
Self::TrieIterator => "trie_iterator",
Self::TriePrefetchingStorage => "trie_prefetching_storage",
Self::TrieMemoryPartialStorage => "trie_memory_partial_storage",
Self::TrieStorage => "trie_storage",
}
}
}

/// Errors which may occur during working with trie storages, storing
/// trie values (trie nodes and state values) by their hashes.
#[derive(
Expand Down
9 changes: 8 additions & 1 deletion core/store/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::TrieStorage;
use crate::{metrics, TrieStorage};
use near_primitives::errors::StorageError;
use near_primitives::hash::CryptoHash;
use near_primitives::stateless_validation::contract_distribution::CodeHash;
use near_vm_runner::ContractCode;
Expand Down Expand Up @@ -124,6 +125,12 @@ impl ContractStorage {

match self.storage.retrieve_raw_bytes(&code_hash) {
Ok(raw_code) => Some(ContractCode::new(raw_code.to_vec(), Some(code_hash))),
Err(StorageError::MissingTrieValue(context, _)) => {
metrics::STORAGE_MISSING_CONTRACTS_COUNT
.with_label_values(&[context.metrics_label()])
.inc();
None
}
Err(_) => None,
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/store/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,16 @@ pub static TRIE_MEMORY_PARTIAL_STORAGE_MISSING_VALUES_COUNT: LazyLock<IntCounter
.unwrap()
});

/// This metrics is useful to track witness contract distribution failures.
pub static STORAGE_MISSING_CONTRACTS_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
try_create_int_counter_vec(
"near_storage_missing_contracts_count",
"Number of contract reads from storage resulted in MissingTrieValue error",
&["context"],
)
.unwrap()
});

fn export_store_stats(store: &Store, temperature: Temperature) {
if let Some(stats) = store.get_store_statistics() {
tracing::debug!(target:"metrics", "Exporting the db metrics for {temperature:?} store.");
Expand Down
Loading