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

refactor: ddcommon-net+profiling with hyper 1 #748

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

morrisonlevi
Copy link
Contributor

What does this PR do?

  1. There is a new crate ddcommon-net, naming suggestions welcome. It has bits of ddcommon networking code which have been upgraded to hyper 1. Note it's not a direct 1:1 because hyper 1 changed a lot.
  2. The datadog-profiling crate has been updated to use it. Currently its tests pass for me locally. The datadog-profiling-ffi is currently broken.
  3. Other crates are not touched

Motivation

The main motivation is to upgrade hyper from v0.14 to v1. There are a lot of changes when moving to v1. Some things do not have direct replacements, so upgrading all crates at once is difficult. I decided (with input from a few others) that it seemed sensible to try making a ddcommon-net crate that uses hyper 1, and then crates can migrate one-by-one from ddcommon to ddcommon-net.

Additional Notes

Please tell me if you have concerns about the approach, technical or otherwise. Here are some of mine:

  1. Since datadog-profiling is the only crate using this for now, is ddcommon-net really going to be common? Maybe we should make a net module inside of datadog-profiling instead and only extract a crate when there is at least one other crate migrated to hyper 1?
  2. There is some of copy/paste in ddcommon-net::compat and ddcommon, mostly around Uri and Endpoint related things. Probably okay, not sure.

How to test the change?

Don't. This is a WIP, I'll update this when it's ready for testing.

@github-actions github-actions bot added profiling Relates to the profiling* modules. common labels Nov 19, 2024
@@ -37,7 +37,7 @@ members = [
"data-pipeline-ffi",
"ddsketch",
"tinybytes",
"dogstatsd-client",
"dogstatsd-client", "ddcommon-net",
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting

ddcommon = { path = "../ddcommon" }
hex = { version = "0.4" }
http = { version = "1" }
hyper = { version = "1", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

use std::borrow::Cow;
use std::ops::Deref;

// todo: why do we need to serialize and deserialize endpoints?
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe crashtracker uses this: we spawn a collector, and then tell it where to send data by sending a Config struct as json over a pipe.

/// - User agent
/// - Api key
/// - Container Id/Entity Id
pub fn into_request_builder(
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ I'd expect into_ named functions to consume the object.

Self {
url: uri,
api_key: None,
timeout_ms: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be DEFAULT_TIMEOUT?

api_key: Some(api_key.into()),
..Default::default()
})
pub trait ProfilingEndpoint {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a trait?


/// Creates a tokio runtime for the current thread. This is the expected
/// way to create a runtime used by this crate.
pub fn create_current_thread_runtime() -> io::Result<runtime::Runtime> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we stash this in a thread_local?

if uri.scheme_str() != Some("unix") || uri.scheme_str() != Some("windows") {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"URI scheme must be unix or windows",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"URI scheme must be unix or windows",
format!("URI scheme must be unix or windows: was {}", uri.scheme_str()),

if uri.scheme_str() != Some("https") {
return Err(Error::Io(io::Error::new(
io::ErrorKind::InvalidInput,
"URI scheme must be https",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"URI scheme must be https",
format!("URI scheme must be https, was {}", uri.scheme_str()),

Some(scheme) => match scheme.as_str() {
"http" => send_http(request).await,
"https" => send_https(request).await,
#[cfg(unix)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we eventually want to support this on Windows? https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common profiling Relates to the profiling* modules.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants