Skip to content

Commit f1f0e32

Browse files
authored
chore: Add/update doc for aggregators (#764)
Add / update doc for trace / log / otlp / proxy aggregator.
1 parent 156eba5 commit f1f0e32

7 files changed

Lines changed: 27 additions & 17 deletions

File tree

bottlecap/src/logs/aggregator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use tracing::warn;
33

44
use crate::logs::constants;
55

6+
/// Takes in log payloads and aggregates them into larger batches to be flushed to Datadog.
67
#[derive(Debug, Clone)]
78
pub struct Aggregator {
89
messages: VecDeque<String>,
@@ -41,12 +42,14 @@ impl Aggregator {
4142
}
4243
}
4344

45+
/// Takes in a batch of log payloads.
4446
pub fn add_batch(&mut self, logs: Vec<String>) {
4547
for log in logs {
4648
self.messages.push_back(log);
4749
}
4850
}
4951

52+
/// Returns a batch of log payloads, subject to the max content size.
5053
pub fn get_batch(&mut self) -> Vec<u8> {
5154
self.buffer.extend(b"[");
5255

bottlecap/src/otlp/agent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,18 @@ impl Agent {
176176

177177
match trace_tx.send(send_data_builder).await {
178178
Ok(()) => {
179-
debug!("OTLP | Successfully buffered traces to be flushed.");
179+
debug!("OTLP | Successfully buffered traces to be aggregated.");
180180
(
181181
StatusCode::OK,
182182
json!({"rate_by_service":{"service:,env:":1}}).to_string(),
183183
)
184184
.into_response()
185185
}
186186
Err(err) => {
187-
error!("OTLP | Error sending traces to the trace flusher: {err}");
187+
error!("OTLP | Error sending traces to the trace aggregator: {err}");
188188
(
189189
StatusCode::INTERNAL_SERVER_ERROR,
190-
json!({ "message": format!("Error sending traces to the trace flusher: {err}") }).to_string()
190+
json!({ "message": format!("Error sending traces to the trace aggregator: {err}") }).to_string()
191191
).into_response()
192192
}
193193
}

bottlecap/src/traces/proxy_aggregator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct ProxyRequest {
77
pub target_url: String,
88
}
99

10+
/// Takes in individual proxy requests and aggregates them into batches to be flushed to Datadog.
1011
pub struct Aggregator {
1112
queue: Vec<ProxyRequest>,
1213
}
@@ -20,10 +21,12 @@ impl Default for Aggregator {
2021
}
2122

2223
impl Aggregator {
24+
/// Takes in an individual proxy request.
2325
pub fn add(&mut self, request: ProxyRequest) {
2426
self.queue.push(request);
2527
}
2628

29+
/// Returns a batch of proxy requests.
2730
pub fn get_batch(&mut self) -> Vec<ProxyRequest> {
2831
std::mem::take(&mut self.queue)
2932
}

bottlecap/src/traces/stats_aggregator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl Default for StatsAggregator {
3434
}
3535
}
3636

37+
/// Takes in individual trace stats payloads and aggregates them into batches to be flushed to Datadog.
3738
impl StatsAggregator {
3839
#[allow(dead_code)]
3940
#[allow(clippy::must_use_candidate)]
@@ -45,10 +46,12 @@ impl StatsAggregator {
4546
}
4647
}
4748

49+
/// Takes in an individual trace stats payload.
4850
pub fn add(&mut self, payload: ClientStatsPayload) {
4951
self.queue.push_back(payload);
5052
}
5153

54+
/// Returns a batch of trace stats payloads, subject to the max content size.
5255
pub fn get_batch(&mut self) -> Vec<ClientStatsPayload> {
5356
let mut batch_size = 0;
5457

bottlecap/src/traces/stats_processor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ impl StatsProcessor for ServerlessStatsProcessor {
9393
return Ok((StatusCode::INTERNAL_SERVER_ERROR, error_msg).into_response());
9494
};
9595

96-
// send trace payload to our trace flusher
96+
// send trace stats payload to our stats aggregator
9797
match tx.send(stats).await {
9898
Ok(()) => {
99-
debug!("Successfully buffered stats to be flushed.");
99+
debug!("Successfully buffered stats to be aggregated.");
100100
Ok((
101101
StatusCode::ACCEPTED,
102-
"Successfully buffered stats to be flushed.",
102+
"Successfully buffered stats to be aggregated.",
103103
)
104104
.into_response())
105105
}
106106
Err(err) => {
107-
let error_msg = format!("Error sending stats to the stats flusher: {err}");
107+
let error_msg = format!("Error sending stats to the stats aggregator: {err}");
108108
error!("{}", error_msg);
109109
Ok((StatusCode::INTERNAL_SERVER_ERROR, error_msg).into_response())
110110
}

bottlecap/src/traces/trace_agent.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,13 @@ impl TraceAgent {
119119
invocation_processor: Arc<Mutex<InvocationProcessor>>,
120120
tags_provider: Arc<provider::Provider>,
121121
) -> TraceAgent {
122-
// setup a channel to send processed traces to our flusher. tx is passed through each
122+
// Set up a channel to send processed traces to our trace aggregator. tx is passed through each
123123
// endpoint_handler to the trace processor, which uses it to send de-serialized
124-
// processed trace payloads to our trace flusher.
124+
// processed trace payloads to our trace aggregator.
125125
let (trace_tx, mut trace_rx): (Sender<SendDataBuilderInfo>, Receiver<SendDataBuilderInfo>) =
126126
mpsc::channel(TRACER_PAYLOAD_CHANNEL_BUFFER_SIZE);
127127

128-
// start our trace flusher. receives trace payloads and handles buffering + deciding when to
129-
// flush to backend.
130-
128+
// Start the trace aggregator, which receives and buffers trace payloads to be consumed by the trace flusher.
131129
tokio::spawn(async move {
132130
while let Some(tracer_payload_info) = trace_rx.recv().await {
133131
let mut aggregator = trace_aggregator.lock().await;
@@ -151,13 +149,13 @@ impl TraceAgent {
151149
pub async fn start(&self) -> Result<(), Box<dyn std::error::Error>> {
152150
let now = Instant::now();
153151

154-
// channels to send processed stats to our stats flusher.
152+
// Set up a channel to send processed stats to our stats aggregator.
155153
let (stats_tx, mut stats_rx): (
156154
Sender<pb::ClientStatsPayload>,
157155
Receiver<pb::ClientStatsPayload>,
158156
) = mpsc::channel(STATS_PAYLOAD_CHANNEL_BUFFER_SIZE);
159157

160-
// Receive stats payload and send it to the aggregator
158+
// Start the stats aggregator, which receives and buffers stats payloads to be consumed by the stats flusher.
161159
let stats_aggregator = self.stats_aggregator.clone();
162160
tokio::spawn(async move {
163161
while let Some(stats_payload) = stats_rx.recv().await {
@@ -500,12 +498,12 @@ impl TraceAgent {
500498
)
501499
.await;
502500

503-
// send trace payload to our trace flusher
501+
// send trace payload to our trace aggregator
504502
match trace_tx.send(send_data).await {
505-
Ok(()) => success_response("Successfully buffered traces to be flushed."),
503+
Ok(()) => success_response("Successfully buffered traces to be aggregated."),
506504
Err(err) => error_response(
507505
StatusCode::INTERNAL_SERVER_ERROR,
508-
format!("Error sending traces to the trace flusher: {err}"),
506+
format!("Error sending traces to the trace aggregator: {err}"),
509507
),
510508
}
511509
}

bottlecap/src/traces/trace_aggregator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ impl SendDataBuilderInfo {
2020
}
2121
}
2222

23+
/// Takes in individual trace payloads and aggregates them into batches to be flushed to Datadog.
2324
#[allow(clippy::module_name_repetitions)]
2425
pub struct TraceAggregator {
2526
queue: VecDeque<SendDataBuilderInfo>,
@@ -48,10 +49,12 @@ impl TraceAggregator {
4849
}
4950
}
5051

52+
/// Takes in an individual trace payload.
5153
pub fn add(&mut self, payload_info: SendDataBuilderInfo) {
5254
self.queue.push_back(payload_info);
5355
}
5456

57+
/// Returns a batch of trace payloads, subject to the max content size.
5558
pub fn get_batch(&mut self) -> Vec<SendDataBuilder> {
5659
let mut batch_size = 0;
5760

0 commit comments

Comments
 (0)