Skip to content

Conversation

@bmuddha
Copy link
Contributor

@bmuddha bmuddha commented Oct 4, 2025

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:

  1. New RPC-focused metrics - Added comprehensive RPC request tracking including:

    • RPC_REQUESTS_COUNT for counting HTTP and WebSocket requests by method
    • RPC_REQUEST_HANDLING_TIME for measuring HTTP request duration
    • RPC_WS_SUBSCRIPTIONS_COUNT for tracking active WebSocket subscriptions
    • TRANSACTION_PROCESSING_TIME and TRANSACTION_SKIP_PREFLIGHT for transaction-related insights
    • ENSURE_ACCOUNTS_TIME for monitoring account fetching performance
    • FAILED_TRANSACTIONS_COUNT for tracking processing failures
  2. Infrastructure additions - Added the magicblock-metrics dependency to both magicblock-aperture and magicblock-processor packages to enable metrics collection across RPC-handling components.

  3. String conversion support - Extended RPC method enums with as_str() methods to provide static string representations for metrics labeling, enabling categorization by method type.

  4. WebSocket subscription tracking - Implemented a sophisticated RAII guard pattern (SubMetricGuard) to accurately track active subscription counts across all subscription types (account, program, logs, slot).

  5. 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
Filename Score Overview
magicblock-metrics/src/metrics/mod.rs 3/5 Major refactoring removing many existing metrics while adding RPC-specific ones; potential breaking changes
magicblock-aperture/src/state/subscriptions.rs 4/5 Implements RAII-based WebSocket subscription counting with proper lifecycle management
magicblock-aperture/src/requests/mod.rs 5/5 Adds string conversion methods to RPC enums for metrics labeling support
magicblock-aperture/src/server/http/dispatch.rs 4/5 Adds RPC request counting and timing metrics to HTTP dispatcher
magicblock-aperture/src/server/websocket/dispatch.rs 5/5 Adds RPC request counting for WebSocket operations
magicblock-aperture/src/requests/http/mod.rs 4/5 Adds timing metrics for account ensuring operations across different scenarios
magicblock-aperture/src/requests/http/send_transaction.rs 5/5 Adds transaction processing time and preflight skip metrics
magicblock-processor/src/executor/processing.rs 5/5 Adds failed transaction counting at the load phase
programs/magicblock/src/mutate_accounts/account_mod_data.rs 4/5 Removes account modification metrics tracking, simplifying data operations
magicblock-account-cloner/src/remote_account_cloner_worker.rs 4/5 Removes account cloning metrics from multiple operations
magicblock-aperture/Cargo.toml 5/5 Adds magicblock-metrics dependency for RPC metrics collection
magicblock-processor/Cargo.toml 5/5 Adds magicblock-metrics dependency for processor metrics

Confidence score: 3/5

  • This PR requires careful review due to significant metrics refactoring and potential breaking changes
  • Score reflects the removal of existing metrics infrastructure that may break monitoring dashboards or alerting
  • Pay close attention to magicblock-metrics/src/metrics/mod.rs for the extensive metrics changes and ensure dependent systems are updated accordingly

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
Loading

@bmuddha bmuddha self-assigned this Oct 4, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +154 to 156
pub static ref TRANSACTION_SKIP_PREFLIGHT: IntCounter = IntCounter::new(
"transaction_skip_preflight", "Count of transactions with/without preflight check",
).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: The description 'Count of transactions with/without preflight check' is ambiguous - this counter only increments, so it can't track both with and without. Consider renaming to clarify what exactly is being counted.

Suggested change
pub static ref TRANSACTION_SKIP_PREFLIGHT: IntCounter = IntCounter::new(
"transaction_skip_preflight", "Count of transactions with/without preflight check",
).unwrap();
pub static ref TRANSACTION_SKIP_PREFLIGHT: IntCounter = IntCounter::new(
"transaction_skip_preflight", "Count of transactions that skip preflight check",
).unwrap();
Prompt To Fix With AI
This is a comment left during a code review.
Path: magicblock-metrics/src/metrics/mod.rs
Line: 154:156

Comment:
**style:** The description 'Count of transactions with/without preflight check' is ambiguous - this counter only increments, so it can't track both with and without. Consider renaming to clarify what exactly is being counted.

```suggestion
    pub static ref TRANSACTION_SKIP_PREFLIGHT: IntCounter = IntCounter::new(
        "transaction_skip_preflight", "Count of transactions that skip preflight check",
    ).unwrap();
```

How can I resolve this? If you propose a fix, please make it concise.

@thlorenz thlorenz deleted the branch thlorenz/chainlink October 24, 2025 12:02
@thlorenz thlorenz closed this Oct 24, 2025
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