Skip to content

Commit

Permalink
runtime: add near_action_called_count metric with an action label (#…
Browse files Browse the repository at this point in the history
…6679)

Replace `near_action_<action-type>_total` metrics with a single
`near_action_called_count` metric with an action label.  This
simplifies the code considerably and makes it easier to scrape,
aggregate and otherwise manipulate the metric in Prometheus.
  • Loading branch information
mina86 authored Apr 26, 2022
1 parent ab04de4 commit 0390c24
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 73 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<msg-type>_{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_<action-type>_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]

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
12 changes: 11 additions & 1 deletion core/primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -356,7 +355,6 @@ impl Runtime {
)?;
}
Action::FunctionCall(function_call) => {
metrics::ACTION_FUNCTION_CALL_TOTAL.inc();
action_function_call(
state_update,
apply_state,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -418,7 +414,6 @@ impl Runtime {
)?;
}
Action::AddKey(add_key) => {
metrics::ACTION_ADD_KEY_TOTAL.inc();
action_add_key(
apply_state,
state_update,
Expand All @@ -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,
Expand All @@ -441,7 +435,6 @@ impl Runtime {
)?;
}
Action::DeleteAccount(delete_account) => {
metrics::ACTION_DELETE_ACCOUNT_TOTAL.inc();
action_delete_account(
state_update,
account,
Expand All @@ -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,
Expand Down
69 changes: 7 additions & 62 deletions runtime/runtime/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounter> = 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<IntCounterVec> = 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<IntCounter> = Lazy::new(|| {
try_create_int_counter(
"near_transaction_processed_total",
Expand Down

0 comments on commit 0390c24

Please sign in to comment.