Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions src/internal/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ impl Drop for SpanOperation {
}

/// Shared delivery lifecycle, independent of resource HTTP operations.
#[async_trait]
pub(crate) trait DeliveryControl: Send + Sync {
fn flush(&self) -> crate::Completion<crate::FlushReport, crate::FlushError>;
async fn trigger_flush(&self) -> Result<()>;
}

#[async_trait]
pub(crate) trait SpanSubmitter: DeliveryControl {
fn operation(&self) -> std::result::Result<SpanOperation, crate::EnqueueError>;

Expand Down
68 changes: 2 additions & 66 deletions src/log_queue/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ fn default_flush_chunk_size() -> usize {
DEFAULT_FLUSH_CHUNK_SIZE
}

fn default_sync_flush() -> bool {
matches!(
std::env::var("BRAINTRUST_SYNC_FLUSH").ok().as_deref(),
Some("1") | Some("true") | Some("yes")
)
}

fn default_failed_publish_payloads_dir() -> Option<PathBuf> {
std::env::var("BRAINTRUST_FAILED_PUBLISH_PAYLOADS_DIR")
.ok()
Expand Down Expand Up @@ -100,7 +93,8 @@ fn default_all_publish_payloads_dir() -> Option<PathBuf> {
/// ```
#[derive(bon::Builder, Debug, Clone)]
pub struct LogQueueConfig {
/// Max queue size (BRAINTRUST_QUEUE_DROP_EXCEEDING_MAXSIZE, default: 15000)
/// Maximum accepted writes, including in-flight work
/// (BRAINTRUST_QUEUE_DROP_EXCEEDING_MAXSIZE, default: 15000).
#[builder(default = default_queue_max_size())]
queue_max_size: usize,

Expand All @@ -122,15 +116,6 @@ pub struct LogQueueConfig {
#[builder(default = default_num_retries())]
num_retries: usize,

/// Legacy compatibility value. Delivery is always automatic; ignored.
#[builder(default = default_sync_flush())]
sync_flush: bool,

/// Legacy compatibility value. Flush reports covered active failures and
/// delivery remains automatic; ignored.
#[builder(default = false)]
checked_delivery: bool,

/// Chunk size for flush processing (BRAINTRUST_LOG_FLUSH_CHUNK_SIZE, default: 25).
/// Rows drained from the queue are merged and sent in sequential chunks of this size.
/// Each chunk's batches are sent concurrently (matching TypeScript SDK behavior).
Expand All @@ -142,11 +127,6 @@ pub struct LogQueueConfig {

/// Debug: save all payloads (BRAINTRUST_ALL_PUBLISH_PAYLOADS_DIR)
all_publish_payloads_dir: Option<PathBuf>,

/// Legacy compatibility value. Admission is always bounded by queue_max_size,
/// including in-flight work; ignored.
#[builder(default = true)]
enforce_queue_size_limit: bool,
}

impl Default for LogQueueConfig {
Expand Down Expand Up @@ -176,14 +156,6 @@ impl LogQueueConfig {
self.num_retries
}

pub fn sync_flush(&self) -> bool {
self.sync_flush
}

pub fn checked_delivery(&self) -> bool {
self.checked_delivery
}

pub fn flush_chunk_size(&self) -> usize {
self.flush_chunk_size
}
Expand All @@ -199,10 +171,6 @@ impl LogQueueConfig {
.clone()
.or_else(default_all_publish_payloads_dir)
}

pub fn enforce_queue_size_limit(&self) -> bool {
self.enforce_queue_size_limit
}
}

#[cfg(test)]
Expand All @@ -216,16 +184,6 @@ mod tests {
assert_eq!(config.batch_max_items(), DEFAULT_BATCH_MAX_ITEMS);
assert_eq!(config.batch_max_bytes(), DEFAULT_BATCH_MAX_BYTES);
assert_eq!(config.num_retries(), DEFAULT_NUM_RETRIES);
assert!(!config.sync_flush());
assert!(config.enforce_queue_size_limit());
}

#[test]
fn test_enforce_queue_size_limit_can_be_enabled() {
let config = LogQueueConfig::builder()
.enforce_queue_size_limit(true)
.build();
assert!(config.enforce_queue_size_limit());
}

#[test]
Expand All @@ -234,33 +192,11 @@ mod tests {
.queue_max_size(5000)
.batch_max_items(50)
.num_retries(5)
.sync_flush(true)
.build();

assert_eq!(config.queue_max_size(), 5000);
assert_eq!(config.batch_max_items(), 50);
assert_eq!(config.num_retries(), 5);
assert!(config.sync_flush());
}

#[test]
fn test_sync_flush_env_var_accepts_truthy_strings() {
for truthy in &["1", "true", "yes"] {
unsafe { std::env::set_var("BRAINTRUST_SYNC_FLUSH", truthy) };
assert!(
default_sync_flush(),
"BRAINTRUST_SYNC_FLUSH={truthy} should enable sync flush"
);
}
for falsy in &["0", "false", "no", ""] {
unsafe { std::env::set_var("BRAINTRUST_SYNC_FLUSH", falsy) };
assert!(
!default_sync_flush(),
"BRAINTRUST_SYNC_FLUSH={falsy} should not enable sync flush"
);
}
unsafe { std::env::remove_var("BRAINTRUST_SYNC_FLUSH") };
assert!(!default_sync_flush(), "unset should not enable sync flush");
}

#[test]
Expand Down
17 changes: 1 addition & 16 deletions src/log_queue/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ impl LogQueueCore {
}
}

/// Compatibility adapter connecting span preparation to the bounded write service.
/// Span preparation and submission through the bounded write service.
#[derive(Clone)]
pub struct LogQueue {
core: Arc<LogQueueCore>,
Expand All @@ -654,7 +654,6 @@ impl LogQueue {
pub fn new(
config: LogQueueConfig,
client: reqwest::Client,
_worker_queue_size: usize,
execution: ExecutionBinding,
) -> Self {
Self {
Expand Down Expand Up @@ -795,25 +794,13 @@ impl LogQueue {
pub(crate) fn is_started(&self) -> bool {
matches!(*self.state(), QueueState::Running(_))
}
pub async fn trigger_flush_command(&self) -> Result<()> {
let token = self.flush();
if let Err(error) = &*token {
return Err(error.clone().into());
}
Ok(())
}
}

#[async_trait::async_trait]
impl DeliveryControl for LogQueue {
fn flush(&self) -> Completion<FlushReport, FlushError> {
LogQueue::flush(self)
}
async fn trigger_flush(&self) -> Result<()> {
self.trigger_flush_command().await
}
}
#[async_trait::async_trait]
impl SpanSubmitter for LogQueue {
fn operation(&self) -> std::result::Result<SpanOperation, crate::EnqueueError> {
let lease = {
Expand Down Expand Up @@ -884,7 +871,6 @@ mod tests {
LogQueue::new(
LogQueueConfig::builder().num_retries(0).build(),
reqwest::Client::new(),
32,
ExecutionBinding::external(tokio::runtime::Handle::current()),
)
}
Expand Down Expand Up @@ -918,7 +904,6 @@ mod tests {
.num_retries(0)
.build(),
reqwest::Client::new(),
8,
ExecutionBinding::external(tokio::runtime::Handle::current()),
);
assert!(!queue.is_started());
Expand Down
Loading
Loading