Skip to content

Commit

Permalink
WIP: move sidecar interface to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
ekump committed Apr 17, 2024
1 parent c3c5d76 commit 580ae4e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 35 deletions.
37 changes: 2 additions & 35 deletions sidecar/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SidecarAction>,
);
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<u8>,
headers: SerializedTracerHeaderTags,
);
async fn ping();
async fn dump() -> String;
async fn stats() -> String;
}

#[derive(Serialize, Deserialize)]
pub struct SidecarStats {
pub trace_flusher: TraceFlusherStats,
Expand Down
4 changes: 4 additions & 0 deletions sidecar/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
115 changes: 115 additions & 0 deletions sidecar/src/service/sidecar_interface.rs
Original file line number Diff line number Diff line change
@@ -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<SidecarAction>,
);

/// 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<u8>,
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;
}

0 comments on commit 580ae4e

Please sign in to comment.