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 sidecar/interface.rs into smaller files #395

Merged
merged 24 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0231400
remove unnecessary clippy allow for needless collect in sidecar
ekump Apr 15, 2024
be066c5
refactor Sidecar::Interface::InstanceId to separate file
ekump Apr 16, 2024
f9d170a
refactor Sidecar::Interface::QueueId to a separate file.
ekump Apr 16, 2024
f66cefc
refactor sidecar::interface::RuntimeMeta to separate file
ekump Apr 16, 2024
e0da65e
minor cleanup of sidecar::interface file.
ekump Apr 16, 2024
fb0d198
refactor Sidecar::Interface::SerializedTracerHeaderTags to a separate…
ekump Apr 17, 2024
dcda29e
refactor RequestIdentifier and RequqestIdentification to separate file
ekump Apr 17, 2024
43dff04
refactor sidecar_interface from interface.rs to separate file
ekump Apr 17, 2024
6bc665b
Refactor sidecar::interface::SessionInfo to its own file.
ekump Apr 17, 2024
e3920e4
refactor Sidecar::SidecarServer to separate file
ekump Apr 18, 2024
7f37365
extract session interceptor into separate function in sidecar_server
ekump Apr 22, 2024
884ff38
sidecar server - move logic for processing of interceptor response
ekump Apr 30, 2024
55463dd
Add rustdoc comments for public sidecar_server methods
ekump May 2, 2024
f011497
Minor tweak to sidecar session_info::shutdown_runtime to reduce mutex…
ekump May 2, 2024
0532d2d
refactor sidecar RuntimeInfo from interface.rs to separate file
ekump May 4, 2024
d818098
refactor complex type in sidecar RuntimeInfo
ekump May 4, 2024
c06a39a
Sidecar - move SessionConfig, SidecarAction, and ApporQueue structs
ekump May 4, 2024
7ed1eb4
refactor sidecar::AppInstance in to separate file
ekump May 4, 2024
10ca393
sidecar - refactor enqueued_telemetry_data and enqueued_telemetry_sta…
ekump May 5, 2024
e61995a
sidecar - refactor tracing logic in interface.rs to separate files
ekump May 5, 2024
b675f04
refactor SidecarStats to telemetry namespace
ekump May 5, 2024
f8c54d4
Move blocking sidecar_interface to separate file
ekump May 6, 2024
6104084
Reduce visibility scope of types after sidecar::interface refactor
ekump May 6, 2024
64b271d
Move SidecarStats and AppOrQueue structs to more appropriate locations.
ekump May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 45 additions & 34 deletions sidecar-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ use datadog_sidecar::agent_remote_config::{
};
use datadog_sidecar::config;
use datadog_sidecar::config::LogMethod;
use datadog_sidecar::one_way_shared_memory::{OneWayShmReader, ReaderOpener};
use datadog_sidecar::service::{
blocking::{self, SidecarTransport},
InstanceId, QueueId, RuntimeMetadata, SerializedTracerHeaderTags, SessionConfig, SidecarAction,
};
use ddcommon::Endpoint;
use ddcommon_ffi as ffi;
use ddcommon_ffi::MaybeError;
use ddtelemetry::{
data::{self, Dependency, Integration},
worker::{LifecycleAction, TelemetryActions},
};
use ddtelemetry_ffi::try_c;
use ffi::slice::AsBytes;
use libc::c_char;
use std::convert::TryInto;
use std::ffi::c_void;
use std::fs::File;
#[cfg(unix)]
Expand All @@ -20,21 +34,6 @@ use std::os::windows::io::{FromRawHandle, RawHandle};
use std::slice;
use std::time::Duration;

use datadog_sidecar::interface::{
blocking::{self, SidecarTransport},
InstanceId, QueueId, RuntimeMeta, SerializedTracerHeaderTags, SessionConfig, SidecarAction,
};
use datadog_sidecar::one_way_shared_memory::{OneWayShmReader, ReaderOpener};
use ddcommon::Endpoint;
use ddtelemetry::{
data::{self, Dependency, Integration},
worker::{LifecycleAction, TelemetryActions},
};
use ffi::slice::AsBytes;

use ddcommon_ffi::MaybeError;
use ddtelemetry_ffi::try_c;

#[repr(C)]
pub struct NativeFile {
pub handle: Box<PlatformHandle<File>>,
Expand Down Expand Up @@ -241,8 +240,8 @@ pub unsafe extern "C" fn ddog_sidecar_runtimeMeta_build(
language_name: ffi::CharSlice,
language_version: ffi::CharSlice,
tracer_version: ffi::CharSlice,
) -> Box<RuntimeMeta> {
let inner = RuntimeMeta::new(
) -> Box<RuntimeMetadata> {
let inner = RuntimeMetadata::new(
language_name.to_utf8_lossy(),
language_version.to_utf8_lossy(),
tracer_version.to_utf8_lossy(),
Expand All @@ -253,7 +252,7 @@ pub unsafe extern "C" fn ddog_sidecar_runtimeMeta_build(

#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn ddog_sidecar_runtimeMeta_drop(meta: Box<RuntimeMeta>) {
pub unsafe extern "C" fn ddog_sidecar_runtimeMeta_drop(meta: Box<RuntimeMetadata>) {
drop(meta)
}

Expand Down Expand Up @@ -345,7 +344,7 @@ pub unsafe extern "C" fn ddog_sidecar_telemetry_flushServiceData(
transport: &mut Box<SidecarTransport>,
instance_id: &InstanceId,
queue_id: &QueueId,
runtime_meta: &RuntimeMeta,
runtime_meta: &RuntimeMetadata,
service_name: ffi::CharSlice,
env_name: ffi::CharSlice,
) -> MaybeError {
Expand Down Expand Up @@ -429,19 +428,27 @@ pub struct TracerHeaderTags<'a> {
pub client_computed_stats: bool,
}

impl<'a> From<&'a TracerHeaderTags<'a>> for SerializedTracerHeaderTags {
fn from(tags: &'a TracerHeaderTags<'a>) -> Self {
datadog_trace_utils::trace_utils::TracerHeaderTags {
lang: &tags.lang.to_utf8_lossy(),
lang_version: &tags.lang_version.to_utf8_lossy(),
lang_interpreter: &tags.lang_interpreter.to_utf8_lossy(),
lang_vendor: &tags.lang_vendor.to_utf8_lossy(),
tracer_version: &tags.tracer_version.to_utf8_lossy(),
container_id: &tags.container_id.to_utf8_lossy(),
client_computed_top_level: tags.client_computed_top_level,
client_computed_stats: tags.client_computed_stats,
}
.into()
impl<'a> TryInto<SerializedTracerHeaderTags> for &'a TracerHeaderTags<'a> {
type Error = std::io::Error;

fn try_into(self) -> Result<SerializedTracerHeaderTags, Self::Error> {
let tags = datadog_trace_utils::trace_utils::TracerHeaderTags {
lang: &self.lang.to_utf8_lossy(),
lang_version: &self.lang_version.to_utf8_lossy(),
lang_interpreter: &self.lang_interpreter.to_utf8_lossy(),
lang_vendor: &self.lang_vendor.to_utf8_lossy(),
tracer_version: &self.tracer_version.to_utf8_lossy(),
container_id: &self.container_id.to_utf8_lossy(),
client_computed_top_level: self.client_computed_top_level,
client_computed_stats: self.client_computed_stats,
};

tags.try_into().map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Failed to convert TracerHeaderTags to SerializedTracerHeaderTags",
)
})
}
}

Expand All @@ -453,11 +460,13 @@ pub unsafe extern "C" fn ddog_sidecar_send_trace_v04_shm(
shm_handle: Box<ShmHandle>,
tracer_header_tags: &TracerHeaderTags,
) -> MaybeError {
let tracer_header_tags = try_c!(tracer_header_tags.try_into());

try_c!(blocking::send_trace_v04_shm(
transport,
instance_id,
*shm_handle,
tracer_header_tags.into(),
tracer_header_tags,
));

MaybeError::None
Expand All @@ -471,11 +480,13 @@ pub unsafe extern "C" fn ddog_sidecar_send_trace_v04_bytes(
data: ffi::CharSlice,
tracer_header_tags: &TracerHeaderTags,
) -> MaybeError {
let tracer_header_tags = try_c!(tracer_header_tags.try_into());

try_c!(blocking::send_trace_v04_bytes(
transport,
instance_id,
data.as_bytes().to_vec(),
tracer_header_tags.into(),
tracer_header_tags,
));

MaybeError::None
Expand Down
4 changes: 2 additions & 2 deletions sidecar/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use std::{
};
use tokio::sync::mpsc;

use crate::interface::blocking::SidecarTransport;
use crate::interface::SidecarServer;
use crate::service::blocking::SidecarTransport;
use crate::service::SidecarServer;
use datadog_ipc::platform::AsyncChannel;

use crate::setup::{self, IpcClient, IpcServer, Liaison};
Expand Down
Loading
Loading