Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add chunk application stats (near#12797)
This is the first step towards per-chunk metrics (near#12758). This PR adds a new struct - `ChunkApplyStats` - which keeps information about things that happened during chunk application. For example how many transactions there were, how many receipts, what were the outgoing limits, how many receipts were forwarded, buffered, etc, etc. For now `ChunkApplyStats` contain mainly data relevant to the bandwidth scheduler, in the future more stats can be added to measure other things that we're interested in. I didn't want to add too much stuff at once to keep the PR size reasonable. There was already a struct called `ApplyStats`, but it was used only for the balance checker. I replaced it with `BalanceStats` inside `ChunkApplyStats`. `ChunkApplyStats` are returned in `ApplyChunkResult` and saved to the database for later use. A new database column is added to keep the chunk application stats. The column is included in the standard garbage collection logic to keep the size of saved data reasonable. Running `neard view-state chunk-apply-stats` allows node operator to view chunk application stats for a given chunk. Example output for a mainnet chunk: <details> <summary> Click to expand </summary> ```rust $ ./neard view-state chunk-apply-stats --block-hash GKzyP7DVNw5ctUcBhRRkABMaC2giNSKK5oHCrRc9hnXH --shard-id 0 ... V0( ChunkApplyStatsV0 { height: 138121896, shard_id: 0, is_chunk_missing: false, transactions_num: 35, incoming_receipts_num: 103, receipt_sink: ReceiptSinkStats { outgoing_limits: { 0: OutgoingLimitStats { size: 102400, gas: 18446744073709551615, }, 1: OutgoingLimitStats { size: 4718592, gas: 300000000000000000, }, 2: OutgoingLimitStats { size: 102400, gas: 300000000000000000, }, 3: OutgoingLimitStats { size: 102400, gas: 300000000000000000, }, 4: OutgoingLimitStats { size: 102400, gas: 300000000000000000, }, 5: OutgoingLimitStats { size: 102400, gas: 300000000000000000, }, }, forwarded_receipts: { 0: ReceiptsStats { num: 24, total_size: 6801, total_gas: 515985143008901, }, 2: ReceiptsStats { num: 21, total_size: 6962, total_gas: 639171080456467, }, 3: ReceiptsStats { num: 58, total_size: 17843, total_gas: 1213382619794847, }, 4: ReceiptsStats { num: 20, total_size: 6278, total_gas: 235098003759589, }, 5: ReceiptsStats { num: 4, total_size: 2089, total_gas: 245101556851946, }, }, buffered_receipts: {}, final_outgoing_buffers: { 0: ReceiptsStats { num: 0, total_size: 0, total_gas: 0, }, 2: ReceiptsStats { num: 0, total_size: 0, total_gas: 0, }, 3: ReceiptsStats { num: 0, total_size: 0, total_gas: 0, }, 4: ReceiptsStats { num: 0, total_size: 0, total_gas: 0, }, 5: ReceiptsStats { num: 0, total_size: 0, total_gas: 0, }, }, is_outgoing_metadata_ready: { 0: false, 2: false, 3: false, 4: false, 5: false, }, all_outgoing_metadatas_ready: false, }, bandwidth_scheduler: BandwidthSchedulerStats { params: None, prev_bandwidth_requests: {}, prev_bandwidth_requests_num: 0, time_to_run_ms: 0, granted_bandwidth: {}, new_bandwidth_requests: {}, }, balance: BalanceStats { tx_burnt_amount: 4115983319195000000000, slashed_burnt_amount: 0, other_burnt_amount: 0, gas_deficit_amount: 0, }, }, ) ``` </details> The stats are also available in `ChainStore`, making it easy to read them from tests. In the future we could also add an RPC endpoint to make the stats available in `debug-ui`. The PR is divided into commits for easier review.
- Loading branch information