vector/sinks/statsd/
batch.rs

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