|
1 | 1 | //! Tests for scheduler metrics. |
2 | 2 |
|
3 | 3 | use super::super::test_utilities::{ |
4 | | - SchedulerTestBuilder, TestInstallCode, ingress, instructions, on_response, other_side, |
| 4 | + SchedulerTest, SchedulerTestBuilder, TestInstallCode, ingress, instructions, on_response, |
| 5 | + other_side, |
5 | 6 | }; |
6 | 7 | use super::super::*; |
7 | 8 | use super::{ |
@@ -44,6 +45,20 @@ use ic_types_test_utils::ids::{canister_test_id, message_test_id, subnet_test_id |
44 | 45 | use more_asserts::assert_ge; |
45 | 46 | use std::time::Duration; |
46 | 47 |
|
| 48 | +/// Observes the state metrics at `height`, having first refreshed the derived |
| 49 | +/// consumed-cycles total that the `replicated_state_consumed_cycles_since_replica_started` |
| 50 | +/// gauge reads. Production refreshes it on every `commit_and_certify`, which this |
| 51 | +/// harness never does. |
| 52 | +fn observe_state_metrics(test: &mut SchedulerTest, height: u64) { |
| 53 | + test.state_mut().refresh_consumed_cycles(); |
| 54 | + test.state_metrics().observe( |
| 55 | + test.state().metadata.own_subnet_id, |
| 56 | + test.state(), |
| 57 | + height.into(), |
| 58 | + &no_op_logger(), |
| 59 | + ); |
| 60 | +} |
| 61 | + |
47 | 62 | #[test] |
48 | 63 | fn validate_consumed_instructions_metric() { |
49 | 64 | let mut test = SchedulerTestBuilder::new() |
@@ -892,12 +907,7 @@ fn threshold_signature_agreements_metric_is_updated() { |
892 | 907 | ]) |
893 | 908 | .build(); |
894 | 909 |
|
895 | | - test.state_metrics().observe( |
896 | | - test.state().metadata.own_subnet_id, |
897 | | - test.state(), |
898 | | - 1.into(), |
899 | | - &no_op_logger(), |
900 | | - ); |
| 910 | + observe_state_metrics(&mut test, 1); |
901 | 911 |
|
902 | 912 | let canister_id = test.create_canister(); |
903 | 913 |
|
@@ -1056,12 +1066,7 @@ fn threshold_signature_agreements_metric_is_updated() { |
1056 | 1066 |
|
1057 | 1067 | test.execute_round(ExecutionRoundType::OrdinaryRound); |
1058 | 1068 |
|
1059 | | - test.state_metrics().observe( |
1060 | | - test.state().metadata.own_subnet_id, |
1061 | | - test.state(), |
1062 | | - 2.into(), |
1063 | | - &no_op_logger(), |
1064 | | - ); |
| 1069 | + observe_state_metrics(&mut test, 2); |
1065 | 1070 |
|
1066 | 1071 | let threshold_signature_agreements_after = &test |
1067 | 1072 | .state() |
@@ -1116,12 +1121,7 @@ fn consumed_cycles_ecdsa_outcalls_are_added_to_consumed_cycles_total() { |
1116 | 1121 |
|
1117 | 1122 | let canister_id = test.create_canister(); |
1118 | 1123 |
|
1119 | | - test.state_metrics().observe( |
1120 | | - test.state().metadata.own_subnet_id, |
1121 | | - test.state(), |
1122 | | - 0.into(), |
1123 | | - &no_op_logger(), |
1124 | | - ); |
| 1124 | + observe_state_metrics(&mut test, 0); |
1125 | 1125 |
|
1126 | 1126 | let consumed_cycles_before = NominalCycles::new( |
1127 | 1127 | fetch_gauge( |
@@ -1153,12 +1153,7 @@ fn consumed_cycles_ecdsa_outcalls_are_added_to_consumed_cycles_total() { |
1153 | 1153 | .sign_with_ecdsa_contexts(); |
1154 | 1154 | assert_eq!(sign_with_ecdsa_contexts.len(), 1); |
1155 | 1155 |
|
1156 | | - test.state_metrics().observe( |
1157 | | - test.state().metadata.own_subnet_id, |
1158 | | - test.state(), |
1159 | | - 0.into(), |
1160 | | - &no_op_logger(), |
1161 | | - ); |
| 1156 | + observe_state_metrics(&mut test, 0); |
1162 | 1157 | let consumed_cycles_after = NominalCycles::new( |
1163 | 1158 | fetch_gauge( |
1164 | 1159 | test.metrics_registry(), |
@@ -1197,12 +1192,7 @@ fn consumed_cycles_http_outcalls_are_added_to_consumed_cycles_total() { |
1197 | 1192 | .subnet_features |
1198 | 1193 | .http_requests = true; |
1199 | 1194 |
|
1200 | | - test.state_metrics().observe( |
1201 | | - test.state().metadata.own_subnet_id, |
1202 | | - test.state(), |
1203 | | - 0.into(), |
1204 | | - &no_op_logger(), |
1205 | | - ); |
| 1195 | + observe_state_metrics(&mut test, 0); |
1206 | 1196 |
|
1207 | 1197 | let consumed_cycles_before = NominalCycles::new( |
1208 | 1198 | fetch_gauge( |
@@ -1263,12 +1253,7 @@ fn consumed_cycles_http_outcalls_are_added_to_consumed_cycles_total() { |
1263 | 1253 | Some(NumBytes::from(response_size_limit)), |
1264 | 1254 | ); |
1265 | 1255 |
|
1266 | | - test.state_metrics().observe( |
1267 | | - test.state().metadata.own_subnet_id, |
1268 | | - test.state(), |
1269 | | - 0.into(), |
1270 | | - &no_op_logger(), |
1271 | | - ); |
| 1256 | + observe_state_metrics(&mut test, 0); |
1272 | 1257 | let consumed_cycles_after = NominalCycles::new( |
1273 | 1258 | fetch_gauge( |
1274 | 1259 | test.metrics_registry(), |
@@ -1434,12 +1419,7 @@ fn consumed_cycles_for_instructions_are_updated_from_valid_canisters() { |
1434 | 1419 | .system_state |
1435 | 1420 | .consume_cycles(removed_cycles); |
1436 | 1421 |
|
1437 | | - test.state_metrics().observe( |
1438 | | - test.state().metadata.own_subnet_id, |
1439 | | - test.state(), |
1440 | | - 0.into(), |
1441 | | - &no_op_logger(), |
1442 | | - ); |
| 1422 | + observe_state_metrics(&mut test, 0); |
1443 | 1423 |
|
1444 | 1424 | assert_eq!( |
1445 | 1425 | fetch_gauge_vec( |
@@ -1480,12 +1460,7 @@ fn consumed_cycles_for_resource_allocations_are_updated_from_valid_canisters() { |
1480 | 1460 | test.advance_time(duration); |
1481 | 1461 | test.charge_for_resource_allocations(); |
1482 | 1462 |
|
1483 | | - test.state_metrics().observe( |
1484 | | - test.state().metadata.own_subnet_id, |
1485 | | - test.state(), |
1486 | | - 0.into(), |
1487 | | - &no_op_logger(), |
1488 | | - ); |
| 1463 | + observe_state_metrics(&mut test, 0); |
1489 | 1464 |
|
1490 | 1465 | let expected_memory_cycles = (test.memory_cost(memory_allocation, duration) |
1491 | 1466 | + test.canister_base_cost(memory_allocation, duration)) |
@@ -1558,12 +1533,7 @@ fn consumed_cycles_are_updated_from_deleted_canisters() { |
1558 | 1533 | ); |
1559 | 1534 | test.execute_round(ExecutionRoundType::OrdinaryRound); |
1560 | 1535 |
|
1561 | | - test.state_metrics().observe( |
1562 | | - test.state().metadata.own_subnet_id, |
1563 | | - test.state(), |
1564 | | - 0.into(), |
1565 | | - &no_op_logger(), |
1566 | | - ); |
| 1536 | + observe_state_metrics(&mut test, 0); |
1567 | 1537 |
|
1568 | 1538 | assert_eq!( |
1569 | 1539 | fetch_gauge_vec( |
|
0 commit comments