Skip to content

Commit 88da8cb

Browse files
authored
refactor(value): Preserve known UTF-8 as strings (vectordotdev#26608)
1 parent be6be60 commit 88da8cb

33 files changed

Lines changed: 188 additions & 167 deletions

File tree

‎lib/codecs/src/decoding/format/gelf.rs‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,38 +316,36 @@ mod tests {
316316

317317
assert_eq!(
318318
log.get(event_path!(VERSION)),
319-
Some(&Value::Bytes(Bytes::from_static(b"1.1")))
319+
Some(&Value::from_static_str("1.1"))
320320
);
321321
assert_eq!(
322322
log.get(event_path!(HOST)),
323-
Some(&Value::Bytes(Bytes::from_static(b"example.org")))
323+
Some(&Value::from_static_str("example.org"))
324324
);
325325
assert_eq!(
326326
log.get(log_schema().message_key_target_path().unwrap()),
327-
Some(&Value::Bytes(Bytes::from_static(
328-
b"A short message that helps you identify what is going on"
329-
)))
327+
Some(&Value::from_static_str(
328+
"A short message that helps you identify what is going on"
329+
))
330330
);
331331
assert_eq!(
332332
log.get(event_path!(FULL_MESSAGE)),
333-
Some(&Value::Bytes(Bytes::from_static(
334-
b"Backtrace here\n\nmore stuff"
335-
)))
333+
Some(&Value::from_static_str("Backtrace here\n\nmore stuff"))
336334
);
337335
let dt = DateTime::from_timestamp(1_385_053_862, 307_200_000).expect("invalid timestamp");
338336
assert_eq!(log.get(event_path!(TIMESTAMP)), Some(&Value::Timestamp(dt)));
339337
assert_eq!(log.get(event_path!(LEVEL)), Some(&Value::Integer(1)));
340338
assert_eq!(
341339
log.get(event_path!(FACILITY)),
342-
Some(&Value::Bytes(Bytes::from_static(b"foo")))
340+
Some(&Value::from_static_str("foo"))
343341
);
344342
assert_eq!(
345343
log.get(event_path!(LINE)),
346344
Some(&Value::Float(ordered_float::NotNan::new(42.0).unwrap()))
347345
);
348346
assert_eq!(
349347
log.get(event_path!(FILE)),
350-
Some(&Value::Bytes(Bytes::from_static(b"/tmp/bar")))
348+
Some(&Value::from_static_str("/tmp/bar"))
351349
);
352350
assert_eq!(
353351
log.get(event_path!(add_on_int_in)),
@@ -357,7 +355,7 @@ mod tests {
357355
);
358356
assert_eq!(
359357
log.get(event_path!(add_on_str_in)),
360-
Some(&Value::Bytes(Bytes::from_static(b"A Space Odyssey")))
358+
Some(&Value::from_static_str("A Space Odyssey"))
361359
);
362360
}
363361

@@ -486,7 +484,7 @@ mod tests {
486484

487485
assert_eq!(
488486
log.get(event_path!(VERSION)),
489-
Some(&Value::Bytes(Bytes::from_static(b"1.0")))
487+
Some(&Value::from_static_str("1.0"))
490488
);
491489

492490
assert_eq!(

‎lib/codecs/src/decoding/format/syslog.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl Deserializer for SyslogDeserializer {
297297
syslog_loose::parse_message_with_year_exact(line, resolve_year, Variant::Either)?;
298298

299299
let log = if let (Some(source), LogNamespace::Vector) = (self.source, log_namespace) {
300-
let mut log = LogEvent::from(Value::Bytes(Bytes::from(parsed.msg.to_string())));
300+
let mut log = LogEvent::from(Value::from(parsed.msg));
301301
insert_metadata_fields_from_syslog(&mut log, source, parsed, log_namespace);
302302
log
303303
} else {

‎lib/opentelemetry-proto/src/common.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::proto::common::v1::{AnyValue, ArrayValue, KeyValue, any_value::Value
88
impl From<PBValue> for Value {
99
fn from(av: PBValue) -> Self {
1010
match av {
11-
PBValue::StringValue(v) => Value::Bytes(Bytes::from(v)),
11+
PBValue::StringValue(v) => Value::from(v),
1212
PBValue::BoolValue(v) => Value::Boolean(v),
1313
PBValue::IntValue(v) => Value::Integer(v),
1414
PBValue::DoubleValue(v) => NotNan::new(v).map_or(Value::Null, Value::Float),

‎lib/opentelemetry-proto/src/logs.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use bytes::Bytes;
21
use chrono::{DateTime, TimeZone, Utc};
32
use vector_core::{
43
config::{LegacyKey, LogNamespace, log_schema},
@@ -147,7 +146,7 @@ impl ResourceLog {
147146
&mut log,
148147
Some(LegacyKey::Overwrite(path!(TRACE_ID_KEY))),
149148
path!(TRACE_ID_KEY),
150-
Bytes::from(to_hex(&self.log_record.trace_id)),
149+
Value::from(to_hex(&self.log_record.trace_id)),
151150
);
152151
}
153152
if !self.log_record.span_id.is_empty() {
@@ -156,7 +155,7 @@ impl ResourceLog {
156155
&mut log,
157156
Some(LegacyKey::Overwrite(path!(SPAN_ID_KEY))),
158157
path!(SPAN_ID_KEY),
159-
Bytes::from(to_hex(&self.log_record.span_id)),
158+
Value::from(to_hex(&self.log_record.span_id)),
160159
);
161160
}
162161
if !self.log_record.severity_text.is_empty() {
@@ -240,7 +239,7 @@ impl ResourceLog {
240239
&mut log,
241240
log_schema().source_type_key(),
242241
path!("source_type"),
243-
Bytes::from_static(SOURCE_NAME.as_bytes()),
242+
Value::from_static_str(SOURCE_NAME),
244243
);
245244
if log_namespace == LogNamespace::Vector {
246245
log.metadata_mut()

‎lib/vector-core/src/config/mod.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::{collections::HashMap, fmt, num::NonZeroUsize, sync::Arc};
22

33
use bitmask_enum::bitmask;
4-
use bytes::Bytes;
54
use chrono::{DateTime, Utc};
65

76
mod global_options;
@@ -501,7 +500,7 @@ impl LogNamespace {
501500
log,
502501
log_schema().source_type_key(),
503502
path!("source_type"),
504-
Bytes::from_static(source_name.as_bytes()),
503+
Value::from_static_str(source_name),
505504
);
506505
self.insert_vector_metadata(
507506
log,

‎lib/vector-core/src/event/log_event.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ impl From<&tracing::Event<'_>> for LogEvent {
792792
log.insert(
793793
&TRACING_TARGET_PATHS.kind,
794794
if meta.is_event() {
795-
Value::Bytes("event".to_string().into())
795+
Value::from_static_str("event")
796796
} else if meta.is_span() {
797-
Value::Bytes("span".to_string().into())
797+
Value::from_static_str("span")
798798
} else {
799799
Value::Null
800800
},
@@ -803,7 +803,7 @@ impl From<&tracing::Event<'_>> for LogEvent {
803803
log.insert(
804804
&TRACING_TARGET_PATHS.module_path,
805805
meta.module_path()
806-
.map_or(Value::Null, |mp| Value::Bytes(mp.to_string().into())),
806+
.map_or(Value::Null, |mp| Value::from(mp.to_string())),
807807
);
808808
log.insert(&TRACING_TARGET_PATHS.target, meta.target().to_string());
809809
log

‎lib/vector-vrl/metrics/src/common.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub(crate) fn metric_into_vrl(value: &Metric) -> Value {
150150
Value::Array(
151151
v.iter()
152152
.filter_map(|v| {
153-
v.map(ToString::to_string).map(Into::into).map(Value::Bytes)
153+
v.map(ToString::to_string).map(Value::from)
154154
})
155155
.collect(),
156156
),

‎src/conditions/datadog_search.rs‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{borrow::Cow, str::FromStr};
22

3-
use bytes::Bytes;
43
use vector_lib::{
54
configurable::configurable_component,
65
event::{Event, EventRef, LogEvent, Value},
@@ -140,17 +139,13 @@ impl Filter<LogEvent> for EventFilter {
140139
Field::Reserved(field) if field == "tags" => {
141140
let to_match = to_match.to_owned();
142141

143-
array_match_multiple(vec!["ddtags", "tags"], move |values| {
144-
values.contains(&Value::Bytes(Bytes::copy_from_slice(to_match.as_bytes())))
145-
})
142+
any_string_match_multiple(vec!["ddtags", "tags"], move |value| value == to_match)
146143
}
147144
// Individual tags are compared by element key:value.
148145
Field::Tag(tag) => {
149-
let value_bytes = Value::Bytes(format!("{tag}:{to_match}").into());
146+
let to_match = format!("{tag}:{to_match}");
150147

151-
array_match_multiple(vec!["ddtags", "tags"], move |values| {
152-
values.contains(&value_bytes)
153-
})
148+
any_string_match_multiple(vec!["ddtags", "tags"], move |value| value == to_match)
154149
}
155150
// A literal "source" field should string match in "source" and "ddsource" fields (OR condition).
156151
Field::Reserved(field) if field == "source" => {
@@ -1648,6 +1643,28 @@ mod test {
16481643
test_filter(EventFilter, vector_lib::event::Event::into_log);
16491644
}
16501645

1646+
#[test]
1647+
fn tag_equality_matches_byte_values() {
1648+
for query in ["tags:foo", "env:prod"] {
1649+
let config: DatadogSearchConfig = query.parse().unwrap();
1650+
let runner = DatadogSearchRunner::try_from(&config).unwrap();
1651+
let mut log = LogEvent::default();
1652+
log.insert(
1653+
vrl::event_path!("tags"),
1654+
Value::Array(vec![Value::Bytes(
1655+
if query == "tags:foo" {
1656+
"foo"
1657+
} else {
1658+
"env:prod"
1659+
}
1660+
.into(),
1661+
)]),
1662+
);
1663+
1664+
assert!(runner.matches(&Event::Log(log)), "query: {query}");
1665+
}
1666+
}
1667+
16511668
#[test]
16521669
fn generate_config() {
16531670
crate::test_util::test_generate_config::<DatadogSearchConfig>();

‎src/enrichment_tables/memory/bloom_table.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77

88
use async_trait::async_trait;
99
use bloomy::{BloomFilter, bloom};
10-
use bytes::Bytes;
1110
use futures::{
1211
Stream, StreamExt,
1312
stream::{self, BoxStream},
@@ -164,10 +163,7 @@ impl Table for BloomMemoryTable {
164163
include_key_metric_tag: self.config.internal_metrics.include_key_tag
165164
});
166165
let result = ObjectMap::from([
167-
(
168-
KeyString::from("key"),
169-
Value::Bytes(Bytes::copy_from_slice(key.as_bytes())),
170-
),
166+
(KeyString::from("key"), Value::from(key)),
171167
(KeyString::from("value"), Value::Null),
172168
]);
173169
Ok(vec![result])

‎src/enrichment_tables/memory/cuckoo_table.rs‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::{
1414
};
1515

1616
use async_trait::async_trait;
17-
use bytes::Bytes;
1817
use cuckoo_clock::{
1918
CuckooFilter, ExportableRandomState, InsertValues, LookupValues,
2019
config::{CounterConfig, CuckooConfiguration, LruAgingStrategy, LruConfig, TtlConfig},
@@ -646,16 +645,10 @@ impl Table for CuckooMemoryTable {
646645
include_key_metric_tag: self.config.internal_metrics.include_key_tag
647646
});
648647
let mut result = ObjectMap::from([
649-
(
650-
KeyString::from("key"),
651-
Value::Bytes(Bytes::copy_from_slice(key.as_bytes())),
652-
),
648+
(KeyString::from("key"), Value::from(key)),
653649
(
654650
KeyString::from("fingerprint"),
655-
Value::Bytes(Bytes::from(format!(
656-
"{:X}",
657-
associated_data.get_fingerprint()
658-
))),
651+
Value::from(format!("{:X}", associated_data.get_fingerprint())),
659652
),
660653
(KeyString::from("value"), Value::Null),
661654
]);

0 commit comments

Comments
 (0)