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
+12
@@ -185,12 +185,24 @@ impl Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self, transport: &mut Transport, batch: &[Metric], host_tag: &str) {
|
fn flush(&self, transport: &mut Transport, batch: &[Metric], host_tag: &str) {
|
||||||
|
match transport {
|
||||||
|
Transport::Udp(_) => {
|
||||||
|
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);
|
let mut data = String::with_capacity(batch.len() * 300);
|
||||||
for metric in batch {
|
for metric in batch {
|
||||||
self.write_lines(metric, host_tag, &mut data);
|
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) {
|
||||||
match metric {
|
match metric {
|
||||||
|
|||||||
Reference in new issue
Block a user