Skip to content
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

Allow the SidecarTransport to recreate its underlying transport #440

Merged
merged 7 commits into from
May 27, 2024

Conversation

iamluc
Copy link
Contributor

@iamluc iamluc commented May 21, 2024

What does this PR do?

Replace the SidecarTransport type alias by a real struct that handles reconnection.

This is handled in the Rust code so that sidecar's clients (like the PHP tracer) can use the SidecarTransport in a thread safe way.

Motivation

In the PHP tracer, the reconnection was previously done in the C code, but was not thread safe.

Additional Notes

Anything else we should know when reviewing?

How to test the change?

Describe here in detail how the change can be validated.

@iamluc iamluc force-pushed the luc/sidecar-reconnect branch 2 times, most recently from e290c6a to b25df51 Compare May 22, 2024 07:21
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2024

Codecov Report

Attention: Patch coverage is 78.50467% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 67.88%. Comparing base (315a093) to head (5eb41c8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #440      +/-   ##
==========================================
+ Coverage   67.76%   67.88%   +0.12%     
==========================================
  Files         193      193              
  Lines       24476    24583     +107     
==========================================
+ Hits        16585    16689     +104     
- Misses       7891     7894       +3     
Components Coverage Δ
crashtracker 19.34% <ø> (ø)
datadog-alloc 98.76% <ø> (ø)
data-pipeline 51.45% <ø> (ø)
data-pipeline-ffi 0.00% <ø> (ø)
ddcommon 85.24% <ø> (ø)
ddcommon-ffi 74.93% <ø> (ø)
ddtelemetry 56.09% <ø> (ø)
ipc 81.69% <ø> (+0.41%) ⬆️
profiling 78.09% <ø> (ø)
profiling-ffi 60.05% <ø> (ø)
serverless 0.00% <ø> (ø)
sidecar 37.87% <78.50%> (+1.28%) ⬆️
sidecar-ffi 0.00% <0.00%> (ø)
spawn-worker 54.98% <ø> (ø)
trace-mini-agent 69.12% <ø> (ø)
trace-normalization 97.79% <ø> (ø)
trace-obfuscation 95.74% <ø> (ø)
trace-protobuf 30.76% <ø> (ø)
trace-utils 78.29% <ø> (ø)

@iamluc iamluc marked this pull request as ready for review May 22, 2024 13:24
@iamluc iamluc requested a review from a team as a code owner May 22, 2024 13:24
@iamluc iamluc requested a review from bwoebi May 22, 2024 13:27
Copy link
Contributor

@pierotibou pierotibou left a comment

Choose a reason for hiding this comment

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

Too complicated for me ;) but a few comments around testing and comments

sidecar-ffi/src/lib.rs Show resolved Hide resolved
}

impl SidecarTransport {
pub fn reconnect<F>(&mut self, factory: F)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add utests for all those fonctions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some tests, but I'm not really happy with them as they are really coupled to the BlockingTransport.

Any advice is welcome!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's fine, the functionality itself is coupled to the BlockingTransport, so that's quite natural here.

pub fn is_closed(&self) -> bool {
match self.inner.lock() {
Ok(t) => t.is_closed(),
Err(_) => true, // Well... what can we do?
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that we're not just unwrapping and potentially panicking on the lock acquisitions, but I'm not sure what here is safe? I believe the majority of the time we'd get an error on a lock is if the lock is poisoned, which means we might be in a bad state? is it ok to assume that if self.inner is poisoned that the connection is closed and we should move forward with trying to reconnect?

Copy link
Contributor

Choose a reason for hiding this comment

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

The scenario where this will happen is when the reconnect callback executes functions on the sidecar instance (only location which calls back to caller from within the lock). And ... during the reconnect the original sidecar instance is always closed (otherwise the reconnect wouldn't happen in the first place), so actually true is the right value to report there.

Copy link
Contributor

Choose a reason for hiding this comment

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

This fact should be noted as comment rather than "what can we do" though :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment updated 😛

@iamluc iamluc requested review from a team as code owners May 24, 2024 13:10
@iamluc iamluc force-pushed the luc/sidecar-reconnect branch 4 times, most recently from fca832a to 797cd71 Compare May 24, 2024 14:14
Copy link
Contributor

@bwoebi bwoebi left a comment

Choose a reason for hiding this comment

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

Looks good to me, good for safety in threaded environments, especially avoiding possible risk of cross talk on send() and call().

…se it is broken.

This is handled in the Rust code so that sidecar's clients (like the PHP tracer)
can use the SidecarTransport in a thread safe way.
@bwoebi bwoebi merged commit 259ca9c into main May 27, 2024
25 checks passed
@bwoebi bwoebi deleted the luc/sidecar-reconnect branch May 27, 2024 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants