Track beacon processor import result metrics (#6541)

* Track beacon processor import result metrics

* Update metric name
This commit is contained in:
Lion - dapplion
2024-12-16 12:33:33 +08:00
committed by GitHub
parent d49e1be35d
commit c92c07ff49
4 changed files with 99 additions and 43 deletions

View File

@@ -2,7 +2,8 @@ use beacon_chain::{
attestation_verification::Error as AttnError,
light_client_finality_update_verification::Error as LightClientFinalityUpdateError,
light_client_optimistic_update_verification::Error as LightClientOptimisticUpdateError,
sync_committee_verification::Error as SyncCommitteeError,
sync_committee_verification::Error as SyncCommitteeError, AvailabilityProcessingStatus,
BlockError,
};
use fnv::FnvHashMap;
use lighthouse_network::{
@@ -11,12 +12,19 @@ use lighthouse_network::{
};
pub use metrics::*;
use std::sync::{Arc, LazyLock};
use strum::AsRefStr;
use strum::IntoEnumIterator;
use types::EthSpec;
pub const SUCCESS: &str = "SUCCESS";
pub const FAILURE: &str = "FAILURE";
#[derive(Debug, AsRefStr)]
pub(crate) enum BlockSource {
Gossip,
Rpc,
}
pub static BEACON_BLOCK_MESH_PEERS_PER_CLIENT: LazyLock<Result<IntGaugeVec>> =
LazyLock::new(|| {
try_create_int_gauge_vec(
@@ -59,6 +67,27 @@ pub static SYNC_COMMITTEE_SUBSCRIPTION_REQUESTS: LazyLock<Result<IntCounter>> =
)
});
/*
* Beacon processor
*/
pub static BEACON_PROCESSOR_MISSING_COMPONENTS: LazyLock<Result<IntCounterVec>> = LazyLock::new(
|| {
try_create_int_counter_vec(
"beacon_processor_missing_components_total",
"Total number of imported individual block components that resulted in missing components",
&["source", "component"],
)
},
);
pub static BEACON_PROCESSOR_IMPORT_ERRORS_PER_TYPE: LazyLock<Result<IntCounterVec>> =
LazyLock::new(|| {
try_create_int_counter_vec(
"beacon_processor_import_errors_total",
"Total number of block components that were not verified",
&["source", "component", "type"],
)
});
/*
* Gossip processor
*/
@@ -606,6 +635,37 @@ pub fn register_sync_committee_error(error: &SyncCommitteeError) {
inc_counter_vec(&GOSSIP_SYNC_COMMITTEE_ERRORS_PER_TYPE, &[error.as_ref()]);
}
pub(crate) fn register_process_result_metrics(
result: &std::result::Result<AvailabilityProcessingStatus, BlockError>,
source: BlockSource,
block_component: &'static str,
) {
match result {
Ok(status) => match status {
AvailabilityProcessingStatus::Imported { .. } => match source {
BlockSource::Gossip => {
inc_counter(&BEACON_PROCESSOR_GOSSIP_BLOCK_IMPORTED_TOTAL);
}
BlockSource::Rpc => {
inc_counter(&BEACON_PROCESSOR_RPC_BLOCK_IMPORTED_TOTAL);
}
},
AvailabilityProcessingStatus::MissingComponents { .. } => {
inc_counter_vec(
&BEACON_PROCESSOR_MISSING_COMPONENTS,
&[source.as_ref(), block_component],
);
}
},
Err(error) => {
inc_counter_vec(
&BEACON_PROCESSOR_IMPORT_ERRORS_PER_TYPE,
&[source.as_ref(), block_component, error.as_ref()],
);
}
}
}
pub fn from_result<T, E>(result: &std::result::Result<T, E>) -> &str {
match result {
Ok(_) => SUCCESS,