feat: add RPC specific metrics #562
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A few metrics which might reveal interesting insights into how the validator is used
Greptile Overview
Updated On: 2025-10-04 18:19:28 UTC
Summary
This PR implements a significant refactoring of the metrics system to focus on RPC-specific observability. The changes shift away from granular transaction and account-level metrics toward higher-level RPC performance monitoring.Key changes include:
New RPC-focused metrics - Added comprehensive RPC request tracking including:
RPC_REQUESTS_COUNTfor counting HTTP and WebSocket requests by methodRPC_REQUEST_HANDLING_TIMEfor measuring HTTP request durationRPC_WS_SUBSCRIPTIONS_COUNTfor tracking active WebSocket subscriptionsTRANSACTION_PROCESSING_TIMEandTRANSACTION_SKIP_PREFLIGHTfor transaction-related insightsENSURE_ACCOUNTS_TIMEfor monitoring account fetching performanceFAILED_TRANSACTIONS_COUNTfor tracking processing failuresInfrastructure additions - Added the
magicblock-metricsdependency to bothmagicblock-apertureandmagicblock-processorpackages to enable metrics collection across RPC-handling components.String conversion support - Extended RPC method enums with
as_str()methods to provide static string representations for metrics labeling, enabling categorization by method type.WebSocket subscription tracking - Implemented a sophisticated RAII guard pattern (
SubMetricGuard) to accurately track active subscription counts across all subscription types (account, program, logs, slot).Metrics removal and cleanup - Removed several existing metrics including transaction execution timing histograms, account clone/commit counters, and signature verification metrics. Also removed various helper functions and cleaned up unused parameters.
The changes integrate throughout the RPC request handling pipeline, from the dispatch layer down to individual request handlers, providing comprehensive visibility into how the validator's RPC interface is being utilized. The timing metrics use proper RAII patterns to ensure accurate measurement, while counters track both successful operations and error conditions.
Important Files Changed
Changed Files
Confidence score: 3/5
Sequence Diagram
sequenceDiagram participant User participant HttpDispatcher as "HTTP Dispatcher" participant Metrics as "Metrics System" participant ChainLink as "ChainLink" participant AccountsDb as "Accounts DB" participant TransactionScheduler as "Transaction Scheduler" participant TransactionExecutor as "Transaction Executor" participant Ledger participant WebSocketDispatcher as "WebSocket Dispatcher" participant SubscriptionsDb as "Subscriptions DB" User->>HttpDispatcher: "HTTP RPC Request" HttpDispatcher->>Metrics: "Increment RPC_REQUESTS_COUNT" HttpDispatcher->>Metrics: "Start RPC_REQUEST_HANDLING_TIME timer" alt Account Info Request HttpDispatcher->>Metrics: "Start ENSURE_ACCOUNTS_TIME timer (account)" HttpDispatcher->>ChainLink: "ensure_accounts([pubkey])" ChainLink-->>HttpDispatcher: "Account ensured" HttpDispatcher->>AccountsDb: "get_account(pubkey)" AccountsDb-->>HttpDispatcher: "Account data" HttpDispatcher->>Metrics: "Stop timer" else Send Transaction HttpDispatcher->>Metrics: "Start TRANSACTION_PROCESSING_TIME timer" HttpDispatcher->>Metrics: "Start ENSURE_ACCOUNTS_TIME timer (transaction)" HttpDispatcher->>ChainLink: "ensure_transaction_accounts(transaction)" ChainLink-->>HttpDispatcher: "Accounts ensured" alt Skip Preflight HttpDispatcher->>Metrics: "Increment TRANSACTION_SKIP_PREFLIGHT" HttpDispatcher->>TransactionScheduler: "schedule(transaction)" else With Preflight HttpDispatcher->>TransactionScheduler: "execute(transaction)" TransactionScheduler->>TransactionExecutor: "Process transaction" TransactionExecutor->>TransactionExecutor: "SVM execution" alt Transaction Failed TransactionExecutor->>Metrics: "Increment FAILED_TRANSACTIONS_COUNT" TransactionExecutor->>Ledger: "Write failed transaction" else Transaction Succeeded TransactionExecutor->>AccountsDb: "Update accounts" TransactionExecutor->>Ledger: "Write transaction" end TransactionExecutor-->>TransactionScheduler: "Execution result" TransactionScheduler-->>HttpDispatcher: "Transaction result" end HttpDispatcher->>Metrics: "Stop timers" end HttpDispatcher->>Metrics: "Stop RPC_REQUEST_HANDLING_TIME timer" HttpDispatcher-->>User: "JSON-RPC Response" User->>WebSocketDispatcher: "WebSocket Subscription" WebSocketDispatcher->>Metrics: "Increment RPC_REQUESTS_COUNT" alt Account Subscribe WebSocketDispatcher->>SubscriptionsDb: "subscribe_to_account()" SubscriptionsDb->>Metrics: "Increment RPC_WS_SUBSCRIPTIONS_COUNT (account)" SubscriptionsDb-->>WebSocketDispatcher: "Subscription handle" Note over SubscriptionsDb: "Account update occurs" SubscriptionsDb->>WebSocketDispatcher: "Account update notification" WebSocketDispatcher-->>User: "WebSocket notification" else Signature Subscribe WebSocketDispatcher->>SubscriptionsDb: "subscribe_to_signature()" SubscriptionsDb->>Metrics: "Increment RPC_WS_SUBSCRIPTIONS_COUNT (signature)" SubscriptionsDb-->>WebSocketDispatcher: "Subscription handle" Note over TransactionExecutor: "Transaction completes" TransactionExecutor->>SubscriptionsDb: "send_signature_update()" SubscriptionsDb->>WebSocketDispatcher: "Signature result" WebSocketDispatcher-->>User: "WebSocket notification" SubscriptionsDb->>Metrics: "Decrement RPC_WS_SUBSCRIPTIONS_COUNT (signature)" end