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

chore(deps): Update VRL to use KeyString type wrapper #19069

Merged
merged 3 commits into from
Nov 8, 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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ members = [
]

[workspace.dependencies]
vrl = { version = "0.8.1", features = ["cli"] }

pin-project = { version = "1.1.3", default-features = false }
vrl = { git = "https://github.com/vectordotdev/vrl", rev = "37319dfca17dc5d7637b24455199029cc30eb128", features = ["arbitrary", "cli", "test", "test_framework"] }
pront marked this conversation as resolved.
Show resolved Hide resolved

[dependencies]
vrl.workspace = true
pin-project.workspace = true
vrl.workspace = true

# Internal libs
dnsmsg-parser = { path = "lib/dnsmsg-parser", optional = true }
Expand Down Expand Up @@ -362,7 +361,7 @@ tokio = { version = "1.33.0", features = ["test-util"] }
tokio-test = "0.4.3"
tower-test = "0.4.0"
vector-lib = { path = "lib/vector-lib", default-features = false, features = ["vrl", "test"] }
vrl = { version = "0.8.1", features = ["cli", "test", "test_framework", "arbitrary"] }
vrl = { git = "https://github.com/vectordotdev/vrl", rev = "37319dfca17dc5d7637b24455199029cc30eb128", features = ["cli", "test", "test_framework", "arbitrary"] }

wiremock = "0.5.21"
zstd = { version = "0.13.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion lib/codecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ futures = { version = "0.3", default-features = false }
indoc = { version = "2", default-features = false }
tokio = { version = "1", features = ["test-util"] }
similar-asserts = "1.5.0"
vrl = { version = "0.8.1", features = ["cli", "test", "test_framework", "arbitrary"] }
vector-core = { path = "../vector-core", default-features = false, features = ["test"] }
vrl.workspace = true

[features]
syslog = ["dep:syslog_loose"]
11 changes: 5 additions & 6 deletions lib/codecs/src/decoding/format/protobuf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::BTreeMap;
use std::path::PathBuf;

use bytes::Bytes;
Expand All @@ -14,7 +13,7 @@ use vector_core::{
event::Event,
schema,
};
use vrl::value::Kind;
use vrl::value::{Kind, ObjectMap};

use crate::common::protobuf::get_message_descriptor;

Expand Down Expand Up @@ -171,11 +170,11 @@ fn to_vrl(
}
}
prost_reflect::Value::Message(v) => {
let mut obj_map = BTreeMap::new();
let mut obj_map = ObjectMap::new();
for field_desc in v.descriptor().fields() {
let field_value = v.get_field(&field_desc);
let out = to_vrl(field_value.as_ref(), Some(&field_desc))?;
obj_map.insert(field_desc.name().to_string(), out);
obj_map.insert(field_desc.name().into(), out);
}
vrl::value::Value::from(obj_map)
}
Expand Down Expand Up @@ -206,11 +205,11 @@ fn to_vrl(
field_descriptor
)
})?
.to_string(),
.into(),
to_vrl(kv.1, Some(&message_desc.map_entry_value_field()))?,
))
})
.collect::<vector_common::Result<BTreeMap<String, _>>>()?,
.collect::<vector_common::Result<ObjectMap>>()?,
)
} else {
Err("Expected valid field descriptor")?
Expand Down
17 changes: 8 additions & 9 deletions lib/codecs/src/decoding/format/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use derivative::Derivative;
use lookup::{event_path, owned_value_path, OwnedTargetPath, OwnedValuePath};
use smallvec::{smallvec, SmallVec};
use std::borrow::Cow;
use std::collections::BTreeMap;
use syslog_loose::{IncompleteDate, Message, ProcId, Protocol, Variant};
use vector_config::configurable_component;
use vector_core::config::{LegacyKey, LogNamespace};
use vector_core::{
config::{log_schema, DataType},
event::{Event, LogEvent, Value},
event::{Event, LogEvent, ObjectMap, Value},
schema,
};
use vrl::value::{kind::Collection, Kind};
Expand Down Expand Up @@ -292,7 +291,7 @@ impl Deserializer for SyslogDeserializer {
log
}
_ => {
let mut log = LogEvent::from(Value::Object(BTreeMap::new()));
let mut log = LogEvent::from(Value::Object(ObjectMap::new()));
insert_fields_from_syslog(&mut log, parsed, log_namespace);
log
}
Expand Down Expand Up @@ -402,15 +401,15 @@ fn insert_metadata_fields_from_syslog(
);
}

let mut sdata: BTreeMap<String, Value> = BTreeMap::new();
let mut sdata = ObjectMap::new();
for element in parsed.structured_data.into_iter() {
let mut data: BTreeMap<String, Value> = BTreeMap::new();
let mut data = ObjectMap::new();

for (name, value) in element.params() {
data.insert(name.to_string(), value.into());
data.insert(name.to_string().into(), value.into());
}

sdata.insert(element.id.to_string(), data.into());
sdata.insert(element.id.into(), data.into());
}

log_namespace.insert_source_metadata(
Expand Down Expand Up @@ -474,9 +473,9 @@ fn insert_fields_from_syslog(
}

for element in parsed.structured_data.into_iter() {
let mut sdata: BTreeMap<String, Value> = BTreeMap::new();
let mut sdata = ObjectMap::new();
for (name, value) in element.params() {
sdata.insert(name.to_string(), value.into());
sdata.insert(name.to_string().into(), value.into());
}
log.insert(event_path!(element.id), sdata);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/codecs/src/encoding/format/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,20 @@ mod tests {
use chrono::DateTime;
use ordered_float::NotNan;
use vector_common::btreemap;
use vector_core::event::{LogEvent, Value};
use vector_core::event::{LogEvent, ObjectMap, Value};

use super::*;

fn make_event_with_fields(field_data: Vec<(&str, &str)>) -> (Vec<ConfigTargetPath>, Event) {
let mut fields: Vec<ConfigTargetPath> = std::vec::Vec::new();
let mut tree = std::collections::BTreeMap::new();
let mut tree = ObjectMap::new();

for (field_name, field_value) in field_data.iter() {
let field = ConfigTargetPath::try_from(field_name.to_string()).unwrap();
for (field_name, field_value) in field_data.into_iter() {
let field = ConfigTargetPath::try_from(field_name.clone()).unwrap();
fields.push(field);

let field_value = Value::from(field_value.to_string());
tree.insert(field_name.to_string().clone(), field_value);
tree.insert(field_name.into(), field_value);
}

let event = Event::Log(LogEvent::from(tree));
Expand Down
23 changes: 9 additions & 14 deletions lib/codecs/src/encoding/format/gelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use snafu::Snafu;
use tokio_util::codec::Encoder;
use vector_core::{
config::{log_schema, DataType},
event::Event,
event::LogEvent,
event::Value,
event::{Event, KeyString, LogEvent, Value},
schema,
};

Expand All @@ -26,7 +24,7 @@ use vector_core::{
#[derive(Debug, Snafu)]
pub enum GelfSerializerError {
#[snafu(display(r#"LogEvent does not contain required field: "{}""#, field))]
MissingField { field: String },
MissingField { field: KeyString },
#[snafu(display(
r#"LogEvent contains a value with an invalid type. field = "{}" type = "{}" expected type = "{}""#,
field,
Expand Down Expand Up @@ -194,9 +192,11 @@ fn coerce_field_names_and_values(
_ => {
// additional fields must be only word chars, dashes and periods.
if !VALID_FIELD_REGEX.is_match(field) {
return MissingFieldSnafu { field }
.fail()
.map_err(|e| e.to_string().into());
return MissingFieldSnafu {
field: field.clone(),
}
.fail()
.map_err(|e| e.to_string().into());
}

// additional field values must be only strings or numbers
Expand Down Expand Up @@ -238,20 +238,15 @@ fn to_gelf_event(log: LogEvent) -> vector_common::Result<LogEvent> {

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;

use crate::encoding::SerializerConfig;

use super::*;
use chrono::NaiveDateTime;
use vector_core::event::{Event, EventMetadata};
use vrl::btreemap;
use vrl::value::Value;
use vrl::value::{ObjectMap, Value};

fn do_serialize(
expect_success: bool,
event_fields: BTreeMap<String, Value>,
) -> Option<serde_json::Value> {
fn do_serialize(expect_success: bool, event_fields: ObjectMap) -> Option<serde_json::Value> {
let config = GelfSerializerConfig::new();
let mut serializer = config.build();
let event: Event = LogEvent::from_map(event_fields, EventMetadata::default()).into();
Expand Down
2 changes: 1 addition & 1 deletion lib/codecs/src/encoding/format/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn convert_value_raw(
for (key, val) in o.into_iter() {
match convert_value(&value_field, val) {
Ok(prost_val) => {
map.insert(MapKey::String(key), prost_val);
map.insert(MapKey::String(key.into()), prost_val);
}
Err(e) => return Err(e),
}
Expand Down
4 changes: 2 additions & 2 deletions lib/enrichment/src/find_enrichment_table_records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Function for FindEnrichmentTableRecords {
#[derive(Debug, Clone)]
pub struct FindEnrichmentTableRecordsFn {
table: String,
condition: BTreeMap<String, expression::Expr>,
condition: BTreeMap<KeyString, expression::Expr>,
index: Option<IndexHandle>,
select: Option<Box<dyn Expression>>,
case_sensitive: Case,
Expand Down Expand Up @@ -203,7 +203,7 @@ mod tests {
};

let tz = TimeZone::default();
let object: Value = BTreeMap::new().into();
let object: Value = ObjectMap::new().into();
let mut target = TargetValue {
value: object,
metadata: value!({}),
Expand Down
2 changes: 1 addition & 1 deletion lib/enrichment/src/get_enrichment_table_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Function for GetEnrichmentTableRecord {
#[derive(Debug, Clone)]
pub struct GetEnrichmentTableRecordFn {
table: String,
condition: BTreeMap<String, expression::Expr>,
condition: BTreeMap<KeyString, expression::Expr>,
index: Option<IndexHandle>,
select: Option<Box<dyn Expression>>,
case_sensitive: Case,
Expand Down
7 changes: 3 additions & 4 deletions lib/enrichment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ pub mod tables;
#[cfg(test)]
mod test_util;
mod vrl_util;
use std::collections::BTreeMap;

use dyn_clone::DynClone;
pub use tables::{TableRegistry, TableSearch};
use vrl::compiler::Function;
use vrl::value::Value;
use vrl::value::{ObjectMap, Value};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct IndexHandle(pub usize);
Expand Down Expand Up @@ -49,7 +48,7 @@ pub trait Table: DynClone {
condition: &'a [Condition<'a>],
select: Option<&[String]>,
index: Option<IndexHandle>,
) -> Result<BTreeMap<String, Value>, String>;
) -> Result<ObjectMap, String>;

/// Search the enrichment table data with the given condition.
/// All conditions must match (AND).
Expand All @@ -60,7 +59,7 @@ pub trait Table: DynClone {
condition: &'a [Condition<'a>],
select: Option<&[String]>,
index: Option<IndexHandle>,
) -> Result<Vec<BTreeMap<String, Value>>, String>;
) -> Result<Vec<ObjectMap>, String>;

/// Hints to the enrichment table what data is going to be searched to allow it to index the
/// data in advance.
Expand Down
14 changes: 7 additions & 7 deletions lib/enrichment/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
//! can be searched.

use std::{
collections::{BTreeMap, HashMap},
collections::HashMap,
sync::{Arc, Mutex},
};

use arc_swap::ArcSwap;
use vrl::value::Value;
use vrl::value::ObjectMap;

use super::{Condition, IndexHandle, Table};
use crate::Case;
Expand Down Expand Up @@ -205,7 +205,7 @@ impl TableSearch {
condition: &'a [Condition<'a>],
select: Option<&[String]>,
index: Option<IndexHandle>,
) -> Result<BTreeMap<String, Value>, String> {
) -> Result<ObjectMap, String> {
let tables = self.0.load();
if let Some(ref tables) = **tables {
match tables.get(table) {
Expand All @@ -227,7 +227,7 @@ impl TableSearch {
condition: &'a [Condition<'a>],
select: Option<&[String]>,
index: Option<IndexHandle>,
) -> Result<Vec<BTreeMap<String, Value>>, String> {
) -> Result<Vec<ObjectMap>, String> {
let tables = self.0.load();
if let Some(ref tables) = **tables {
match tables.get(table) {
Expand Down Expand Up @@ -357,7 +357,7 @@ mod tests {
registry.finish_load();

assert_eq!(
Ok(BTreeMap::from([("field".into(), Value::from("result"))])),
Ok(ObjectMap::from([("field".into(), Value::from("result"))])),
tables_search.find_table_row(
"dummy1",
Case::Sensitive,
Expand Down Expand Up @@ -410,8 +410,8 @@ mod tests {
// After we finish load there are no tables in the list
assert!(registry.table_ids().is_empty());

let mut new_data = BTreeMap::new();
new_data.insert("thing".to_string(), Value::Null);
let mut new_data = ObjectMap::new();
new_data.insert("thing".into(), Value::Null);

let mut tables: TableMap = HashMap::new();
tables.insert(
Expand Down
14 changes: 7 additions & 7 deletions lib/enrichment/src/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{
collections::{BTreeMap, HashMap},
collections::HashMap,
sync::{Arc, Mutex},
};

use vrl::value::Value;
use vrl::value::{ObjectMap, Value};

use crate::{Case, Condition, IndexHandle, Table, TableRegistry};

#[derive(Debug, Clone)]
pub(crate) struct DummyEnrichmentTable {
data: BTreeMap<String, Value>,
data: ObjectMap,
indexes: Arc<Mutex<Vec<Vec<String>>>>,
}

Expand All @@ -20,12 +20,12 @@ impl DummyEnrichmentTable {

pub(crate) fn new_with_index(indexes: Arc<Mutex<Vec<Vec<String>>>>) -> Self {
Self {
data: BTreeMap::from([("field".to_string(), Value::from("result"))]),
data: ObjectMap::from([("field".into(), Value::from("result"))]),
indexes,
}
}

pub(crate) fn new_with_data(data: BTreeMap<String, Value>) -> Self {
pub(crate) fn new_with_data(data: ObjectMap) -> Self {
Self {
data,
indexes: Default::default(),
Expand All @@ -40,7 +40,7 @@ impl Table for DummyEnrichmentTable {
_condition: &[Condition],
_select: Option<&[String]>,
_index: Option<IndexHandle>,
) -> Result<BTreeMap<String, Value>, String> {
) -> Result<ObjectMap, String> {
Ok(self.data.clone())
}

Expand All @@ -50,7 +50,7 @@ impl Table for DummyEnrichmentTable {
_condition: &[Condition],
_select: Option<&[String]>,
_index: Option<IndexHandle>,
) -> Result<Vec<BTreeMap<String, Value>>, String> {
) -> Result<Vec<ObjectMap>, String> {
Ok(vec![self.data.clone()])
}

Expand Down
Loading
Loading