Skip to content

Commit

Permalink
feat(RUN-893): Metric for large intra subnet calls
Browse files Browse the repository at this point in the history
  • Loading branch information
adambratschikaye committed Feb 7, 2024
1 parent 11798c8 commit 9ad470e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
6 changes: 6 additions & 0 deletions rs/execution_environment/src/execution_environment.rs
Expand Up @@ -66,6 +66,7 @@ use ic_types::{
extract_effective_canister_id, AnonymousQuery, CanisterCall, CanisterCallOrTask,
CanisterMessage, CanisterMessageOrTask, CanisterTask, Payload, RejectContext, Request,
Response, SignedIngressContent, StopCanisterCallId, StopCanisterContext,
MAX_INTER_CANISTER_PAYLOAD_IN_BYTES,
},
methods::SystemMethod,
nominal_cycles::NominalCycles,
Expand Down Expand Up @@ -3260,6 +3261,11 @@ pub fn execute_canister(
},
None => {
let message = canister.pop_input().unwrap();
if let CanisterMessage::Request(req) = &message {
if req.payload_size_bytes() > MAX_INTER_CANISTER_PAYLOAD_IN_BYTES {
exec_env.metrics.oversize_intra_subnet_messages.inc();
}
}
(CanisterMessageOrTask::Message(message), None)
}
};
Expand Down
9 changes: 9 additions & 0 deletions rs/execution_environment/src/execution_environment_metrics.rs
Expand Up @@ -51,6 +51,11 @@ pub(crate) struct ExecutionEnvironmentMetrics {
pub(crate) invalid_canister_state_error: IntCounter,
/// Critical error for failed canister creation.
pub(crate) canister_creation_error: IntCounter,
/// Intra-subnet messages that would be oversize if they were between
/// different subnets (not including install_code messages). This metric can
/// be removed if the limit for intra-subnet messages and inter-subnet
/// messages are brought back in sync.
pub(crate) oversize_intra_subnet_messages: IntCounter,
}

impl ExecutionEnvironmentMetrics {
Expand Down Expand Up @@ -104,6 +109,10 @@ impl ExecutionEnvironmentMetrics {
.error_counter("execution_environment_invalid_canister_state"),
canister_creation_error: metrics_registry
.error_counter("execution_environment_canister_creation_failed"),
oversize_intra_subnet_messages: metrics_registry.int_counter(
"execution_environment_oversize_intra_subnet_messages_total",
"Total number of intra-subnet messages that exceed the 2 MiB limit for inter-subnet messages."
),
}
}

Expand Down
79 changes: 78 additions & 1 deletion rs/execution_environment/tests/execution_test.rs
@@ -1,4 +1,5 @@
use candid::Encode;
use ic_base_types::PrincipalId;
use ic_config::{
execution_environment::Config as HypervisorConfig,
subnet_config::{CyclesAccountManagerConfig, SubnetConfig},
Expand All @@ -9,8 +10,9 @@ use ic_ic00_types::{
};
use ic_registry_subnet_type::SubnetType;
use ic_state_machine_tests::{
ErrorCode, StateMachine, StateMachineBuilder, StateMachineConfig, UserError,
ErrorCode, IngressStatus, StateMachine, StateMachineBuilder, StateMachineConfig, UserError,
};
use ic_test_utilities_metrics::fetch_int_counter;
use ic_types::{ingress::WasmResult, CanisterId, Cycles, NumBytes};
use ic_universal_canister::{call_args, wasm, UNIVERSAL_CANISTER_WASM};
use std::{convert::TryInto, sync::Arc, time::Duration};
Expand Down Expand Up @@ -1421,3 +1423,78 @@ fn reserved_balance_limit_is_initialized_after_replica_upgrade() {
Some(CyclesAccountManagerConfig::application_subnet().default_reserved_balance_limit),
)
}

#[test]
fn execution_observes_oversize_messages() {
let sm = StateMachine::new();

let a_id = sm
.install_canister_with_cycles(
UNIVERSAL_CANISTER_WASM.into(),
vec![],
None,
INITIAL_CYCLES_BALANCE,
)
.unwrap();

// Canister A calls itself with a large message
let a_calls_self_wasm = wasm()
.stable_grow(100)
.inter_update(
a_id,
call_args().eval_other_side(wasm().stable_read(0, 3 * 1024 * 1024).build()),
)
.build();
let ingress_id = sm.send_ingress(
PrincipalId::new_anonymous(),
a_id,
"update",
a_calls_self_wasm,
);

assert!(matches!(
sm.ingress_status(&ingress_id),
IngressStatus::Known { .. }
));

assert_eq!(
1,
fetch_int_counter(
sm.metrics_registry(),
"execution_environment_oversize_intra_subnet_messages_total"
)
.unwrap()
);

// Canister A calls B with a large message
let b_id = sm
.install_canister_with_cycles(
UNIVERSAL_CANISTER_WASM.into(),
vec![],
None,
INITIAL_CYCLES_BALANCE,
)
.unwrap();

let a_calls_b_wasm = wasm()
.inter_update(
b_id,
call_args().eval_other_side(wasm().stable_read(0, 3 * 1024 * 1024)),
)
.build();
let ingress_id = sm.send_ingress(PrincipalId::new_anonymous(), a_id, "update", a_calls_b_wasm);

assert!(matches!(
sm.ingress_status(&ingress_id),
IngressStatus::Known { .. }
));

assert_eq!(
2,
fetch_int_counter(
sm.metrics_registry(),
"execution_environment_oversize_intra_subnet_messages_total"
)
.unwrap()
);
}

0 comments on commit 9ad470e

Please sign in to comment.