diff --git a/src/internet_identity/tests/integration/active_anchor_stats/all_domains.rs b/src/internet_identity/tests/integration/active_anchor_stats/all_domains.rs index b881d0df38..b585235363 100644 --- a/src/internet_identity/tests/integration/active_anchor_stats/all_domains.rs +++ b/src/internet_identity/tests/integration/active_anchor_stats/all_domains.rs @@ -4,8 +4,7 @@ use canister_tests::api::internet_identity as api; use canister_tests::flows; use canister_tests::framework::*; use ic_test_state_machine_client::CallError; -use std::ops::Add; -use std::time::{Duration, UNIX_EPOCH}; +use std::time::Duration; const DAY_SECONDS: u64 = 24 * 60 * 60; const MONTH_SECONDS: u64 = 30 * DAY_SECONDS; @@ -16,34 +15,15 @@ fn should_report_daily_active_anchors() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("internet_identity_daily_active_anchors")); + let anchor_number = flows::register_anchor(&env, canister_id); flows::register_anchor(&env, canister_id); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors - .counter, - 2 - ); - // repeated activity within the 24h collection period should not increase the counter api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors - .counter, - 2 - ); - env.advance_time(Duration::from_secs(DAY_SECONDS)); // some activity is required to update the stats @@ -54,28 +34,6 @@ fn should_report_daily_active_anchors() -> Result<(), CallError> { "internet_identity_daily_active_anchors", 2f64, ); - - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .daily_active_anchors - .counter, - 1 - ); - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .completed - .daily_active_anchors - .unwrap() - .counter, - 2 - ); Ok(()) } @@ -85,38 +43,15 @@ fn should_report_monthly_active_anchors() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("internet_identity_monthly_active_anchors")); + let anchor_number = flows::register_anchor(&env, canister_id); flows::register_anchor(&env, canister_id); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .counter, - 2 - ); - // repeated activity within the 30-day collection period should not increase the counter api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .counter, - 2 - ); - env.advance_time(Duration::from_secs(MONTH_SECONDS)); // some activity is required to update the stats @@ -127,30 +62,6 @@ fn should_report_monthly_active_anchors() -> Result<(), CallError> { "internet_identity_monthly_active_anchors", 2f64, ); - - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .counter, - 1 - ); - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .completed - .monthly_active_anchors - .unwrap() - .counter, - 2 - ); Ok(()) } @@ -160,53 +71,17 @@ fn should_update_monthly_active_anchors_every_day() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("internet_identity_monthly_active_anchors")); + let anchor_number = flows::register_anchor(&env, canister_id); flows::register_anchor(&env, canister_id); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .counter, - 2 - ); - // advance by 24h to record in the shifted 30-day period env.advance_time(Duration::from_secs(DAY_SECONDS)); api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .counter, - 2 - ); - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .monthly_active_anchors - .get(1) - .unwrap() - .counter, - 1 - ); - // advance time to complete the first 30-day collection period env.advance_time(Duration::from_secs(29 * DAY_SECONDS)); @@ -219,30 +94,6 @@ fn should_update_monthly_active_anchors_every_day() -> Result<(), CallError> { 2f64, ); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .counter, - 1 - ); - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .completed - .monthly_active_anchors - .unwrap() - .counter, - 2 - ); - // advance by 24h to complete the next 30-day period env.advance_time(Duration::from_secs(DAY_SECONDS)); @@ -263,83 +114,23 @@ fn should_update_monthly_active_anchors_every_day() -> Result<(), CallError> { fn should_keep_stats_across_upgrades() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); - flows::register_anchor(&env, canister_id); - - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors - .counter, - 1 - ); - - upgrade_ii_canister(&env, canister_id, II_WASM.clone()); - - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors - .counter, - 1 - ); - Ok(()) -} + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("internet_identity_daily_active_anchors")); -/// Tests that the ongoing monthly collection periods are rolled over correctly. -#[test] -fn should_have_30_parallel_monthly_collection_windows() -> Result<(), CallError> { - let env = env(); - let canister_id = install_ii_canister(&env, II_WASM.clone()); let anchor_number = flows::register_anchor(&env, canister_id); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .len(), - 1 - ); + upgrade_ii_canister(&env, canister_id, II_WASM.clone()); - for _ in 0..30 { - // advance time to trigger the next ongoing 30-day collection period - env.advance_time(Duration::from_secs(DAY_SECONDS)); - // some activity is required to update the stats - api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - } - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .monthly_active_anchors - .len(), - 30 - ); + env.advance_time(Duration::from_secs(DAY_SECONDS)); + + // some activity is required to update the stats + api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - // after 30 days the first monthly collection period should be completed - assert_eq!( - stats - .active_anchor_stats - .as_ref() - .unwrap() - .completed - .monthly_active_anchors - .as_ref() - .unwrap() - .counter, - 1 + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_daily_active_anchors", + 1f64, ); Ok(()) @@ -351,31 +142,22 @@ fn should_have_correct_stats_after_long_inactivity() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("internet_identity_daily_active_anchors")); + // some activity let anchor_number = flows::register_anchor(&env, canister_id); - let t0 = env.time(); - // more than 24h without activity env.advance_time(Duration::from_secs(2 * DAY_SECONDS + 1)); // some activity to update stats api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - let stats = api::stats(&env, canister_id)?; - let daily_stats = stats - .active_anchor_stats - .unwrap() - .completed - .daily_active_anchors - .unwrap(); - assert_eq!(daily_stats.counter, 0); - assert_eq!( - daily_stats.start_timestamp, - t0.duration_since(UNIX_EPOCH) - .unwrap() - .add(Duration::from_secs(DAY_SECONDS)) - .as_nanos() as u64 + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_daily_active_anchors", + 0f64, ); // more than 30 days without activity @@ -384,33 +166,10 @@ fn should_have_correct_stats_after_long_inactivity() -> Result<(), CallError> { // some activity to update stats api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - let stats = api::stats(&env, canister_id)?; - let monthly_stats = stats - .active_anchor_stats - .as_ref() - .unwrap() - .completed - .monthly_active_anchors - .as_ref() - .unwrap(); - assert_eq!(monthly_stats.counter, 0); - assert_eq!( - monthly_stats.start_timestamp, - t0.duration_since(UNIX_EPOCH) - .unwrap() - .add(Duration::from_secs(3 * DAY_SECONDS)) - .as_nanos() as u64 - ); - - // there is one ongoing collection period setup - assert_eq!( - stats - .active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .len(), - 1 + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_monthly_active_anchors", + 0f64, ); Ok(()) diff --git a/src/internet_identity/tests/integration/active_anchor_stats/ii_domains.rs b/src/internet_identity/tests/integration/active_anchor_stats/ii_domains.rs index c95fe55c90..44ff51d4c0 100644 --- a/src/internet_identity/tests/integration/active_anchor_stats/ii_domains.rs +++ b/src/internet_identity/tests/integration/active_anchor_stats/ii_domains.rs @@ -3,8 +3,7 @@ use canister_tests::api::internet_identity as api; use canister_tests::flows; use canister_tests::framework::*; use ic_test_state_machine_client::CallError; -use std::ops::Add; -use std::time::{Duration, UNIX_EPOCH}; +use std::time::Duration; const DAY_SECONDS: u64 = 24 * 60 * 60; const MONTH_SECONDS: u64 = 30 * DAY_SECONDS; @@ -25,10 +24,8 @@ fn should_report_daily_active_anchors() -> Result<(), CallError> { let no_origin_device = device_with_origin(None); // ensure stats are initially absent - assert_eq!( - api::stats(&env, canister_id)?.domain_active_anchor_stats, - None - ); + assert!(!get_metrics(&env, canister_id) + .contains("internet_identity_daily_active_anchors_by_domain")); let ic0_app_anchor = flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); @@ -58,30 +55,6 @@ fn should_report_daily_active_anchors() -> Result<(), CallError> { flows::register_anchor_with_device(&env, canister_id, &other_origin_device); flows::register_anchor_with_device(&env, canister_id, &no_origin_device); - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors; - assert_eq!(stats.ic0_app_counter, 6); - assert_eq!(stats.internetcomputer_org_counter, 2); - assert_eq!(stats.both_ii_domains_counter, 1); - - // repeated activity within the 24h collection period should not increase the counter - api::get_anchor_info( - &env, - canister_id, - principal(&ic0_app_device), - ic0_app_anchor, - )?; - - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors; - assert_eq!(stats.ic0_app_counter, 6); - env.advance_time(Duration::from_secs(DAY_SECONDS)); // some activity is required to update the stats @@ -108,16 +81,6 @@ fn should_report_daily_active_anchors() -> Result<(), CallError> { "internet_identity_daily_active_anchors_by_domain{domain=\"both_ii_domains\"}", 1f64, ); - - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .completed - .daily_active_anchors - .unwrap(); - assert_eq!(stats.ic0_app_counter, 6); - assert_eq!(stats.internetcomputer_org_counter, 2); - assert_eq!(stats.both_ii_domains_counter, 1); Ok(()) } @@ -133,10 +96,8 @@ fn should_report_monthly_active_anchors() -> Result<(), CallError> { let no_origin_device = device_with_origin(None); // ensure stats are initially absent - assert_eq!( - api::stats(&env, canister_id)?.domain_active_anchor_stats, - None - ); + assert!(!get_metrics(&env, canister_id) + .contains("internet_identity_monthly_active_anchors_by_domain")); let ic0_app_anchor = flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); @@ -165,36 +126,6 @@ fn should_report_monthly_active_anchors() -> Result<(), CallError> { flows::register_anchor_with_device(&env, canister_id, &other_origin_device); flows::register_anchor_with_device(&env, canister_id, &no_origin_device); - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .clone(); - assert_eq!(stats.ic0_app_counter, 2); - assert_eq!(stats.internetcomputer_org_counter, 3); - assert_eq!(stats.both_ii_domains_counter, 1); - - // repeated activity within the 24h collection period should not increase the counter - api::get_anchor_info( - &env, - canister_id, - principal(&ic0_app_device), - ic0_app_anchor, - )?; - - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .clone(); - assert_eq!(stats.ic0_app_counter, 2); - env.advance_time(Duration::from_secs(MONTH_SECONDS)); // some activity is required to update the stats @@ -221,16 +152,60 @@ fn should_report_monthly_active_anchors() -> Result<(), CallError> { "internet_identity_monthly_active_anchors_by_domain{domain=\"both_ii_domains\"}", 1f64, ); + Ok(()) +} + +/// Tests that active anchors are only counted once in a collection period. +#[test] +fn should_not_count_repeated_activity_in_same_collection_period() -> Result<(), CallError> { + let env = env(); + let canister_id = install_ii_canister(&env, II_WASM.clone()); + let ic0_app_device = device_with_origin(Some(ICP0_APP_ORIGIN.to_string())); + + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("active_anchors_by_domain")); + + let ic0_app_anchor = flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); + + // repeated activity within the 24h collection period should not increase the counter + api::get_anchor_info( + &env, + canister_id, + principal(&ic0_app_device), + ic0_app_anchor, + )?; + + env.advance_time(Duration::from_secs(DAY_SECONDS)); + + // some activity is required to update the stats + api::get_anchor_info( + &env, + canister_id, + principal(&ic0_app_device), + ic0_app_anchor, + )?; + + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_daily_active_anchors_by_domain{domain=\"identity.ic0.app\"}", + 1f64, + ); - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .completed - .monthly_active_anchors - .unwrap(); - assert_eq!(stats.ic0_app_counter, 2); - assert_eq!(stats.internetcomputer_org_counter, 3); - assert_eq!(stats.both_ii_domains_counter, 1); + env.advance_time(Duration::from_secs(MONTH_SECONDS)); + + // some activity is required to update the stats + api::get_anchor_info( + &env, + canister_id, + principal(&ic0_app_device), + ic0_app_anchor, + )?; + + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_monthly_active_anchors_by_domain{domain=\"identity.ic0.app\"}", + 1f64, + ); Ok(()) } @@ -243,32 +218,11 @@ fn should_update_monthly_active_anchors_every_day() -> Result<(), CallError> { let anchor_number = flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .domain_active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .ic0_app_counter, - 2 - ); - // advance by 24h to record in the shifted 30-day period env.advance_time(Duration::from_secs(DAY_SECONDS)); api::get_anchor_info(&env, canister_id, principal(&ic0_app_device), anchor_number)?; - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors; - assert_eq!(stats.first().unwrap().ic0_app_counter, 2); - assert_eq!(stats.get(1).unwrap().ic0_app_counter, 1); - // advance time to complete the first 30-day collection period env.advance_time(Duration::from_secs(29 * DAY_SECONDS)); @@ -281,27 +235,6 @@ fn should_update_monthly_active_anchors_every_day() -> Result<(), CallError> { 2f64, ); - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap(); - assert_eq!( - stats - .ongoing - .monthly_active_anchors - .first() - .unwrap() - .ic0_app_counter, - 1 - ); - assert_eq!( - stats - .completed - .monthly_active_anchors - .unwrap() - .ic0_app_counter, - 2 - ); - // advance by 24h to complete the next 30-day period env.advance_time(Duration::from_secs(DAY_SECONDS)); @@ -322,83 +255,24 @@ fn should_update_monthly_active_anchors_every_day() -> Result<(), CallError> { fn should_keep_stats_across_upgrades() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); - flows::register_anchor(&env, canister_id); - - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .domain_active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors - .internetcomputer_org_counter, - 1 - ); - - upgrade_ii_canister(&env, canister_id, II_WASM.clone()); + let ic0_app_device = device_with_origin(Some(ICP0_APP_ORIGIN.to_string())); + let anchor = flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .domain_active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors - .internetcomputer_org_counter, - 1 - ); + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id) + .contains("internet_identity_daily_active_anchors_by_domain")); - Ok(()) -} + upgrade_ii_canister(&env, canister_id, II_WASM.clone()); -/// Tests that the ongoing monthly collection periods are rolled over correctly. -#[test] -fn should_have_30_parallel_monthly_collection_windows() -> Result<(), CallError> { - let env = env(); - let canister_id = install_ii_canister(&env, II_WASM.clone()); - let anchor_number = flows::register_anchor(&env, canister_id); - - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .domain_active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .len(), - 1 - ); + env.advance_time(Duration::from_secs(DAY_SECONDS)); - for _ in 0..30 { - // advance time to trigger the next ongoing 30-day collection period - env.advance_time(Duration::from_secs(DAY_SECONDS)); - // some activity is required to update the stats - api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - } - let stats = api::stats(&env, canister_id)?; - assert_eq!( - stats - .domain_active_anchor_stats - .as_ref() - .unwrap() - .ongoing - .monthly_active_anchors - .len(), - 30 - ); + // some activity is required to update the stats + api::get_anchor_info(&env, canister_id, ic0_app_device.principal(), anchor)?; - // after 30 days the first monthly collection period should be completed - assert_eq!( - stats - .domain_active_anchor_stats - .as_ref() - .unwrap() - .completed - .monthly_active_anchors - .as_ref() - .unwrap() - .internetcomputer_org_counter, - 1 + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_daily_active_anchors_by_domain{domain=\"identity.ic0.app\"}", + 1f64, ); Ok(()) @@ -409,67 +283,36 @@ fn should_have_30_parallel_monthly_collection_windows() -> Result<(), CallError> fn should_have_correct_stats_after_long_inactivity() -> Result<(), CallError> { let env = env(); let canister_id = install_ii_canister(&env, II_WASM.clone()); + let ic0_app_device = device_with_origin(Some(ICP0_APP_ORIGIN.to_string())); - // some activity - let anchor_number = flows::register_anchor(&env, canister_id); + // ensure stats are initially absent + assert!(!get_metrics(&env, canister_id).contains("active_anchors_by_domain")); - let t0 = env.time(); + // some activity + let anchor_number = flows::register_anchor_with_device(&env, canister_id, &ic0_app_device); // more than 24h without activity env.advance_time(Duration::from_secs(2 * DAY_SECONDS + 1)); // some activity to update stats - api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - - let stats = api::stats(&env, canister_id)?; - let daily_stats = stats - .domain_active_anchor_stats - .unwrap() - .completed - .daily_active_anchors - .unwrap(); - assert_eq!(daily_stats.internetcomputer_org_counter, 0); - assert_eq!( - daily_stats.start_timestamp, - t0.duration_since(UNIX_EPOCH) - .unwrap() - .add(Duration::from_secs(DAY_SECONDS)) - .as_nanos() as u64 + api::get_anchor_info(&env, canister_id, ic0_app_device.principal(), anchor_number)?; + + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_daily_active_anchors_by_domain{domain=\"identity.ic0.app\"}", + 0f64, ); // more than 30 days without activity env.advance_time(Duration::from_secs(31 * DAY_SECONDS)); // some activity to update stats - api::get_anchor_info(&env, canister_id, principal_1(), anchor_number)?; - - let stats = api::stats(&env, canister_id)?; - let monthly_stats = stats - .domain_active_anchor_stats - .as_ref() - .unwrap() - .completed - .monthly_active_anchors - .as_ref() - .unwrap(); - assert_eq!(monthly_stats.internetcomputer_org_counter, 0); - assert_eq!( - monthly_stats.start_timestamp, - t0.duration_since(UNIX_EPOCH) - .unwrap() - .add(Duration::from_secs(3 * DAY_SECONDS)) - .as_nanos() as u64 - ); + api::get_anchor_info(&env, canister_id, ic0_app_device.principal(), anchor_number)?; - // there is one ongoing collection period setup - assert_eq!( - stats - .domain_active_anchor_stats - .unwrap() - .ongoing - .monthly_active_anchors - .len(), - 1 + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_monthly_active_anchors_by_domain{domain=\"identity.ic0.app\"}", + 0f64, ); Ok(()) @@ -485,18 +328,23 @@ fn should_count_activity_on_other_and_ii_domain() -> Result<(), CallError> { let other_origin_device = device_with_origin(Some(OTHER_ORIGIN.to_string())); // ensure stats are initially absent - assert_eq!( - api::stats(&env, canister_id)?.domain_active_anchor_stats, - None - ); + assert!(!get_metrics(&env, canister_id).contains("active_anchors_by_domain")); + // activity not attributed to any II domain --> no stats let anchor_number = flows::register_anchor_with_device(&env, canister_id, &other_origin_device); - // activity not attributed to any II domain --> no stats - assert_eq!( - api::stats(&env, canister_id)?.domain_active_anchor_stats, - None - ); + env.advance_time(Duration::from_secs(DAY_SECONDS)); + + // some activity to update stats + api::get_anchor_info( + &env, + canister_id, + other_origin_device.principal(), + anchor_number, + )?; + + // ensure stats are still absent + assert!(!get_metrics(&env, canister_id).contains("active_anchors_by_domain")); api::add( &env, @@ -514,15 +362,20 @@ fn should_count_activity_on_other_and_ii_domain() -> Result<(), CallError> { anchor_number, )?; - let stats = api::stats(&env, canister_id)? - .domain_active_anchor_stats - .unwrap() - .ongoing - .daily_active_anchors; + env.advance_time(Duration::from_secs(DAY_SECONDS)); - // activity is now attributed to II domain - assert_eq!(stats.ic0_app_counter, 0); - assert_eq!(stats.internetcomputer_org_counter, 1); - assert_eq!(stats.both_ii_domains_counter, 0); + // some activity to update stats + api::get_anchor_info( + &env, + canister_id, + internetcomputer_org_device.principal(), + anchor_number, + )?; + + assert_metric( + &get_metrics(&env, canister_id), + "internet_identity_daily_active_anchors_by_domain{domain=\"identity.internetcomputer.org\"}", + 1f64, + ); Ok(()) }