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:
Nils Andreas Svee committed 2026-04-13 17:21:14 +07:00
1 parent 0f902e27a3
commit 699c8782d9
1 file changed
+16 -4
+16 -4
View File
@@ -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) {