diff --git a/sidecar/src/interface.rs b/sidecar/src/interface.rs index b001e74860..ce0e5b326b 100644 --- a/sidecar/src/interface.rs +++ b/sidecar/src/interface.rs @@ -57,43 +57,10 @@ use crate::{config, log, tracer}; use crate::service::{ InstanceId, QueueId, RequestIdentification, RequestIdentifier, RuntimeMetadata, - SerializedTracerHeaderTags, + SerializedTracerHeaderTags, SidecarInterface, SidecarInterfaceRequest, + SidecarInterfaceResponse, }; -#[datadog_sidecar_macros::extract_request_id] -#[datadog_ipc_macros::impl_transfer_handles] -#[tarpc::service] -pub trait SidecarInterface { - async fn enqueue_actions( - instance_id: InstanceId, - queue_id: QueueId, - actions: Vec, - ); - async fn register_service_and_flush_queued_actions( - instance_id: InstanceId, - queue_id: QueueId, - meta: RuntimeMetadata, - service_name: String, - env_name: String, - ); - async fn set_session_config(session_id: String, config: SessionConfig); - async fn shutdown_runtime(instance_id: InstanceId); - async fn shutdown_session(session_id: String); - async fn send_trace_v04_shm( - instance_id: InstanceId, - #[SerializedHandle] handle: ShmHandle, - headers: SerializedTracerHeaderTags, - ); - async fn send_trace_v04_bytes( - instance_id: InstanceId, - data: Vec, - headers: SerializedTracerHeaderTags, - ); - async fn ping(); - async fn dump() -> String; - async fn stats() -> String; -} - #[derive(Serialize, Deserialize)] pub struct SidecarStats { pub trace_flusher: TraceFlusherStats, diff --git a/sidecar/src/service/mod.rs b/sidecar/src/service/mod.rs index ddedfca064..52ba3c8b7e 100644 --- a/sidecar/src/service/mod.rs +++ b/sidecar/src/service/mod.rs @@ -6,9 +6,13 @@ pub use queue_id::QueueId; pub use request_identification::{RequestIdentification, RequestIdentifier}; pub use runtime_metadata::RuntimeMetadata; pub use serialized_tracer_header_tags::SerializedTracerHeaderTags; +pub use sidecar_interface::{ + SidecarInterface, SidecarInterfaceClient, SidecarInterfaceRequest, SidecarInterfaceResponse, +}; mod instance_id; pub mod queue_id; mod request_identification; mod runtime_metadata; mod serialized_tracer_header_tags; +mod sidecar_interface; diff --git a/sidecar/src/service/sidecar_interface.rs b/sidecar/src/service/sidecar_interface.rs new file mode 100644 index 0000000000..0d8d764331 --- /dev/null +++ b/sidecar/src/service/sidecar_interface.rs @@ -0,0 +1,115 @@ +// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 + +use crate::interface::{SessionConfig, SidecarAction}; +use crate::service::{ + InstanceId, QueueId, RequestIdentification, RequestIdentifier, RuntimeMetadata, + SerializedTracerHeaderTags, +}; +use anyhow::Result; +use datadog_ipc::platform::ShmHandle; +use datadog_ipc::tarpc; + +/// The `SidecarInterface` trait defines the necessary methods for the sidecar service. +/// +/// These methods include operations such as enqueueing actions, registering services, setting +/// session configurations, and sending traces. +#[datadog_sidecar_macros::extract_request_id] +#[datadog_ipc_macros::impl_transfer_handles] +#[tarpc::service] +pub trait SidecarInterface { + /// Enqueues a list of actions to be performed. + /// + /// # Arguments + /// + /// * `instance_id` - The ID of the instance. + /// * `queue_id` - The unique identifier for the action in the queue. + /// * `actions` - The action type being enqueued. + async fn enqueue_actions( + instance_id: InstanceId, + queue_id: QueueId, + actions: Vec, + ); + + /// Registers a service and flushes any queued actions. + /// + /// # Arguments + /// + /// * `instance_id` - The ID of the instance. + /// * `queue_id` - The unique identifier for the action in the queue. + /// * `meta` - The metadata of the runtime. + /// * `service_name` - The name of the service. + /// * `env_name` - The name of the environment. + async fn register_service_and_flush_queued_actions( + instance_id: InstanceId, + queue_id: QueueId, + meta: RuntimeMetadata, + service_name: String, + env_name: String, + ); + + /// Sets the configuration for a session. + /// + /// # Arguments + /// + /// * `session_id` - The ID of the session. + /// * `config` - The configuration to be set. + async fn set_session_config(session_id: String, config: SessionConfig); + + /// Shuts down a runtime. + /// + /// # Arguments + /// + /// * `instance_id` - The ID of the instance. + async fn shutdown_runtime(instance_id: InstanceId); + + /// Shuts down a session. + /// + /// # Arguments + /// + /// * `session_id` - The ID of the session. + async fn shutdown_session(session_id: String); + + /// Sends a trace via shared memory. + /// + /// # Arguments + /// + /// * `instance_id` - The ID of the instance. + /// * `handle` - The handle to the shared memory. + /// * `headers` - The serialized headers from the tracer. + async fn send_trace_v04_shm( + instance_id: InstanceId, + #[SerializedHandle] handle: ShmHandle, + headers: SerializedTracerHeaderTags, + ); + + /// Sends a trace as bytes. + /// + /// # Arguments + /// + /// * `instance_id` - The ID of the instance. + /// * `data` - The trace data serialized as bytes. + /// * `headers` - The serialized headers from the tracer. + async fn send_trace_v04_bytes( + instance_id: InstanceId, + data: Vec, + headers: SerializedTracerHeaderTags, + ); + + /// Sends a ping to the service. + async fn ping(); + + /// Dumps the current state of the service. + /// + /// # Returns + /// + /// A string representation of the current state of the service. + async fn dump() -> String; + + /// Retrieves the current statistics of the service. + /// + /// # Returns + /// + /// A string representation of the current statistics of the service. + async fn stats() -> String; +}