Skip to content

feat: Export million_round_instructions_total in subnet_metrics - #11587

Merged
schneiderstefan merged 4 commits into
masterfrom
stschnei/cycle-metrics
Sep 16, 2026
Merged

schneiderstefan merged 4 commits into
masterfrom
stschnei/cycle-metrics

Conversation

@schneiderstefan

Copy link
Copy Markdown
Contributor

This commit adds an addition field returned with the subnet_metrics management canister endpoint. It tracks the existing prometheus metric execution_round_instructions, except that it does not get reset on replica start.

One user of the existing metric and the new value are the public dashboards, with the off-chain dashboard currently relying on the prometheus metric.

The new value starts at 0 with the introduction of this commit. Like the metric, the new field counts the executed wasm instructions, plus instruction overheads the scheduler uses (e.g. there is a base overhead per message).

While the instructions are tracked exactly internally, they are only exported in millions of instructions.

As a drive-by, this commit also fixes an issue where the metric/new total was not correctly tracked in the edge case of heap delta rate limiting kicking in.

This commit adds an addition field returned with the subnet_metrics
management canister endpoint. It tracks the existing prometheus metric
execution_round_instructions, except that it does not get reset on
replica start.

One user of the existing metric and the new value are the public
dashboards, with the off-chain dashboard currently relying on the
prometheus metric.

The new value starts at 0 with the introduction of this commit. Like the
metric, the new field counts the executed wasm instructions, plus
instruction overheads the scheduler uses (e.g. there is a base overhead
per message).

While the instructions are tracked exactly internally, they are only
exported in millions of instructions.

As a drive-by, this commit also fixes an issue where the metric/new
total was not correctly tracked in the edge case of heap delta rate
limiting kicking in.
@github-actions github-actions Bot added the feat label Sep 16, 2026
@schneiderstefan

Copy link
Copy Markdown
Contributor Author

Intended follow-up once this is rolled out: #11586

@zeropath-ai

zeropath-ai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to c6df79f.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/execution_environment/src/execution_environment.rs
    Reporting new million_round_instructions_total in subnet metrics computation and mapping from metrics.round_instructions_total (div_ceil)
Enhancement ► rs/execution_environment/src/metrics.rs
    Add instructions() accessor to MeasurementScope
Enhancement ► rs/execution_environment/src/scheduler.rs
    Introduce accumulate_round_subnet_metrics to aggregate round metrics; update round_subnet metrics accumulation on exits
Enhancement ► rs/execution_environment/src/scheduler/tests/rate_limiting.rs
    Add test ensuring drained consensus queue messages are counted toward update_transactions_total and that round instructions are tracked across rounds
Enhancement ► rs/execution_environment/tests/execution_test.rs
    Update subnet metrics test to account for round_instructions_total and its relation to million rounding behavior
Enhancement ► rs/protobuf/def/state/metadata/v1/metadata.proto
    Add round_instructions_total field to SubnetMetrics (tag 13)
Enhancement ► rs/protobuf/src/gen/state/state.metadata.v1.rs
    Include optional round_instructions_total field in SubnetMetrics struct
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Add round_instructions_total field to SubnetMetrics
Enhancement ► rs/replicated_state/src/metadata_state/proto.rs
    Serialize/deserialize round_instructions_total in SubnetMetrics
Enhancement ► rs/replicated_state/src/metadata_state/tests.rs
    Test decoding of zero when round_instructions_total field absent
Enhancement ► rs/state_manager/src/manifest/split/tests.rs
    Update expected size/hash for SYSTEM_METADATA_FILE and related entries due to new round_instructions_total field
Enhancement ► rs/state_manager/tests/state_manager.rs
    New test: round_instructions_total_survives_a_checkpoint
Enhancement ► rs/test_utilities/state/src/lib.rs
    Propagate round_instructions_total in SubnetMetrics generation for tests
Enhancement ► rs/types/management_canister_types/src/lib.rs
    Update SubnetMetricsArgs/docs to include million_round_instructions_total
Enhancement ► rs/types/management_canister_types/tests/ic.did
    Update DID interface to document million_round_instructions_total field

@schneiderstefan
schneiderstefan added this pull request to the merge queue Sep 16, 2026
Merged via the queue into master with commit 2788b2b Sep 16, 2026
40 checks passed
@schneiderstefan
schneiderstefan deleted the stschnei/cycle-metrics branch September 16, 2026 16:09
mraszyk added a commit to dfinity/developer-docs that referenced this pull request Sep 17, 2026
Documents dfinity/ic#11587, which adds a sixth field to the endpoint this
branch specifies. It reports the total instructions the subnet accounted for
across the execution phases of all rounds, in units of one million and rounded
up, and unlike the four aggregates it has no path under
`/subnet/<subnet_id>/metrics` in the certified state tree.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
mraszyk added a commit to dfinity/developer-docs that referenced this pull request Oct 7, 2026
## Summary

Specifies the EXPERIMENTAL management canister endpoint
`subnet_metrics`, which returns subnet-wide metrics to canisters: the
subnet block height, the four aggregates the certified state tree
already exposes at `/subnet/<subnet_id>/metrics`, and the total number
of instructions the subnet accounted for when executing its blocks.

The block height is new; the four aggregates exist in the state tree but
are unreachable from canister code, since no System API or management
canister method exposes state tree paths. That is why they are bundled
rather than only the block height and `consumed_cycles_total` originally
requested.

Covers two replica PRs:

- dfinity/ic#11032 - the endpoint and its first five fields.
- dfinity/ic#11587 - the sixth field `million_round_instructions_total`.

## Changes

- `ic-interface-spec/management-canister.md`: new section for
`subnet_metrics` with the full field semantics.
- `ic-interface-spec/abstract-behavior.md`: new transition for
`subnet_metrics`; the metric values are implementation-specific and
attached cycles are refunded.
- `ic-interface-spec/index.md`: new definitions of *cost schedules*
(normal and free; a free schedule waives resource charges only, such as
instruction execution, memory usage, and HTTPS outcalls, while cycles
burned via `ic0.cycles_burn128`, deleted canisters' remaining cycle
balances, and the cycles of dropped messages or refunds are still lost)
and *nominal cycles* (the normal-schedule amount for resource charges,
and the amount lost for cycles that are lost under either schedule), and
corrected descriptions of the four aggregates under
`/subnet/<subnet_id>/metrics` (current values vs. counters, the 10-block
refresh of `canister_state_bytes`, the full composition of
`consumed_cycles_total`, as a list of its four summands), so the state
tree and the method describe the same quantities.
- `ic-interface-spec/changelog.md`: version 0.69.0 entry covering the
new endpoint, the new definitions, and the clarified state tree metrics
(still the next version after merging the latest `main`, whose newest
entry is 0.68.0).
- `references/management-canister.md`: condensed reference entry linking
to the spec.
- `public/references/ic.did`: new types and method, with field comments.

## Interface

```candid
type subnet_metrics_args = record { subnet_id : principal };

type subnet_metrics_result = record {
    block_height : nat;
    num_canisters : nat;
    canister_state_bytes : nat;
    consumed_cycles_total : nat;
    update_transactions_total : nat;
    million_round_instructions_total : nat;
};
```

Callable by canisters only (not via ingress), and `subnet_id` may name
any subnet, not only the caller's.

## Field semantics

- Only `block_height` describes the block in whose execution the call is
processed. The other five are aggregates refreshed at block boundaries,
so they describe an earlier block; they are not refreshed at the same
rate, so they need not be mutually consistent.
- `num_canisters` and `canister_state_bytes` are current values, not
counters. `canister_state_bytes` refreshes only every 10 blocks, at
heights that are multiples of 10. It reads 0 before the first refresh.
- `consumed_cycles_total` is measured in *nominal cycles*: resource
charges are recorded at normal cost-schedule rates even on a subnet with
a free cost schedule, where no cycles are deducted from canister
balances. It sums the historical consumption of the canisters currently
on the subnet, the historical consumption of the canisters deleted on
the subnet plus their remaining cycle balances at deletion, the cycles
charged at the subnet level for HTTPS outcalls, threshold signature
requests, and vetKD requests, and the cycles lost when messages or
refunds are dropped (for example, because their recipient no longer
exists). Refunds of prepaid charges reduce the total. Subnet splitting
redistributes canisters' histories, so the total can decrease and can
include consumption from before the receiving subnet was created. It is
not a count of cycles actually burned on this subnet.
- `update_transactions_total` counts messages executed in replicated
mode. It and `million_round_instructions_total` are monotonically
non-decreasing counters covering the subnet's lifetime, or the period
since each metric was introduced for subnets that predate it.
- `million_round_instructions_total` is reported in units of one million
and rounded up: a value of `42` represents 41,000,001 through 42,000,000
instructions. It counts the instructions accounted for when executing
the subnet's blocks. Besides the executed Wasm instructions, it covers
the fixed per-execution and per-canister overheads charged by the
scheduler and the charges for work performed outside of Wasm execution
(compilation, chunk assembly, snapshots), so it is not a Wasm
instruction meter.
- `block_height` and `million_round_instructions_total` are the two
fields with no path under `/subnet/<subnet_id>/metrics`, so they are
available only through this method and cannot be verified against a
certificate.

## Follow-ups outside this repo

- `ic-cdk` and Motoko management canister bindings.
- dfinity/ic: the `million_round_instructions_total` comment in
`rs/types/management_canister_types/tests/ic.did` says "Unlike the four
fields above", but five fields precede it and `block_height` also has no
state tree path.

---------

Co-authored-by: Bjoern Tackmann <[email protected]>
Co-authored-by: mraszyk <[email protected]>
Co-authored-by: Martin Raszyk <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants