Skip to content

feat: Metrics for requested ledger age#2947

Open
kuznetsss wants to merge 11 commits intoXRPLF:developfrom
kuznetsss:Add_age_metric
Open

feat: Metrics for requested ledger age#2947
kuznetsss wants to merge 11 commits intoXRPLF:developfrom
kuznetsss:Add_age_metric

Conversation

@kuznetsss
Copy link
Collaborator

@kuznetsss kuznetsss commented Feb 13, 2026

Adding metrics to be able to analyse requested ledger age distribution.

kuznetsss and others added 3 commits February 13, 2026 14:19
Add prometheus metrics to track ledger request patterns:
- rpc_ledger_requests_total: Counter with labels for current/validated/specific
- rpc_ledger_age_seconds: Histogram for ledger age in seconds (approximate)
- rpc_ledger_age_ledgers: Histogram for ledger age in ledger count

This enables analysis of how often users request old ledgers.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Add recordLedgerMetrics call after successful RPC request completion
to track ledger request patterns. This is called in both old and new
RPCServerHandler implementations.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Add comprehensive tests for the new ledger metrics:
- Test current ledger requests
- Test validated ledger requests (both explicit and default)
- Test specific ledger number requests (numeric and string)
- Test ledger hash requests
- Test zero age (same as current ledger)

Also update MockRPCEngine to include recordLedgerMetrics method.

All 18 RPC counter tests passing.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Copy link
Collaborator

@godexsoft godexsoft left a comment

Choose a reason for hiding this comment

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

Looks pretty useful overall!

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 78.78788% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.01%. Comparing base (584d2bb) to head (cd5b36f).

Files with missing lines Patch % Lines
src/rpc/RPCEngine.hpp 0.00% 5 Missing ⚠️
src/rpc/Counters.cpp 92.30% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2947   +/-   ##
========================================
  Coverage    82.00%   82.01%           
========================================
  Files          391      391           
  Lines        14689    14717   +28     
  Branches      8037     8054   +17     
========================================
+ Hits         12046    12070   +24     
- Misses        1459     1461    +2     
- Partials      1184     1186    +2     

☔ 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.

@kuznetsss kuznetsss marked this pull request as ready for review February 16, 2026 16:17
@kuznetsss kuznetsss requested a review from godexsoft February 16, 2026 16:17
godexsoft
godexsoft previously approved these changes Feb 16, 2026
Copy link
Collaborator

@godexsoft godexsoft left a comment

Choose a reason for hiding this comment

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

👍 :rage1:

@kuznetsss kuznetsss force-pushed the Add_age_metric branch 2 times, most recently from 3992999 to 4e8d3c1 Compare February 17, 2026 15:13
…tests

The previous ledger metrics implementation added calls to recordLedgerMetrics
in the RPC server handlers, but the NgRpcServerHandler tests were missing
mock expectations for these calls. This caused 6 tests to fail with
'Uninteresting mock function call' errors.

This commit adds EXPECT_CALL expectations for recordLedgerMetrics in all
successful request test cases where the metrics are recorded.
- Remove ledgerAgeSecondsHistogram metric (not needed, only track by ledger count)
- Move recordLedgerMetrics call into notifyComplete(Context) overload
- Keep early return for ledger_hash requests (can't determine age)
- Update all tests to match new implementation
Copy link
Collaborator

@godexsoft godexsoft left a comment

Choose a reason for hiding this comment

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

I found one more potential thing to fix but i don't have a solution for it.

void
Counters::recordLedgerRequest(boost::json::object const& params, std::uint32_t currentLedgerSequence)
{
if (not params.contains("ledger_index")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is also "ledger_hash" that can be used to refer to the same ledger.. not sure how to deal with it though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think there is an easy way to get ledger index by hash and querying DB or rippled for that is probably too heavy operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a counter for requests with ledger_hash.

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.

2 participants

Comments