Skip to content

Add two client-side warnings to detect non-optimal use of the SDKs#330

Open
irinatomic-db wants to merge 1 commit into
mainfrom
irina-tomic_data/irinatomic-db/add-warnings
Open

Add two client-side warnings to detect non-optimal use of the SDKs#330
irinatomic-db wants to merge 1 commit into
mainfrom
irina-tomic_data/irinatomic-db/add-warnings

Conversation

@irinatomic-db
Copy link
Copy Markdown

@irinatomic-db irinatomic-db commented May 28, 2026

What changes are proposed in this pull request?

Adds two process-wide client-side warnings to ZerobusStream and ZerobusArrowStream that surface common stream misuse patterns at runtime.

Stream churn - fires a WARN when 100 or more streams for the same table are opened within a 60-second sliding window. Re-fires after the rate recovers and rises again.

Both warnings live in a new client_warnings module and can be suppressed with ZEROBUS_SDK_WARNINGS_ENABLED=false.

Why: Users sometimes accidentally create a new stream per record instead of reusing streams, or fan out to many concurrent streams unnecessarily. These patterns cause undue load on the service and are hard to spot from the outside. Python and TypeScript pick these up automatically; Go and Java will on the next FFI release.

How is this tested?

Added unit tests.

For manual verification, a temporary test was added that initialised a tracing subscriber and opened streams in a loop to confirm both WARN lines fired correctly. It was removed before this PR.

@irinatomic-db irinatomic-db force-pushed the irina-tomic_data/irinatomic-db/add-warnings branch 3 times, most recently from 5825e93 to 0e927bf Compare May 29, 2026 11:30
Comment thread rust/sdk/src/lib.rs Outdated
)
})??);

client_warnings::record_stream_opened(&table_properties.table_name);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both new and recreate_stream hit this path. If I am reading this correctly, we do double counting during recreate.

Ideally, recreate stream shouldn't count as churn.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Moved the call out of new_stream() and into the builder, so recreate_stream and recreate_arrow_stream no longer count as churn.

Comment thread rust/NEXT_CHANGELOG.md Outdated
### New Features and Improvements

- Added process-wide client-side warnings to surface common misuse patterns:
- **Concurrent open streams**: logs a `WARN` when 32 or more ingest streams for the same table are open simultaneously.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we really need both patterns? They are kind of doing a similar thing.
Can we just have 100 per 60 seconds?

What is the scenario where we care about 32 concurrent streams?

Copy link
Copy Markdown
Author

@irinatomic-db irinatomic-db May 29, 2026

Choose a reason for hiding this comment

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

Good point.

Main idea was to check if someone is misusing the SDK (treating it like a file push system, opening 1 stream for each record). But the stream churn warning is enough. I'll keep only that one.

Comment thread rust/sdk/src/client_warnings.rs Outdated
/// message the first time the count within the window reaches
/// [`CHURN_WARN_THRESHOLD`] (100). The warning re-fires if the rate drops below
/// the threshold and later surges again in a new window.
pub(crate) fn record_stream_opened(table_name: &str) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we do better naming? register_stream_opened and record_stream_opened sound the same.
(ideally, let's just keep only churn_threshold = 100 so we don't need to do both.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Dropped the concurrent monitor entirely

@irinatomic-db irinatomic-db force-pushed the irina-tomic_data/irinatomic-db/add-warnings branch from 0e927bf to f00f9a5 Compare May 29, 2026 12:13
Comment thread rust/README.md
}
```

## Client-side warnings
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.

We should add this entry in table of contents

@elenagaljak-db
Copy link
Copy Markdown
Contributor

Btw, you need to setup signed commits. Since you've already pushed commits, it needs to be done "retroactively". I usually do it like this:

> git rebase --exec 'git commit --amend --no-edit -S' origin/main
> git push origin HEAD:<branch_name> --force-with-lease

@irinatomic-db irinatomic-db force-pushed the irina-tomic_data/irinatomic-db/add-warnings branch from f00f9a5 to 5d1e988 Compare May 29, 2026 14:00
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.

3 participants