Skip to content

ref: Rewrite Transports to be able to explicitly flush - #314

Merged
Swatinem merged 6 commits into
masterfrom
feat/flush-transport
Feb 3, 2021
Merged

Swatinem merged 6 commits into
masterfrom
feat/flush-transport

Conversation

@Swatinem

@Swatinem Swatinem commented Jan 29, 2021 •

Copy link
Copy Markdown
Contributor

This implements a new flush method for Transports which can flush the current queue without closing the transport.

Also, the default transports were rewritten in a more generic way using an async-capable background thread.

Additionally, the internal transports now support more fine grained rate limiting via X-Sentry-Rate-Limits. The RateLimiter is currently private, but we can decide how to best expose it later on.

TODO

  • Write some integration tests based on a local server which can test proper http requests, rate limiting, etc…
  • Figure out borrow errors related to passing/returning RateLimiter by value instead of &mut.

@Swatinem
Swatinem requested a review from a team January 29, 2021 12:10
Comment thread sentry-core/src/transport.rs Resolved
/// Updates the RateLimiter with information from a `Retry-After` header.
pub fn update_from_retry_after(&mut self, header: &str) {
let new_time = if let Ok(value) = header.parse::<f64>() {
Some(SystemTime::now() + Duration::from_secs(value.ceil() as u64))

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.

Why is rate limiting done with SystemTime rather than Instant?

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.

Not quite sure actually. I just copied the old code, without thinking too much about it.

@Swatinem
Swatinem marked this pull request as ready for review February 3, 2021 11:58
@Swatinem
Swatinem merged commit 50ae926 into master Feb 3, 2021
@Swatinem
Swatinem deleted the feat/flush-transport branch February 3, 2021 13:23
szokeasaurusrex added a commit that referenced this pull request Nov 3, 2026
The `Transport` impl for `Arc<T>` forwarded `send_envelope` and
`shutdown` but not `flush`, so flushing through it hit the trait default
and returned `true` without flushing `T`. This also affects
`Client::flush` when passing an `Arc`-wrapped transport to
`ClientOptions::transport`, as in
`.transport(Arc::new(TestTransport::new()))`. `flush` was added to the
trait in #314 without updating this impl.

`clippy::missing_trait_methods` is denied on the impl so a future
defaulted `Transport` method cannot be silently skipped again.

Fixes #1374
Fixes [RUST-302](https://linear.app/getsentry/issue/RUST-302)

<!-- junior-request-attribution:start -->
via @szokeasaurusrex.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0C01CK9SG2%3A1793270064.615489 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0C01CK9SG2%3A1793270064.615489)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0C01CK9SG2%3A1793270064.615489/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Dr. Daniel Szokenstein <[email protected]>
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