Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loki sink): use json size of unencoded event #17572

Merged
merged 1 commit into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/sinks/loki/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -172,6 +157,7 @@ pub struct LokiRecord {
pub partition: PartitionKey,
pub labels: Labels,
pub event: LokiEvent,
pub json_byte_size: JsonSize,
pub finalizers: EventFinalizers,
}

Expand All @@ -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
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/sinks/loki/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use vector_core::{
partition::Partitioner,
sink::StreamSink,
stream::BatcherSettings,
ByteSizeOf,
ByteSizeOf, EstimatedJsonEncodedSizeOf,
};

use super::{
Expand Down Expand Up @@ -268,6 +268,7 @@ impl EventEncoder {
pub(super) fn encode_event(&mut self, mut event: Event) -> Option<LokiRecord> {
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);

Expand Down Expand Up @@ -302,6 +303,7 @@ impl EventEncoder {
},
partition,
finalizers,
json_byte_size,
})
}
}
Expand Down