diff --git a/CHANGELOG.md b/CHANGELOG.md index fa21c2fb46d..c5ab79f470d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,8 +23,10 @@ * Use kebab-case names for neard subcommands to make them consistent with flag names. snake_case names are still valid for existing subcommands but kebab-case will be used for new commands. * Added `near_peer_message_received_by_type_bytes` metric [#6661](https://github.com/near/nearcore/pull/6661) * Removed `near__{total,bytes}` metrics in favour of `near_peer_message_received_by_type_{total,bytes}` metrics [#6661](https://github.com/near/nearcore/pull/6661) -* Make it possible to update logging at runtime: [#6665](https://github.com/near/nearcore/pull/6665) +* Added `near_action_called_count` metric [#6679]((https://github.com/near/nearcore/pull/6679) +* Removed `near_action__total` metrics [#6679]((https://github.com/near/nearcore/pull/6679) * Added `near_build_info` metric which exports neard’s build information [#6680](https://github.com/near/nearcore/pull/6680) +* Make it possible to update logging at runtime: [#6665](https://github.com/near/nearcore/pull/6665) ## 1.25.0 [2022-03-16] diff --git a/Cargo.lock b/Cargo.lock index 33e21e46e4c..684c2473929 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3081,6 +3081,7 @@ dependencies = [ "serde", "serde_json", "smart-default", + "strum", ] [[package]] diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 9d1a7aa3ac6..cdf0e0d4cbd 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -28,6 +28,7 @@ reed-solomon-erasure = "4" serde = { version = "1", features = ["derive", "rc"] } serde_json = "1" smart-default = "0.6" +strum = "0.20" borsh = { version = "0.9", features = ["rc"] } diff --git a/core/primitives/src/transaction.rs b/core/primitives/src/transaction.rs index 9e01d2e05f9..e0f6a3992f9 100644 --- a/core/primitives/src/transaction.rs +++ b/core/primitives/src/transaction.rs @@ -46,7 +46,17 @@ impl Transaction { } #[cfg_attr(feature = "deepsize_feature", derive(deepsize::DeepSizeOf))] -#[derive(BorshSerialize, BorshDeserialize, Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] +#[derive( + BorshSerialize, + BorshDeserialize, + Serialize, + Deserialize, + PartialEq, + Eq, + Debug, + Clone, + strum::AsRefStr, +)] pub enum Action { /// Create an (sub)account using a transaction `receiver_id` as an ID for /// a new account ID must pass validation rules described here diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 356507f8695..1766667cb64 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -331,9 +331,9 @@ impl Runtime { result.result = Err(e); return Ok(result); } + metrics::ACTION_CALLED_COUNT.with_label_values(&[action.as_ref()]).inc(); match action { Action::CreateAccount(_) => { - metrics::ACTION_CREATE_ACCOUNT_TOTAL.inc(); action_create_account( &apply_state.config.transaction_costs, &apply_state.config.account_creation_config, @@ -345,7 +345,6 @@ impl Runtime { ); } Action::DeployContract(deploy_contract) => { - metrics::ACTION_DEPLOY_CONTRACT_TOTAL.inc(); action_deploy_contract( state_update, account.as_mut().expect(EXPECT_ACCOUNT_EXISTS), @@ -356,7 +355,6 @@ impl Runtime { )?; } Action::FunctionCall(function_call) => { - metrics::ACTION_FUNCTION_CALL_TOTAL.inc(); action_function_call( state_update, apply_state, @@ -374,7 +372,6 @@ impl Runtime { )?; } Action::Transfer(transfer) => { - metrics::ACTION_TRANSFER_TOTAL.inc(); if let Some(account) = account.as_mut() { action_transfer(account, transfer)?; // Check if this is a gas refund, then try to refund the access key allowance. @@ -405,7 +402,6 @@ impl Runtime { } } Action::Stake(stake) => { - metrics::ACTION_STAKE_TOTAL.inc(); action_stake( account.as_mut().expect(EXPECT_ACCOUNT_EXISTS), &mut result, @@ -418,7 +414,6 @@ impl Runtime { )?; } Action::AddKey(add_key) => { - metrics::ACTION_ADD_KEY_TOTAL.inc(); action_add_key( apply_state, state_update, @@ -429,7 +424,6 @@ impl Runtime { )?; } Action::DeleteKey(delete_key) => { - metrics::ACTION_DELETE_KEY_TOTAL.inc(); action_delete_key( &apply_state.config.transaction_costs, state_update, @@ -441,7 +435,6 @@ impl Runtime { )?; } Action::DeleteAccount(delete_account) => { - metrics::ACTION_DELETE_ACCOUNT_TOTAL.inc(); action_delete_account( state_update, account, @@ -455,7 +448,6 @@ impl Runtime { } #[cfg(feature = "protocol_feature_chunk_only_producers")] Action::StakeChunkOnly(stake) => { - metrics::ACTION_STAKE_CHUNK_ONLY_TOTAL.inc(); action_stake( account.as_mut().expect(EXPECT_ACCOUNT_EXISTS), &mut result, diff --git a/runtime/runtime/src/metrics.rs b/runtime/runtime/src/metrics.rs index 055feba2144..a83e170bbef 100644 --- a/runtime/runtime/src/metrics.rs +++ b/runtime/runtime/src/metrics.rs @@ -1,70 +1,15 @@ -use near_metrics::{try_create_int_counter, IntCounter}; +use near_metrics::{try_create_int_counter, try_create_int_counter_vec, IntCounter, IntCounterVec}; use once_cell::sync::Lazy; -pub static ACTION_CREATE_ACCOUNT_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_create_account_total", - "The number of CreateAccount actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_DEPLOY_CONTRACT_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_deploy_contract_total", - "The number of DeployContract actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_FUNCTION_CALL_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_function_call_total", - "The number of FunctionCall actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_TRANSFER_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_transfer_total", - "The number of Transfer actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_STAKE_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_stake_total", - "The number of stake actions called since starting this node", - ) - .unwrap() -}); -#[cfg(feature = "protocol_feature_chunk_only_producers")] -pub static ACTION_STAKE_CHUNK_ONLY_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_stake_chunk_only_total", - "The number of chunk-only stake actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_ADD_KEY_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_add_key_total", - "The number of AddKey actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_DELETE_KEY_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_delete_key_total", - "The number of DeleteKey actions called since starting this node", - ) - .unwrap() -}); -pub static ACTION_DELETE_ACCOUNT_TOTAL: Lazy = Lazy::new(|| { - try_create_int_counter( - "near_action_delete_account_total", - "The number of DeleteAccount actions called since starting this node", +pub static ACTION_CALLED_COUNT: Lazy = Lazy::new(|| { + try_create_int_counter_vec( + "near_action_called_count", + "Number of times given action has been called since starting this node", + &["action"], ) .unwrap() }); + pub static TRANSACTION_PROCESSED_TOTAL: Lazy = Lazy::new(|| { try_create_int_counter( "near_transaction_processed_total",