Skip to content

[plat-407] prometheus metrics#36

Open
dhfang wants to merge 4 commits intomainfrom
feat/prometheus-metrics
Open

[plat-407] prometheus metrics#36
dhfang wants to merge 4 commits intomainfrom
feat/prometheus-metrics

Conversation

@dhfang
Copy link
Copy Markdown
Contributor

@dhfang dhfang commented May 4, 2026

No description provided.

@linear
Copy link
Copy Markdown

linear Bot commented May 4, 2026

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR introduces a Prometheus metrics layer for the IBC attestor, adding a process-wide registry (initialised at startup with adapter and signer constant labels) and instrumenting all RPC handlers, the retry path, the height validator, commitment validation, and the signer with counters, gauges, and histograms. Metrics are exposed via a new GET /metrics endpoint on the existing HTTP health server.

Confidence Score: 4/5

Safe to merge; all findings are P2 style/quality concerns with no correctness impact.

The implementation is well-structured and all instrumentation call sites are correct. Two minor issues were found: a silently discarded encoding error in encode_text and a redundant Instant::now() in each middleware handler. Neither affects correctness or runtime behavior.

apps/ibc-attestor/src/metrics.rs — silently discarded encoder error and test isolation note.

Important Files Changed

Filename Overview
apps/ibc-attestor/src/metrics.rs New module introducing a process-wide Prometheus registry with 8 metrics; two minor issues: silently discarded encoding error and OnceLock test isolation risk.
apps/ibc-attestor/src/rpc/middleware.rs Routes all three gRPC handlers through metrics::track_rpc; each handler retains its own Instant::now() for logging alongside track_rpc's internal timer — redundant but not harmful.
apps/ibc-attestor/src/rpc/health.rs Adds a GET /metrics warp route serving the Prometheus text format alongside the existing /healthz endpoint; clean implementation.
apps/ibc-attestor/src/rpc/attestor.rs Adds height-lag observation, rejection counter, and commitment failure counters at the right call sites; logic is correct.
apps/ibc-attestor/src/adapter/retry.rs Increments adapter_retry_failures_total only when all MAX_ATTEMPTS are exhausted; condition and counter placement are correct.
apps/ibc-attestor/src/adapter/mod.rs Propagates finalized height to the gauge on every successful get_last_height_at_configured_finality call; result is correctly forwarded.
apps/ibc-attestor/src/signer/mod.rs Records ok/err signer outcome after every signing call; no issues.
apps/ibc-attestor/src/bin/ibc_attestor/main.rs Calls metrics::init with &'static str adapter and signer names before server startup; initialization order is correct.

Sequence Diagram

sequenceDiagram
    participant Client
    participant LoggingMiddleware
    participant track_rpc
    participant AttestorService
    participant Adapter
    participant Signer
    participant MetricsRegistry

    Client->>LoggingMiddleware: gRPC request
    LoggingMiddleware->>track_rpc: wrap future + start timer
    track_rpc->>AttestorService: await inner handler
    AttestorService->>Adapter: get_last_height_at_configured_finality()
    Adapter-->>MetricsRegistry: set_adapter_finalized_height(height)
    Adapter-->>AttestorService: finalized height
    AttestorService->>MetricsRegistry: observe_height_lag(lag)
    alt height > finalized
        AttestorService->>MetricsRegistry: inc_height_rejections()
        AttestorService-->>track_rpc: Err(BlockNotFinalized)
    else valid height
        AttestorService->>Adapter: get_commitment(...)
        alt commitment invalid
            AttestorService->>MetricsRegistry: inc_commitment_failure(kind)
        end
        AttestorService->>Signer: sign(payload)
        Signer-->>MetricsRegistry: inc_signer_sign(ok|err)
        AttestorService-->>track_rpc: Ok(response)
    end
    track_rpc->>MetricsRegistry: record_rpc_request(method, code, elapsed)
    track_rpc-->>LoggingMiddleware: result
    LoggingMiddleware-->>Client: gRPC response

    note over Client,MetricsRegistry: Prometheus scraper polls GET /metrics -> encode_text()
Loading

Reviews (1): Last reviewed commit: "refactor: trim metrics docs" | Re-trigger Greptile

Comment thread apps/ibc-attestor/src/metrics.rs Outdated
Comment thread apps/ibc-attestor/src/rpc/middleware.rs Outdated
Comment thread apps/ibc-attestor/src/metrics.rs
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.

1 participant