Skip to content

Commit cd74d8f

Browse files
authored
chore: Use value::Value directly in the codebase (vectordotdev#12673)
* Use `value::Value` directly in the codebase This commit modifies the project to use `value::Value` directly and not as a re-export from VRL. The changeset is large but almost entirely mechanical. I would like to experiment with different representations of `Value` -- imagine a world where the `Value` is mostly stack allocated, or where the `Value::Object` doesn't recurse to another heap allocated `Value` outside of the current virtual machine page -- but I realized while making some modifications to that type that its representation was, well, kindly spread through the project. We don't solve that here. Instead we take a single step in that direction. Follow-up work will work a struct shim over the top of the `BTreeMap` inside `Value` so callers are not aware of the `BTreeMap`. That abstraction is what will allow us to fiddle with the representation, so long as we hew to the enum nature of `Value`. Signed-off-by: Brian L. Troutwine <[email protected]> * test dings Signed-off-by: Brian L. Troutwine <[email protected]> * test dings Signed-off-by: Brian L. Troutwine <[email protected]> * reviews Signed-off-by: Brian L. Troutwine <[email protected]> * test dings Signed-off-by: Brian L. Troutwine <[email protected]> * newline ding Signed-off-by: Brian L. Troutwine <[email protected]> * clippy dings Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent 2f6e57a commit cd74d8f

File tree

396 files changed

+1078
-737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

396 files changed

+1078
-737
lines changed

.rustfmt.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Using defaults.
2-
# Not stable yet.
3-
# indent_style = "Block"
4-
# group_imports = "StdExternalCrate"
5-
# imports_granularity = "Crate"
6-
reorder_imports = true
71
edition = "2021"
2+
newline_style = "unix"
3+
reorder_imports = true
4+
5+
# Nightly only features
6+
# unstable_features = true
7+
# imports_granularity = "Crate"
8+
# group_imports = "StdExternalCrate"
9+
# indent_style = "Block"

Cargo.lock

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ lookup = { path = "lib/lookup" }
113113
portpicker = { path = "lib/portpicker" }
114114
prometheus-parser = { path = "lib/prometheus-parser", optional = true }
115115
tracing-limit = { path = "lib/tracing-limit" }
116-
value = { path = "lib/value", optional = true }
116+
value = { path = "lib/value" }
117117
vector_buffers = { path = "lib/vector-buffers", default-features = false }
118118
vector_common = { path = "lib/vector-common" }
119119
vector_core = { path = "lib/vector-core", default-features = false, features = ["vrl"] }
@@ -465,7 +465,7 @@ sources-aws_ecs_metrics = []
465465
sources-aws_kinesis_firehose = ["base64", "infer", "sources-utils-tls"]
466466
sources-aws_s3 = ["aws-core", "aws-sdk-sqs", "aws-sdk-s3", "semver", "async-compression", "sources-aws_sqs", "tokio-util/io"]
467467
sources-aws_sqs = ["aws-core", "aws-sdk-sqs"]
468-
sources-datadog_agent = ["sources-utils-tls", "sources-utils-http-error", "protobuf-build", "value"]
468+
sources-datadog_agent = ["sources-utils-tls", "sources-utils-http-error", "protobuf-build"]
469469
sources-demo_logs = ["fakedata"]
470470
sources-dnstap = ["base64", "trust-dns-proto", "dnsmsg-parser", "protobuf-build"]
471471
sources-docker_logs = ["docker"]
@@ -577,7 +577,7 @@ transforms-metric_to_log = []
577577
transforms-pipelines = ["transforms-filter", "transforms-route"]
578578
transforms-reduce = []
579579
transforms-regex_parser = []
580-
transforms-remap = ["value"]
580+
transforms-remap = []
581581
transforms-remove_fields = []
582582
transforms-remove_tags = []
583583
transforms-rename_fields = []

benches/codecs/character_delimited_bytes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{fmt, time::Duration};
2+
13
use bytes::BytesMut;
24
use codecs::{
35
self,
@@ -8,7 +10,6 @@ use criterion::{
810
criterion_group, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId, Criterion,
911
SamplingMode, Throughput,
1012
};
11-
use std::{fmt, time::Duration};
1213
use tokio_util::codec::Decoder;
1314

1415
#[derive(Debug)]

benches/codecs/encoder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use std::time::Duration;
2+
13
use bytes::{BufMut, BytesMut};
24
use codecs::{encoding::Framer, JsonSerializer, NewlineDelimitedEncoder};
35
use criterion::{
46
criterion_group, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion, SamplingMode,
57
Throughput,
68
};
7-
use std::time::Duration;
89
use tokio_util::codec::Encoder;
910
use vector::event::Event;
1011
use vector_common::{btreemap, byte_size_of::ByteSizeOf};

benches/codecs/newline_bytes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{fmt, time::Duration};
2+
13
use bytes::BytesMut;
24
use codecs::{
35
self, decoding::Deserializer, decoding::Framer, BytesDeserializer, NewlineDelimitedDecoder,
@@ -6,7 +8,6 @@ use criterion::{
68
criterion_group, measurement::WallTime, BatchSize, BenchmarkGroup, BenchmarkId, Criterion,
79
SamplingMode, Throughput,
810
};
9-
use std::{fmt, time::Duration};
1011
use tokio_util::codec::Decoder;
1112

1213
#[derive(Debug)]

benches/enrichment_tables_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::{collections::BTreeMap, time::SystemTime};
33
use chrono::prelude::*;
44
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
55
use enrichment::Case;
6+
use value::Value;
67
use vector::enrichment_tables::{file::File, Condition, Table};
7-
use vrl::Value;
88

99
criterion_group!(
1010
name = benches;

lib/codecs/src/decoding/format/bytes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ impl Deserializer for BytesDeserializer {
7474

7575
#[cfg(test)]
7676
mod tests {
77-
use super::*;
7877
use vector_core::config::log_schema;
7978

79+
use super::*;
80+
8081
#[test]
8182
fn deserialize_bytes() {
8283
let input = Bytes::from("foo");

lib/codecs/src/decoding/format/json.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
use super::Deserializer;
1+
use std::convert::TryInto;
2+
23
use bytes::Bytes;
34
use chrono::Utc;
45
use serde::{Deserialize, Serialize};
56
use smallvec::{smallvec, SmallVec};
6-
use std::convert::TryInto;
77
use value::Kind;
88
use vector_core::{
99
config::{log_schema, DataType},
1010
event::Event,
1111
schema,
1212
};
1313

14+
use super::Deserializer;
15+
1416
/// Config used to build a `JsonDeserializer`.
1517
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
1618
pub struct JsonDeserializerConfig;
@@ -100,9 +102,10 @@ impl From<&JsonDeserializerConfig> for JsonDeserializer {
100102

101103
#[cfg(test)]
102104
mod tests {
103-
use super::*;
104105
use vector_core::config::log_schema;
105106

107+
use super::*;
108+
106109
#[test]
107110
fn deserialize_json() {
108111
let input = Bytes::from(r#"{ "foo": 123 }"#);

lib/codecs/src/decoding/format/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ mod native_json;
1010
#[cfg(feature = "syslog")]
1111
mod syslog;
1212

13-
pub use self::bytes::{BytesDeserializer, BytesDeserializerConfig};
14-
#[cfg(feature = "syslog")]
15-
pub use self::syslog::{SyslogDeserializer, SyslogDeserializerConfig};
16-
pub use json::{JsonDeserializer, JsonDeserializerConfig};
17-
pub use native::{NativeDeserializer, NativeDeserializerConfig};
18-
pub use native_json::{NativeJsonDeserializer, NativeJsonDeserializerConfig};
13+
use std::fmt::Debug;
1914

2015
use ::bytes::Bytes;
2116
use dyn_clone::DynClone;
17+
pub use json::{JsonDeserializer, JsonDeserializerConfig};
18+
pub use native::{NativeDeserializer, NativeDeserializerConfig};
19+
pub use native_json::{NativeJsonDeserializer, NativeJsonDeserializerConfig};
2220
use smallvec::SmallVec;
23-
use std::fmt::Debug;
2421
use vector_core::event::Event;
2522

23+
pub use self::bytes::{BytesDeserializer, BytesDeserializerConfig};
24+
#[cfg(feature = "syslog")]
25+
pub use self::syslog::{SyslogDeserializer, SyslogDeserializerConfig};
26+
2627
/// Parse structured events from bytes.
2728
pub trait Deserializer: DynClone + Debug + Send + Sync {
2829
/// Parses structured events from bytes.

lib/codecs/src/decoding/format/native_json.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use bytes::Bytes;
22
use serde::{Deserialize, Serialize};
33
use smallvec::{smallvec, SmallVec};
44
use value::Kind;
5+
use vector_core::{config::DataType, event::Event, schema};
56

67
use super::Deserializer;
7-
use vector_core::{config::DataType, event::Event, schema};
88

99
/// Config used to build a `NativeJsonDeserializer`.
1010
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
@@ -57,9 +57,10 @@ impl Deserializer for NativeJsonDeserializer {
5757

5858
#[cfg(test)]
5959
mod test {
60-
use super::*;
6160
use serde_json::json;
6261

62+
use super::*;
63+
6364
#[test]
6465
fn parses_top_level_arrays() {
6566
let config = NativeJsonDeserializerConfig;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use serde::{Deserialize, Serialize};
44
use smallvec::{smallvec, SmallVec};
55
use syslog_loose::{IncompleteDate, Message, ProcId, Protocol};
66
use value::Kind;
7-
8-
use super::Deserializer;
97
use vector_core::{
108
config::{log_schema, DataType},
119
event::{Event, Value},
1210
schema,
1311
};
1412

13+
use super::Deserializer;
14+
1515
/// Config used to build a `SyslogDeserializer`.
1616
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
1717
pub struct SyslogDeserializerConfig;

lib/codecs/src/decoding/framing/character_delimited.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ impl Decoder for CharacterDelimitedDecoder {
148148

149149
#[cfg(test)]
150150
mod tests {
151-
use super::*;
151+
use std::collections::HashMap;
152+
152153
use bytes::BufMut;
153154
use indoc::indoc;
154-
use std::collections::HashMap;
155+
156+
use super::*;
155157

156158
#[test]
157159
fn decode() {

lib/codecs/src/decoding/framing/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ mod length_delimited;
99
mod newline_delimited;
1010
mod octet_counting;
1111

12-
pub use self::bytes::{BytesDecoder, BytesDecoderConfig};
12+
use std::fmt::Debug;
13+
14+
use ::bytes::Bytes;
1315
pub use character_delimited::{
1416
CharacterDelimitedDecoder, CharacterDelimitedDecoderConfig, CharacterDelimitedDecoderOptions,
1517
};
18+
use dyn_clone::DynClone;
1619
pub use length_delimited::{LengthDelimitedDecoder, LengthDelimitedDecoderConfig};
1720
pub use newline_delimited::{
1821
NewlineDelimitedDecoder, NewlineDelimitedDecoderConfig, NewlineDelimitedDecoderOptions,
1922
};
2023
pub use octet_counting::{
2124
OctetCountingDecoder, OctetCountingDecoderConfig, OctetCountingDecoderOptions,
2225
};
26+
use tokio_util::codec::LinesCodecError;
2327

28+
pub use self::bytes::{BytesDecoder, BytesDecoderConfig};
2429
use super::StreamDecodingError;
25-
use ::bytes::Bytes;
26-
use dyn_clone::DynClone;
27-
use std::fmt::Debug;
28-
use tokio_util::codec::LinesCodecError;
2930

3031
/// An error that occurred while producing byte frames from a byte stream / byte
3132
/// message.

lib/codecs/src/decoding/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ mod error;
55
pub mod format;
66
pub mod framing;
77

8+
use std::fmt::Debug;
9+
10+
use bytes::{Bytes, BytesMut};
811
pub use error::StreamDecodingError;
912
pub use format::{
1013
BoxedDeserializer, BytesDeserializer, BytesDeserializerConfig, JsonDeserializer,
@@ -20,11 +23,8 @@ pub use framing::{
2023
NewlineDelimitedDecoderConfig, NewlineDelimitedDecoderOptions, OctetCountingDecoder,
2124
OctetCountingDecoderConfig, OctetCountingDecoderOptions,
2225
};
23-
24-
use bytes::{Bytes, BytesMut};
2526
use serde::{Deserialize, Serialize};
2627
use smallvec::SmallVec;
27-
use std::fmt::Debug;
2828
use vector_core::{config::DataType, event::Event, schema};
2929

3030
/// An error that occurred while decoding structured events from a byte stream /

lib/codecs/src/encoding/format/json.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ impl Encoder<Event> for JsonSerializer {
5858

5959
#[cfg(test)]
6060
mod tests {
61-
use super::*;
6261
use bytes::BytesMut;
6362
use vector_common::btreemap;
6463
use vector_core::event::Value;
6564

65+
use super::*;
66+
6667
#[test]
6768
fn serialize_json() {
6869
let event = Event::from(btreemap! {

lib/codecs/src/encoding/format/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ mod native;
88
mod native_json;
99
mod raw_message;
1010

11+
use std::fmt::Debug;
12+
13+
use dyn_clone::DynClone;
1114
pub use json::{JsonSerializer, JsonSerializerConfig};
1215
pub use native::{NativeSerializer, NativeSerializerConfig};
1316
pub use native_json::{NativeJsonSerializer, NativeJsonSerializerConfig};
1417
pub use raw_message::{RawMessageSerializer, RawMessageSerializerConfig};
15-
16-
use dyn_clone::DynClone;
17-
use std::fmt::Debug;
1818
use vector_core::event::Event;
1919

2020
/// Serialize a structured event into a byte frame.

lib/codecs/src/encoding/format/raw_message.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
use bytes::{BufMut, BytesMut};
2+
use serde::{Deserialize, Serialize};
3+
use tokio_util::codec::Encoder;
4+
use value::Kind;
15
use vector_core::{
26
config::{log_schema, DataType},
37
event::Event,
48
schema,
59
};
610

7-
use bytes::{BufMut, BytesMut};
8-
use serde::{Deserialize, Serialize};
9-
use tokio_util::codec::Encoder;
10-
use value::Kind;
11-
1211
/// Config used to build a `RawMessageSerializer`.
1312
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
1413
pub struct RawMessageSerializerConfig;
@@ -71,9 +70,10 @@ impl Encoder<Event> for RawMessageSerializer {
7170

7271
#[cfg(test)]
7372
mod tests {
74-
use super::*;
7573
use bytes::{Bytes, BytesMut};
7674

75+
use super::*;
76+
7777
#[test]
7878
fn serialize_bytes() {
7979
let input = Event::from("foo");

lib/codecs/src/encoding/framing/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ mod character_delimited;
88
mod length_delimited;
99
mod newline_delimited;
1010

11-
pub use self::bytes::{BytesEncoder, BytesEncoderConfig};
11+
use std::fmt::Debug;
12+
1213
pub use character_delimited::{
1314
CharacterDelimitedEncoder, CharacterDelimitedEncoderConfig, CharacterDelimitedEncoderOptions,
1415
};
16+
use dyn_clone::DynClone;
1517
pub use length_delimited::{LengthDelimitedEncoder, LengthDelimitedEncoderConfig};
1618
pub use newline_delimited::{NewlineDelimitedEncoder, NewlineDelimitedEncoderConfig};
17-
18-
use dyn_clone::DynClone;
19-
use std::fmt::Debug;
2019
use tokio_util::codec::LinesCodecError;
2120

21+
pub use self::bytes::{BytesEncoder, BytesEncoderConfig};
22+
2223
/// An error that occurred while framing bytes.
2324
pub trait FramingError: std::error::Error + Send + Sync {}
2425

0 commit comments

Comments
 (0)