Skip to content

[graphql-stream-metrics] Add per-subscriber subscription metrics [22/n] - #27756

Merged
tpham-mysten merged 1 commit into
tpham-mysten/subscription-metricsfrom
tpham-mysten/subscription-lifecycle-metrics
Aug 26, 2026
Merged

tpham-mysten merged 1 commit into
tpham-mysten/subscription-metricsfrom
tpham-mysten/subscription-lifecycle-metrics

Conversation

@tpham-mysten

Copy link
Copy Markdown
Contributor

Description

Builds on the upstream-stream metrics from #27669 (1/n) with the per-subscriber view. A SubscriptionLifecycleGuard (RAII, held for the lifetime of each subscription stream) records, by subscription type, how many are active, how many opened, how long they live, and how and why they end. It also records per-payload delivery: a delivered counter and a server-side delivery-lag histogram, observed once per payload in the live loop after each yield (so the lag reflects that payload's own throttle pacing).

Metrics added, all labelled by subscription type:

  • graphql_subscription_active_subscriptions (gauge)
  • graphql_subscription_opened (counter)
  • graphql_subscription_terminations (counter, by reason)
  • graphql_subscription_duration_seconds (histogram)
  • graphql_subscription_payloads_delivered (counter)
  • graphql_subscription_payload_delivery_checkpoint_timestamp_lag (histogram)

Test plan

Unit tests for the guard: the active gauge and opened counter on construction, and on drop the gauge decrement, a duration sample, and a client_closed termination when no reason was set; a set reason overriding that default; and per-payload delivery counting plus one lag observation per call.

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • Indexing Framework:

@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 19, 2026 04:10 — with GitHub Actions Inactive
@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sui-docs Ready Ready Preview Aug 26, 2026 6:49pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
multisig-toolkit Ignored Ignored Preview Aug 26, 2026 6:49pm
sui-kiosk Ignored Ignored Preview Aug 26, 2026 6:49pm

Request Review

@tpham-mysten
tpham-mysten marked this pull request as ready for review August 19, 2026 04:11
@tpham-mysten
tpham-mysten requested a review from a team as a code owner August 19, 2026 04:11
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 19, 2026 04:11 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-lifecycle-metrics branch from 14910a1 to 21efcf7 Compare August 19, 2026 18:41
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 19, 2026 18:41 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-lifecycle-metrics branch from 21efcf7 to c82da0f Compare August 20, 2026 15:54
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 20, 2026 15:54 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-lifecycle-metrics branch from c82da0f to b7b7e31 Compare August 21, 2026 02:08
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 21, 2026 02:08 — with GitHub Actions Inactive
@tpham-mysten tpham-mysten changed the title [graphql-stream-metrics] Add per-subscriber subscription metrics [2/n] [graphql-stream-metrics] Add per-subscriber subscription metrics [22/n] Aug 21, 2026
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-lifecycle-metrics branch from b7b7e31 to c7edcd9 Compare August 24, 2026 20:27

@amnn amnn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could look into removing the dependency on strum, but looks good.

Comment thread crates/sui-indexer-alt-graphql/src/api/subscription/mod.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/api/subscription/scan_then_live.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/api/subscription/scan_then_live.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/task/streaming/lifecycle.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/lib.rs Outdated

@tpham-mysten tpham-mysten left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @amnn! I have dropped strum and moved SubscriptionMetrics into the broadcast.

Comment thread crates/sui-indexer-alt-graphql/src/task/streaming/lifecycle.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/api/subscription/scan_then_live.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/api/subscription/scan_then_live.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/api/subscription/mod.rs Outdated
Comment thread crates/sui-indexer-alt-graphql/src/lib.rs Outdated
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 26, 2026 16:47 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-lifecycle-metrics branch from b1d7850 to 88695e2 Compare August 26, 2026 18:44
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 26, 2026 18:44 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-lifecycle-metrics branch from 88695e2 to e26da3b Compare August 26, 2026 18:46
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 26, 2026 18:46 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten merged commit 9f71042 into main Aug 26, 2026
63 checks passed
@tpham-mysten
tpham-mysten deleted the tpham-mysten/subscription-lifecycle-metrics branch August 26, 2026 20:13
tpham-mysten added a commit that referenced this pull request Aug 26, 2026
…_subscribers limit [23/n] (#27787)

## Description

Subscriptions currently open without any aggregate limit, so a burst of
subscribers can drive server CPU and memory unbounded. This adds a
configurable `max_subscribers` (default 1024): each subscription claims
a slot from a shared semaphore held for its lifetime by the lifecycle
guard, and a subscription opened while all slots are taken is refused
with a `resource_exhausted` error so the client can retry later.
Refusals are counted by `graphql_subscription_rejected{type, reason}`.

Guard creation moves out of the driver `stream!` bodies up to the
resolver, so admission happens once at connect time before any work
begins.

## Test plan

New `rejects_at_capacity` unit test covers admission, the at-capacity
refusal and its metric, and slot release on drop. Existing subscription
lib tests cover the guard threaded through the drivers.

## Stack
   - #26019
   - #26094
   - #26117
   - #26170
   - #26194
   - #26202
   - #26414
   - #26453
   - #26476
   - #26487
   - #26425
   - #26495
   - #26731
   - #26714
   - #27140
   - #27537
   - #27564
   - #27580
   - #27635
   - #27709
   - #27669 
   - #27756 
   - #27787

## Release notes

Check each box that your change affects. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol:
- [ ] Nodes (Validators and Full nodes):
- [ ] gRPC:
- [ ] JSON-RPC:
- [ ] GraphQL:
- [ ] CLI:
- [ ] Rust SDK:
- [ ] REST API:

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – sui-docs e26da3bf Deployed Aug 26, 2026 by vercel[bot]
sui-typescript-aws-kms-test-env e26da3bf Deployed Aug 26, 2026 by tpham-mysten via Lint, Build, and Test #90471
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