Skip to content

Commit

Permalink
feat(api): Add metrics for jsonrpsee subscriptions (#733)
Browse files Browse the repository at this point in the history
## What ❔

A small follow-up PR for #693 that introduces some metrics allowing to
track the health of the new approach. Also, does minor refactoring for
the API server builder so it's more typesafe.

## Why ❔

Observability and maintainability.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
slowli authored Dec 22, 2023
1 parent d1d919a commit 39fd71c
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 134 deletions.
15 changes: 15 additions & 0 deletions core/lib/zksync_core/src/api_server/web3/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,27 @@ pub(super) enum SubscriptionType {
#[derive(Debug, Metrics)]
#[metrics(prefix = "api_web3_pubsub")]
pub(super) struct PubSubMetrics {
/// Latency to load new events from Postgres before broadcasting them to subscribers.
#[metrics(buckets = Buckets::LATENCIES)]
pub db_poll_latency: Family<SubscriptionType, Histogram<Duration>>,
/// Latency to send an atomic batch of events to a single subscriber.
#[metrics(buckets = Buckets::LATENCIES)]
pub notify_subscribers_latency: Family<SubscriptionType, Histogram<Duration>>,
/// Total number of events sent to all subscribers of a certain type.
pub notify: Family<SubscriptionType, Counter>,
/// Number of currently active subscribers split by the subscription type.
pub active_subscribers: Family<SubscriptionType, Gauge>,
/// Lifetime of a subscriber of a certain type.
#[metrics(buckets = Buckets::LATENCIES)]
pub subscriber_lifetime: Family<SubscriptionType, Histogram<Duration>>,
/// Current length of the broadcast channel of a certain type. With healthy subscribers, this value
/// should be reasonably low.
pub broadcast_channel_len: Family<SubscriptionType, Gauge<usize>>,
/// Number of skipped broadcast messages.
#[metrics(buckets = Buckets::exponential(1.0..=128.0, 2.0))]
pub skipped_broadcast_messages: Family<SubscriptionType, Histogram<u64>>,
/// Number of subscribers dropped because of a send timeout.
pub subscriber_send_timeouts: Family<SubscriptionType, Counter>,
}

#[vise::register]
Expand Down
Loading

0 comments on commit 39fd71c

Please sign in to comment.