From aec593793d3368c58e0bedd6106364c3f645fc91 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Wed, 19 Jul 2023 17:20:44 -0400 Subject: [PATCH] avoid expensive to_string() calls, now using 'get_message()' --- lib/codecs/src/encoding/format/raw_message.rs | 21 ++++--------------- lib/codecs/src/encoding/format/text.rs | 17 +++------------ 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/lib/codecs/src/encoding/format/raw_message.rs b/lib/codecs/src/encoding/format/raw_message.rs index 0807f01234457..1f341295c12ea 100644 --- a/lib/codecs/src/encoding/format/raw_message.rs +++ b/lib/codecs/src/encoding/format/raw_message.rs @@ -2,12 +2,7 @@ use crate::encoding::format::common::get_serializer_schema_requirement; use bytes::{BufMut, BytesMut}; use serde::{Deserialize, Serialize}; use tokio_util::codec::Encoder; -use vector_core::{ - config::{log_schema, DataType}, - event::Event, - schema, -}; -use vrl::path::PathPrefix; +use vector_core::{config::DataType, event::Event, schema}; /// Config used to build a `RawMessageSerializer`. #[derive(Debug, Clone, Default, Deserialize, Serialize)] @@ -50,18 +45,10 @@ impl Encoder for RawMessageSerializer { type Error = vector_common::Error; fn encode(&mut self, event: Event, buffer: &mut BytesMut) -> Result<(), Self::Error> { - if let Some(message_key) = log_schema().message_key() { - let log = event.as_log(); - - if let Some(bytes) = log - .get_by_meaning(message_key.to_string().as_str()) - .or_else(|| log.get((PathPrefix::Event, message_key))) - .map(|value| value.coerce_to_bytes()) - { - buffer.put(bytes); - } + let log = event.as_log(); + if let Some(bytes) = log.get_message().map(|value| value.coerce_to_bytes()) { + buffer.put(bytes); } - Ok(()) } } diff --git a/lib/codecs/src/encoding/format/text.rs b/lib/codecs/src/encoding/format/text.rs index d6c5bb22ed5fe..3820c606da2b7 100644 --- a/lib/codecs/src/encoding/format/text.rs +++ b/lib/codecs/src/encoding/format/text.rs @@ -1,12 +1,7 @@ use crate::encoding::format::common::get_serializer_schema_requirement; use bytes::{BufMut, BytesMut}; use tokio_util::codec::Encoder; -use vector_core::{ - config::{log_schema, DataType}, - event::Event, - schema, -}; -use vrl::path::PathPrefix; +use vector_core::{config::DataType, event::Event, schema}; use crate::MetricTagValues; @@ -70,14 +65,8 @@ impl Encoder for TextSerializer { fn encode(&mut self, event: Event, buffer: &mut BytesMut) -> Result<(), Self::Error> { match event { Event::Log(log) => { - if let Some(message_key) = log_schema().message_key() { - if let Some(bytes) = log - .get_by_meaning(message_key.to_string().as_str()) - .or(log.get((PathPrefix::Event, message_key))) - .map(|value| value.coerce_to_bytes()) - { - buffer.put(bytes); - } + if let Some(bytes) = log.get_message().map(|value| value.coerce_to_bytes()) { + buffer.put(bytes); } } Event::Metric(mut metric) => {