Repository navigation
feat: use the monotonic consumed cycles by use case in metrics, deletion and install_code - #11776
Merged
Merged
Conversation
…ion and install_code Switch the remaining readers of the `CanisterMetrics::consumed_cycles_by_use_cases` gauges to `consumed_cycles_by_use_cases_monotonic`: - the per-use-case consumed cycles gauge exported by `ReplicatedStateMetrics`; - the per-use-case consumption folded into `SubnetMetrics` on canister deletion; - the burned cycles delta computed when finishing `install_code`. The monotonic map has an `HTTPOutcalls` entry, which the gauges lack because HTTPS outcalls are recorded at the subnet level. It is skipped in the first two places so that HTTPS outcalls are not double counted. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Existing scheduler metric tests will fail under the new prepayment semantics, and HTTPS deletion needs regression coverage.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Switches remaining production consumers to monotonic per-use-case cycle accounting.
Changes:
- Exports monotonic canister cycle metrics, excluding HTTPS outcalls.
- Preserves monotonic accounting during canister deletion.
- Uses monotonic burned-cycle totals during
install_code.
| File | Description |
|---|---|
rs/replicated_state/src/metrics.rs |
Uses monotonic values for Prometheus totals. |
rs/execution_environment/src/canister_manager.rs |
Transfers monotonic values on deletion. |
rs/execution_environment/src/execution/install_code.rs |
Calculates burned-cycle deltas monotonically. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…cs tests The per-use-case consumed cycles gauge and the deleted canisters accounting now read the monotonic amounts, which only count an instructions prepayment once its refund is known. Settle the prepayment with a zero refund, as finishing the execution would. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Regression test for skipping the `HTTPOutcalls` entry of the canister's monotonic consumed cycles when folding them into `SubnetMetrics` on deletion: the subnet-level entries, the consumed cycles total and the exported metrics must count the outcall only once. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
✅ No security or compliance issues detected. Reviewed everything up to d0d7f52. Security Overview
Detected Code Changes
|
eichhorl
approved these changes
Oct 7, 2026
…cles-monotonic-use-sites
- Feed the same per-use-case totals to both the consumed cycles gauge and counter instead of building an identical second map. - Observe the metrics once while the instruction prepayment is still outstanding, so the test fails if the metrics read the gauges again. - Drop the redundant subnet map assertion from the HTTPS outcalls deletion test and build its labels with `labels`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 11, 2026
…#11782) On canister deletion, `CanisterManager::delete_canister` now adds the canister's `CanisterMetrics::consumed_cycles_monotonic` (instead of the `consumed_cycles` gauge) to `SubnetMetrics::consumed_cycles_by_deleted_canisters`. This matches the per-use-case consumption, which is already taken from the monotonic map (dfinity#11776). The monotonic total has been backfilled for all canisters (dfinity#11490). A stopped canister has no outstanding prepayments, so its gauge equals its monotonic counterpart. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.


Switches the remaining production readers of the
CanisterMetrics::consumed_cycles_by_use_casesgauges toconsumed_cycles_by_use_cases_monotonic:rs/replicated_state/src/metrics.rs: the canister part of the per-use-case consumed cycles gauge exported to Prometheus now comes from the monotonic map, withHTTPOutcallsremoved, just like the counter's. The gauge (replicated_state_consumed_cycles_from_replica_start) and the counter (..._as_counters) are therefore built from exactly the same inputs, soobserve()builds a single per-use-case map and feeds it to both, instead of building an identical second map over every canister after each round.rs/execution_environment/src/canister_manager.rs: on canister deletion, the canister's per-use-case consumption is moved intoSubnetMetricsfrom the monotonic map.rs/execution_environment/src/execution/install_code.rs: the burned cycles delta infinishreadsBurnedCyclesfrom the monotonic map. Burned cycles are charged directly without a prepayment, so both maps move together and the balancedebug_assertis unaffected.The monotonic map has an
HTTPOutcallsentry, which the gauge map lacks because HTTPS outcalls are recorded at the subnet level when they are charged. The metrics and deletion paths skip it. Without the skip, deletion would double count outcall cycles in the subnet-levelHTTPOutcallsentry, and through it inSubnetMetrics::consumed_cycles_total(). That subnet-level part goes into the certified/subnet/<subnet_id>/metricstotal from V29 on (consumed_cycles_total_including_canisters) and also into the V30 total (consumed_cycles_total_including_canisters_monotonic, #11777).For the other use cases, the deletion path should behave as before once the monotonic amounts have been backfilled (which is the case in production by now). A stopped canister has no outstanding prepayments, so its gauges equal their monotonic counterparts.
Tests:
http_outcalls_consumed_cycles_are_not_double_counted_on_canister_deletion: deleting a canister that made an HTTPS outcall leaves the subnet-levelHTTPOutcallsentry, the subnet total (beyond the leftover balance), and the exported gauge and counter unchanged. It fails without the skip (subnetHTTPOutcallsentry 2,000,000 instead of 1,000,000).consumed_cycles_for_instructions_are_updated_from_valid_canistersfirst observes the metrics while the instruction prepayment is outstanding and expects0.0(it fails with1000.0ifmetrics.rsreads the gauges again), then settles the prepayment with a zero refund, as finishing an execution would, and expects the full amount.consumed_cycles_are_updated_from_deleted_canisterssettles the prepayment the same way before deleting the canister, so the cycles count as consumed in the monotonic map.🤖 Generated with Claude Code