spec: add subnet_metrics management canister endpoint - #333
Draft
Dfinity-Bjoern wants to merge 2 commits into
Draft
spec: add subnet_metrics management canister endpoint#333Dfinity-Bjoern wants to merge 2 commits into
Dfinity-Bjoern wants to merge 2 commits into
Conversation
Proposal for discussion. Adds a subnet_metrics endpoint returning the subnet block height plus the four subnet-wide metrics that are currently only reachable by external users via the certified state tree path /subnet/<subnet_id>/metrics.
|
🤖 Here's your preview: https://hada6-4yaaa-aaaam-abaha-cai.icp0.io |
- Drop the own-subnet restriction: cross-subnet calls are handled by the existing message routing protocol, so no restriction is needed. - Report the subnet's latest certified height rather than the height of the block containing the call, and rename the field to certified_height. - Keep nat for all fields, since consumed_cycles_total cannot be nat64.
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
Draft for discussion, not ready to merge. Proposes a new EXPERIMENTAL management canister endpoint
subnet_metricsthat returns subnet-wide metrics to canisters.Motivating request: move more dashboard data collection on chain, starting with the subnet block height and the total cycles burned on a subnet.
What already exists
consumed_cycles_totalat/subnet/<subnet_id>/metrics, alongsidenum_canisters,canister_state_bytes, andupdate_transactions_total. But that path is readable only by external users viaread_stateat/api/v2|v3/subnet/<subnet_id>/read_state, and only when the effective subnet id matches. There is no way for a canister to read it, since no System API or management canister method exposes state tree paths to canister code.subnet_inforeturns onlyreplica_versionandregistry_version.update_transactions_totalcounts messages, not blocks. Summingnum_blocks_proposed_totalfromnode_metrics_historyis at best an approximation: counted only since the metric was introduced, sampled at most daily, capped at 60 samples, and documented as resetting to 0 when a node disappears and reappears. The/api/v2/statusendpoint lists block height explicitly as a possible future addition.So the endpoint adds one genuinely new value (the certified height) and makes four existing values reachable from canisters, which is why all five are bundled rather than just the two originally requested.
Proposed interface
Callable by canisters only, replicated calls only,
subnet_idmay be any subnet.Resolved in review
subnet_idto be the caller's own subnet. Removed: cross-subnet calls are carried by the existing message routing protocol, so the request reaches the target subnet and its response comes back without any special handling. The abstract-behavior condition tyingsubnet_idto the caller's subnet is gone too.certified_height, defined as the height of the subnet's latest state for which it produced a certificate. This is the value that is actually verifiable and is well defined for a remote subnet. Note it lags the subnet's latest state, since certification lags execution.natthroughout.nat64was preferred for consistency withnode_metricsand for fixed-width parsing, butconsumed_cycles_totalisu128in the implementation (which is exactly why the state tree splits it into a lownatplus an optional highnatunder CBOR), so it cannot benat64. Rather than mix widths or reproduce the CBOR low/high workaround in a format that has unboundednatnatively, all five fields arenat. This also matchescanister_statusandcanister_metrics, which usenatthroughout.subnet_info. Folding the metrics in as a nestedmetricsfield was considered. Against it: 0.61.0 addedcanister_metricsas a new endpoint rather than extendingcanister_status, which is the same situation; andsubnet_infois not EXPERIMENTAL, so nesting an evolving record inside it means the caveat either leaks onto the whole endpoint or hides in a per-field note. Merging later remains backward compatible if we change our minds; splitting later would not be.Still open
certified_height. The spec requires all nodes executing the call to return the same value, i.e. not a node-local variable. Which agreed-upon value that is, for both the local and the cross-subnet case, needs Consensus to confirm. Marked in the diff.certified_heightis precise and prevents readers from assuming it is the latest finalized block height, which is strictly higher. If the team prefersblock_heightfor continuity with dashboard vocabulary, it is a one-word change.num_canistersandcanister_state_bytesare documented as current values;consumed_cycles_totalandupdate_transactions_totalas counters. The existing state tree description ofcanister_state_bytesinindex.mdsays "since this subnet was created", which reads as a counter and is probably imprecise wording. If so it should be fixed there too. Marked in the diff.Files changed
public/references/ic.did- newsubnet_metrics_args/subnet_metrics_resulttypes and the service method.didc checkpasses.docs/references/ic-interface-spec/management-canister.md- new normativeIC method subnet_metricssection.docs/references/ic-interface-spec/abstract-behavior.md- newIC Management Canister: Subnet Metricssemantics block.docs/references/ic-interface-spec/changelog.md-0.65.0entry. Version and date need confirming at merge time.docs/references/management-canister.md- non-normative reference page entry.No changes needed to the ingress authorization list,
Effective canister id, orEffective subnet id, because the method is not callable via ingress messages.Follow-ups outside this repo
ic-cdkand Motoko management canister bindings./subnet/<subnet_id>/metricsin the state tree as well, so external users get it in certified form without deploying a canister.npm run buildpasses.