Skip to content

Commit 43b3c3e

Browse files
committed
add missing file
1 parent d35bcf4 commit 43b3c3e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/sinks/statsd/batch.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use vector_core::{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.
5+
const EST_OVERHEAD_LEN: usize = 4;
6+
7+
#[derive(Default)]
8+
pub(super) struct StatsdBatchSizer;
9+
10+
impl 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+
}

0 commit comments

Comments
 (0)