Skip to content

feat: allow RPC metrics disable + less locks#7168

Merged
LesnyRumcajs merged 1 commit into
mainfrom
metrics-layer-improvements
Jun 11, 2026
Merged

feat: allow RPC metrics disable + less locks#7168
LesnyRumcajs merged 1 commit into
mainfrom
metrics-layer-improvements

Conversation

@LesnyRumcajs

@LesnyRumcajs LesnyRumcajs commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary of changes

Changes introduced in this pull request:

  • allow disabling RPC metrics
  • made metrics layer less needy, i.e., less locks and allocations, relying more on static data.

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • New Features

    • Added an environment variable to disable per-method JSON-RPC metrics while leaving the metrics endpoint and other metrics active; runtime now honors this setting.
  • Documentation

    • Updated changelog and environment variables reference to document the new setting and how to fully disable metrics.
  • Tests

    • Added tests to validate per-method metrics behavior and the disable flag.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2da9e21a-78cf-4e54-ae85-0b60a6ab6871

📥 Commits

Reviewing files that changed from the base of the PR and between b657e95 and 64cf1d7.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • docs/docs/users/reference/env_variables.md
  • src/daemon/mod.rs
  • src/metrics/mod.rs
  • src/rpc/metrics_layer.rs
  • src/rpc/mod.rs
  • src/tool/offline_server/server.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
✅ Files skipped from review due to trivial changes (3)
  • docs/docs/users/reference/env_variables.md
  • src/daemon/mod.rs
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/tool/offline_server/server.rs
  • src/metrics/mod.rs
  • src/rpc/metrics_layer.rs
  • src/rpc/mod.rs

Walkthrough

Adds a mode-aware RPC metrics layer with a pre-resolved per-method metrics registry and a MetricsMode toggle (honoring FOREST_RPC_METRICS_DISABLED), threads metrics_mode through RPC startup call sites, updates the RPC method label type, and documents the new environment variable.

Changes

RPC Metrics Conditional Control

Layer / File(s) Summary
Metrics Layer with MetricsMode and Pre-Resolved Handles
src/rpc/metrics_layer.rs
Defines MetricsMode, implements MetricsLayer::new(mode) that respects FOREST_RPC_METRICS_DISABLED, builds a static METHOD_METRICS registry of pre-resolved Prometheus Histogram/Counter handles (including aliases and "unknown"), and conditionally wraps call/notification to record metrics when enabled; includes tests.
Metrics Label Type: String to Static Str
src/metrics/mod.rs
Changes RpcMethodLabel.method from String to &'static str to match static registry keys.
RPC Module: MetricsMode Threading
src/rpc/mod.rs
Re-exports MetricsMode, adds metrics_mode: MetricsMode parameter to start_rpc, and constructs per-connection middleware with MetricsLayer::new(metrics_mode); updates test to pass MetricsMode::Enabled.
Configuration Propagation: Daemon and Offline Server
src/daemon/mod.rs, src/tool/offline_server/server.rs
Daemon computes metrics_mode from config.client.enable_metrics_endpoint and passes it to start_rpc; offline server calls start_rpc with MetricsMode::Enabled.
Documentation: Changelog and Environment Variable Reference
CHANGELOG.md, docs/docs/users/reference/env_variables.md
Adds changelog entry and docs table row for FOREST_RPC_METRICS_DISABLED, documenting that it disables per-method JSON-RPC metrics while preserving the metrics endpoint and other metrics; notes --no-metrics disables metrics entirely.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

RPC

Suggested reviewers

  • akaladarshi
  • hanabi1224
  • sudo-shashank
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: allow RPC metrics disable + less locks' directly and clearly summarizes the two main changes: adding RPC metrics disable functionality and optimizing locks/allocations in the metrics layer.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch metrics-layer-improvements
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch metrics-layer-improvements

Comment @coderabbitai help to get the list of available commands and usage tips.

@LesnyRumcajs LesnyRumcajs force-pushed the metrics-layer-improvements branch 2 times, most recently from 66d1cbd to dedcc6c Compare June 11, 2026 12:27
@LesnyRumcajs LesnyRumcajs force-pushed the metrics-layer-improvements branch from dedcc6c to fdc6ff4 Compare June 11, 2026 12:35
@LesnyRumcajs LesnyRumcajs marked this pull request as ready for review June 11, 2026 12:38
@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner June 11, 2026 12:38
@LesnyRumcajs LesnyRumcajs requested review from hanabi1224 and sudo-shashank and removed request for a team June 11, 2026 12:38

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Line 32: Replace the incorrect issue link in the CHANGELOG entry that
currently reads "[`#7168`](https://github.com/ChainSafe/forest/issues/7168)" with
the PR link format "[`#7168`](https://github.com/ChainSafe/forest/pull/7168)" so
the changelog references PR `#7168` instead of an issue; update the single line
containing "Added the `FOREST_RPC_METRICS_DISABLED` environment variable..."
accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 32e8a073-0a00-4c6a-bcac-5ff52ace4831

📥 Commits

Reviewing files that changed from the base of the PR and between be7fba3 and fdc6ff4.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • docs/docs/users/reference/env_variables.md
  • src/daemon/mod.rs
  • src/metrics/mod.rs
  • src/rpc/metrics_layer.rs
  • src/rpc/mod.rs
  • src/tool/offline_server/server.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread CHANGELOG.md Outdated
sudo-shashank
sudo-shashank previously approved these changes Jun 11, 2026
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.20513% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.37%. Comparing base (aff42c3) to head (64cf1d7).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/metrics_layer.rs 79.10% 14 Missing ⚠️
src/daemon/mod.rs 0.00% 2 Missing ⚠️
src/tool/offline_server/server.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/metrics/mod.rs 39.83% <ø> (+7.62%) ⬆️
src/rpc/mod.rs 89.68% <100.00%> (+0.19%) ⬆️
src/tool/offline_server/server.rs 27.23% <0.00%> (ø)
src/daemon/mod.rs 24.81% <0.00%> (-0.08%) ⬇️
src/rpc/metrics_layer.rs 74.72% <79.10%> (+10.01%) ⬆️

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aff42c3...64cf1d7. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2026
@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Jun 11, 2026
Merged via the queue into main with commit 45c8974 Jun 11, 2026
43 checks passed
@LesnyRumcajs LesnyRumcajs deleted the metrics-layer-improvements branch June 11, 2026 13:37
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