vector/sinks/statsd/
batch.rs

1use vector_lib::{event::Metric, stream::batcher::limiter::ItemBatchSize};
2
3// This accounts for the separators, the metric type string, the length of the value itself. It can
4// never be too small, as the above values will always take at least 4 bytes.
5const EST_OVERHEAD_LEN: usize = 4;
6
7#[derive(Default)]
8pub(super) struct StatsdBatchSizer;
9
10impl ItemBatchSize<Metric> for StatsdBatchSizer {
11    fn size(&self, item: &Metric) -> usize {
12        // Metric name.
13        item.series().name().name().len()
14        // Metric namespace, with an additional 1 to account for the namespace separator.
15        + item.series().name().namespace().map(|s| s.len() + 1).unwrap_or(0)
16        // Metric tags, with an additional 1 per tag to account for the tag key/value separator.
17        + item.series().tags().map(|t| {
18            t.iter_all().map(|(k, v)| {
19                k.len() + 1 + v.map(|v| v.len()).unwrap_or(0)
20            })
21            .sum()
22        })
23        .unwrap_or(0)
24        // Estimated overhead (separators, metric value, etc)
25        + EST_OVERHEAD_LEN
26    }
27}