feat: Metrics for requested ledger age#2947
feat: Metrics for requested ledger age#2947kuznetsss wants to merge 11 commits intoXRPLF:developfrom
Conversation
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]>
godexsoft
left a comment
There was a problem hiding this comment.
Looks pretty useful overall!
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
80f64d7 to
344b1d4
Compare
3992999 to
4e8d3c1
Compare
…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
4e8d3c1 to
bfb6379
Compare
bfb6379 to
57be9d0
Compare
godexsoft
left a comment
There was a problem hiding this comment.
I found one more potential thing to fix but i don't have a solution for it.
src/rpc/Counters.cpp
Outdated
| void | ||
| Counters::recordLedgerRequest(boost::json::object const& params, std::uint32_t currentLedgerSequence) | ||
| { | ||
| if (not params.contains("ledger_index")) { |
There was a problem hiding this comment.
There is also "ledger_hash" that can be used to refer to the same ledger.. not sure how to deal with it though.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added a counter for requests with ledger_hash.
Adding metrics to be able to analyse requested ledger age distribution.