-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have close/flush return a Future for callers to wait on #71
base: master
Are you sure you want to change the base?
Conversation
Sorry, this turned into a more involved PR than I expected! |
Will take a look as soon as I can. |
@ramosbugs apologies for such a long delay. I promise I'll look at this as soon as I'm not swamped. I appreciate the contribution! |
no worries, thanks! |
Although I didn't have the intention to expose async outside of the client, I kind of like the approach here. |
The main thing I'd like to change before I merge (if you're up for it!) is to make If you're not up for it (and I totally understand if you aren't), I'll bring it myself in another PR with this one as base. Just let me know what you'd prefer and I'm happy to oblige. I really appreciate your contribution. |
done!
It looks like there are a few complexities around tokio vs. async_std here:
|
also, is the objection to adding |
You hit exactly what my message was intended to deliver and which I failed to deliver 😆 |
I think given the issues around dropping runtimes at various points in the code, the runtime-agnostic approach would be preferable. I'll try to incorporate that change :-) |
looks like the as reflected in #61, my change isn't sufficient to support runtimes other than Tokio because of Reqwest's dependency on Tokio, but it fixes the task management piece. switching to surf (in a follow-up change) would finish adding support for other runtimes. there's also a caveat with my latest change: it relies on |
This is looking great. I'm going to do a deeper review this weekend and get this out there most likely. I can't thank you enough for the contributions and patience on my late reviews. |
@@ -58,9 +58,7 @@ impl Default for Options { | |||
|
|||
/// Client represents an object that can create new builders and events and send them | |||
/// somewhere. | |||
#[derive(Debug, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started going through a closer look and this is probably going to be the biggest change/pain point for consumers of the library.
I experimented with a library beeline-rust
which uses this one, providing an actix-web
middleware and it requires really drastic changes to cope with this Clone
disappearing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for opentelemetry-honeycomb
, I was able to solve this by wrapping the client in an Arc+RwLock
: https://github.com/ramosbugs/opentelemetry-honeycomb-rs/blob/ca82ecd99bdfcf9357547d6079e31d70a5bfb9b4/src/lib.rs#L168-L176
then sending events just involves acquiring the read lock: https://github.com/ramosbugs/opentelemetry-honeycomb-rs/blob/ca82ecd99bdfcf9357547d6079e31d70a5bfb9b4/src/lib.rs#L332-L335
would that solution work for actix-web
, or is there something about actix that makes it more difficult?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would. I'm going to play with it tomorrow am and come back to this. I'm still quite keen on merging this PR.
pub struct TransmissionMock { | ||
started: usize, | ||
stopped: usize, | ||
events_called: usize, | ||
events: Vec<Event>, | ||
events: Mutex<Vec<Event>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this is one where without Clone
(and with this Mutex
here, we pass on all the complexity to consumers).
I'm not saying its the wrong thing to do but the expectation that we'd manage this on the whole is now void.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still re-familiarizing myself with this PR and digesting the Clone
issue for Client
, but isn't this particular comment just on the testing mock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed. I use this in beeline-rust
(to test multi threads) https://github.com/nlopes/beeline-rust/blob/master/src/lib.rs#L211
Currently, calling
flush
triggers an asynchronous flush but doesn'tprovide the caller with a mechanism to wait for all queued events to
be flushed.
This PR changes the
Client::flush
andClient::close
interfaces to beasync
and fixes a few concurrency issues I ran into while making thischange:
crossbeam_channel
withasync_channel
.The
crossbeam_channel
crate blocks the current thread and isn'tsafe to use within an async executor. The timeout behavior is preserved
using
future::timeout
.process_work
task. Instead,tasks are spawned within the
Transmission
's runtime.Mutex
around the runtime, which causes problems sharingthe guards across threads and doesn't appear to be needed.
out of the
process_work
loop (Queued events are ignored when flushing client #65).Resolves #66 and fixes #65.