diff --git a/src/sinks/loki/event.rs b/src/sinks/loki/event.rs index 76389e2c64fb9d..1aede42e359547 100644 --- a/src/sinks/loki/event.rs +++ b/src/sinks/loki/event.rs @@ -139,21 +139,6 @@ impl ByteSizeOf for LokiEvent { } } -/// This implementation approximates the `Serialize` implementation below, without any allocations. -impl EstimatedJsonEncodedSizeOf for LokiEvent { - fn estimated_json_encoded_size_of(&self) -> JsonSize { - static BRACKETS_SIZE: JsonSize = JsonSize::new(2); - static COLON_SIZE: JsonSize = JsonSize::new(1); - static QUOTES_SIZE: JsonSize = JsonSize::new(2); - - BRACKETS_SIZE - + QUOTES_SIZE - + self.timestamp.estimated_json_encoded_size_of() - + COLON_SIZE - + self.event.estimated_json_encoded_size_of() - } -} - impl Serialize for LokiEvent { fn serialize(&self, serializer: S) -> Result where @@ -172,6 +157,7 @@ pub struct LokiRecord { pub partition: PartitionKey, pub labels: Labels, pub event: LokiEvent, + pub json_byte_size: JsonSize, pub finalizers: EventFinalizers, } @@ -187,7 +173,7 @@ impl ByteSizeOf for LokiRecord { impl EstimatedJsonEncodedSizeOf for LokiRecord { fn estimated_json_encoded_size_of(&self) -> JsonSize { - self.event.estimated_json_encoded_size_of() + self.json_byte_size } } diff --git a/src/sinks/loki/sink.rs b/src/sinks/loki/sink.rs index 766526bb12bff5..b5871d4e876e45 100644 --- a/src/sinks/loki/sink.rs +++ b/src/sinks/loki/sink.rs @@ -12,7 +12,7 @@ use vector_core::{ partition::Partitioner, sink::StreamSink, stream::BatcherSettings, - ByteSizeOf, + ByteSizeOf, EstimatedJsonEncodedSizeOf, }; use super::{ @@ -268,6 +268,7 @@ impl EventEncoder { pub(super) fn encode_event(&mut self, mut event: Event) -> Option { let tenant_id = self.key_partitioner.partition(&event); let finalizers = event.take_finalizers(); + let json_byte_size = event.estimated_json_encoded_size_of(); let mut labels = self.build_labels(&event); self.remove_label_fields(&mut event); @@ -302,6 +303,7 @@ impl EventEncoder { }, partition, finalizers, + json_byte_size, }) } }