fix(observability): send individual metrics over UDP to avoid packet size limits
Differentiate flushing logic between transport types to prevent UDP payload truncation while maintaining batched delivery for TCP.
This commit is contained in:
1 file changed
+16
-4
+16
-4
@@ -185,11 +185,23 @@ impl Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self, transport: &mut Transport, batch: &[Metric], host_tag: &str) {
|
fn flush(&self, transport: &mut Transport, batch: &[Metric], host_tag: &str) {
|
||||||
let mut data = String::with_capacity(batch.len() * 300);
|
match transport {
|
||||||
for metric in batch {
|
Transport::Udp(_) => {
|
||||||
self.write_lines(metric, host_tag, &mut data);
|
let mut data = String::with_capacity(300);
|
||||||
|
for metric in batch {
|
||||||
|
data.clear();
|
||||||
|
self.write_lines(metric, host_tag, &mut data);
|
||||||
|
transport.send(&data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Transport::Tcp { .. } => {
|
||||||
|
let mut data = String::with_capacity(batch.len() * 300);
|
||||||
|
for metric in batch {
|
||||||
|
self.write_lines(metric, host_tag, &mut data);
|
||||||
|
}
|
||||||
|
transport.send(&data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
transport.send(&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_lines(&self, metric: &Metric, host_tag: &str, out: &mut String) {
|
fn write_lines(&self, metric: &Metric, host_tag: &str, out: &mut String) {
|
||||||
|
|||||||
Reference in new issue
Block a user