chore: migrate motoko/query_stats to icp-cli - #1364
Merged
Merged
Conversation
Replace dfx.json with icp.yaml, update mops.toml to current toolchain
versions (moc 1.9.0, core 2.5.0, ic 4.0.0), replace inline management
canister actor type with `import { ic } "mo:ic"`, move source to
backend/app.mo, add Makefile with numbered tests, CI workflow, and
updated README.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…local replica Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…cted locally Query stats require 120+ blocks to aggregate on local PocketIC (2 epochs × 60 blocks). Values are always 0 locally — this is correct IC behavior, not a bug. Non-zero values appear on IC mainnet after enough queries accumulate. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
icp canister call makes UPDATE calls by default. UPDATE calls to query functions are NOT counted in query_stats.num_calls_total — only actual QUERY calls are tracked. Adding --query ensures the calls are recorded. The 2-epoch aggregation delay (120 blocks × 100ms ≈ 12s) still means the first run shows 0; the second run shows non-zero values from run 1. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- make test: fast structural check (CI), stats show 0 due to lag - make test-stats: generates load, waits ~20s for 2-epoch aggregation, verifies non-zero values — the full end-to-end demonstration - Use --query flag on load() calls (update calls not counted in query_stats) - README: document both targets, explain timing (2 epochs × 60 blocks × 100ms) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
marc0olo
marked this pull request as ready for review
June 11, 2026 16:54
Fixed sleep of 20s fails on loaded machines where each PocketIC block takes 150-200ms (120 blocks × 200ms = 24s exceeds the sleep). Poll every 3s up to 60s and report how long aggregation actually took. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PocketIC simulates a 13-node subnet. It distributes stats with integer division (num_calls /= 13) before aggregation. With fewer than 13 calls, every node reports 0 and stats are always 0 regardless of wait time. Also: print final result on failure for easier debugging. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
set_epoch_from_height is only called during query execution (query_context.rs). Sleeping without making queries means epoch transitions never trigger a stats flush to the channel. Fix: poll every 3s with 13 --query calls per round so stats are flushed when an epoch boundary is crossed during the loop. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
raymondk
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates
motoko/query_statsfrom dfx to icp-cli.dfx.jsonwithicp.yaml(@dfinity/motoko@v5.0.0)src/query_stats_backend/main.mo→backend/app.mo; rename actor toQueryStatsactor "aaaaa-aa"withimport { ic } "mo:ic"(mo:ic 4.0.0); addNatimportmops.toml: moc 1.9.0, core 2.5.0, ic 4.0.0,--default-persistent-actorsicp.yaml, CI workflow (icp-dev-env-motoko:0.3.2)Makefiletargets:make test— fast structural check (CI); verifies all four stat field names are present; stats show 0 due to aggregation delaymake test-stats— full demonstration; polls every 3s with 13--querycalls per round until non-zero stats appear (up to 30s)How query stats work locally (non-obvious)
Three requirements for stats to appear on a local PocketIC replica:
--query—icp canister callmakes update calls by default; only query calls are tracked inquery_statsnum_calls / 13); fewer than 13 calls round to zeroset_epoch_from_heightis only invoked during query execution; queries must keep running so epoch transitions flush accumulated stats into the payload pipeline (sleeping without queries leaves stats unflushed regardless of how long you wait)Test plan
motoko-query_statsCI passes (make test)make test-statsshows non-zeroNumber of callswithin 30s🤖 Generated with Claude Code