Skip to content

fix(vm-runner): report compilation and cache metrics from all code paths#15580

Merged
ssavenko-near merged 2 commits into
masterfrom
slavas/crt-fix-metrics
Apr 15, 2026
Merged

fix(vm-runner): report compilation and cache metrics from all code paths#15580
ssavenko-near merged 2 commits into
masterfrom
slavas/crt-fix-metrics

Conversation

@ssavenko-near

Copy link
Copy Markdown
Contributor

report_metrics(), which flushes vm-runner's thread-local metric accumulators to Prometheus, was only called on the function-call path. Compilation triggered by contract deployment, global contract distribution, or pipelining accumulated into thread-locals but never flushed — the data was silently lost.

Add report_metrics()`` calls at each of these call sites, where the shard context is available, so the existing near_vm_runner_compilation_seconds histogram and cache counters capture all compilations with proper shard_id and caller context labels. The simpler approach to observe directly in the compile_uncached()` would loose the "shard_id" information.

Also add near_vm_compiled_contract_memory_cache_hits_total to distinguish in-memory cache hits from disk hits. Disk hit rate can be derived as (total_hits - memory_hits) / (total_lookups - memory_hits).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ensures VM-runner compilation and cache metrics are flushed to Prometheus from all compilation-triggering code paths (not only function calls), preserving shard_id and caller-context labeling. It also adds a dedicated counter to distinguish in-memory compiled-contract cache hits from disk cache hits.

Changes:

  • Plumb a preformatted shard_id into ReceiptPreparationPipeline and flush metrics from pipelining worker + main-thread fallback paths.
  • Flush VM-runner metrics after contract compilation triggered by deploys (including implicit account wallet precompile) and global contract distribution.
  • Add near_vm_compiled_contract_memory_cache_hits_total and record memory-cache hits in both NearVM and Wasmtime runners.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
runtime/runtime/src/state_viewer/mod.rs Passes shard id into the receipt preparation pipeline so pipelining metric flushes have correct labels in view execution.
runtime/runtime/src/pipelining.rs Adds shard id to the pipeline and flushes VM-runner thread-local metrics on both worker and main-thread preparation paths.
runtime/runtime/src/lib.rs Flushes metrics after DeployContract compilation; passes shard id into pipelining pipeline creation sites.
runtime/runtime/src/global_contracts.rs Flushes metrics after global-contract distribution precompilation.
runtime/runtime/src/actions.rs Flushes metrics after ETH-implicit wallet precompilation (deploy-like path).
runtime/near-vm-runner/src/wasmtime_runner/mod.rs Records overall cache hit vs memory hit for compiled-contract lookups.
runtime/near-vm-runner/src/near_vm_runner/runner.rs Records overall cache hit vs memory hit for compiled-contract lookups.
runtime/near-vm-runner/src/metrics.rs Adds memory-cache-hit counter + thread-local accumulation and flush logic in report_metrics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runtime/runtime/src/pipelining.rs
@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.68966% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.29%. Comparing base (99bbe5d) to head (fb84c4d).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
runtime/near-vm-runner/src/metrics.rs 46.66% 12 Missing and 4 partials ⚠️
runtime/runtime/src/lib.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15580      +/-   ##
==========================================
+ Coverage   69.27%   69.29%   +0.02%     
==========================================
  Files         940      940              
  Lines      212069   212113      +44     
  Branches   212069   212113      +44     
==========================================
+ Hits       146902   146990      +88     
+ Misses      59329    59295      -34     
+ Partials     5838     5828      -10     
Flag Coverage Δ
pytests-nightly 1.14% <0.00%> (-0.01%) ⬇️
unittests 68.66% <70.68%> (+0.03%) ⬆️
unittests-nightly 68.84% <70.68%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ssavenko-near ssavenko-near force-pushed the slavas/crt-fix-metrics branch from 34be431 to 931e0ee Compare April 15, 2026 09:55
…aths

`report_metrics()`, which flushes vm-runner's thread-local metric accumulators to Prometheus, was only called on the function-call path.
Compilation triggered by contract deployment, global contract distribution, or pipelining accumulated into thread-locals but never flushed — the data was silently lost.

Add `report_metrics()`` calls at each of these call sites, where the shard context is available, so the existing near_vm_runner_compilation_seconds histogram and cache counters capture all compilations with proper shard_id and caller context labels. The simpler approach to observe directly in the `compile_uncached()` would loose the "shard_id" information.

Also add near_vm_compiled_contract_memory_cache_hits_total to distinguish in-memory cache hits from disk hits.
Disk hit rate can be derived as (total_hits - memory_hits) / (total_lookups - memory_hits).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runtime/near-vm-runner/src/metrics.rs
@ssavenko-near ssavenko-near marked this pull request as ready for review April 15, 2026 10:37
@ssavenko-near ssavenko-near requested a review from a team as a code owner April 15, 2026 10:37
@ssavenko-near ssavenko-near requested a review from darioush April 15, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@darioush darioush left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine. Only non-blocking concern is that we have to be careful to add the call to metrics whenever we make a new call to compiling contracts.

@ssavenko-near ssavenko-near added this pull request to the merge queue Apr 15, 2026
@ssavenko-near ssavenko-near removed this pull request from the merge queue due to a manual request Apr 15, 2026
@ssavenko-near

Copy link
Copy Markdown
Contributor Author

Only non-blocking concern is that we have to be careful to add the call to metrics whenever we make a new call to compiling contracts.

Yes. That bothers me as well. I did not find an acceptable way to handle this. But since I do not call reset_metric() anymore worst thing that can happen is wrong attribution, not dropping the data point.

@ssavenko-near ssavenko-near added this pull request to the merge queue Apr 15, 2026
@darioush

Copy link
Copy Markdown
Contributor

@ssavenko-near BTW, please make changelog entry for metrics changes. Thanks.

Merged via the queue into master with commit 0f0cd2a Apr 15, 2026
29 of 32 checks passed
@ssavenko-near ssavenko-near deleted the slavas/crt-fix-metrics branch April 15, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants