Skip to content

Commit 2af657d

Browse files
enhancement(vrl): consolidate all VRL functions into vector-vrl-functions crate (#24402)
* Create all_vrl_functions * Create and use vector-vrl-all * Move dnstap-parser off of vector-lib * Use vector-vrl-all in lib/codecs * refactor: use vector-vrl-all as workspace dependency * docs: add crate-level documentation for vector-vrl-all * Use LazyLock to cache VRL function list * Revert "Use LazyLock to cache VRL function list" This reverts commit 04616c2. * Add back changelog * cargo fmt * Skip testing vrl stdlib functions' examples * Fix broken examples * Move VRL function consolidation logic into vector_vrl_functions::all() * Cargo fmt * Add ignore for disallowed_methods
1 parent fad6e62 commit 2af657d

File tree

34 files changed

+119
-112
lines changed

34 files changed

+119
-112
lines changed

Cargo.lock

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ vector-config-common = { path = "lib/vector-config-common" }
200200
vector-config-macros = { path = "lib/vector-config-macros" }
201201
vector-common-macros = { path = "lib/vector-common-macros" }
202202
vector-lib = { path = "lib/vector-lib", default-features = false, features = ["vrl"] }
203+
vector-vrl-functions = { path = "lib/vector-vrl/functions" }
203204
vrl = { git = "https://github.com/vectordotdev/vrl.git", branch = "main", features = ["arbitrary", "cli", "test", "test_framework"] }
204205
mock_instant = { version = "0.6" }
205206
serial_test = { version = "3.2" }
@@ -227,7 +228,7 @@ vector-lib.workspace = true
227228
vector-config.workspace = true
228229
vector-config-common.workspace = true
229230
vector-config-macros.workspace = true
230-
vector-vrl-functions = { path = "lib/vector-vrl/functions" }
231+
vector-vrl-functions.workspace = true
231232
loki-logproto = { path = "lib/loki-logproto", optional = true }
232233

233234
# Tokio / Futures
@@ -654,7 +655,7 @@ sources-aws_s3 = ["aws-core", "dep:aws-sdk-sqs", "dep:aws-sdk-s3", "dep:async-co
654655
sources-aws_sqs = ["aws-core", "dep:aws-sdk-sqs"]
655656
sources-datadog_agent = ["sources-utils-http-encoding", "protobuf-build", "dep:prost"]
656657
sources-demo_logs = ["dep:fakedata"]
657-
sources-dnstap = ["sources-utils-net-tcp", "dep:base64", "dep:hickory-proto", "dep:dnsmsg-parser", "dep:dnstap-parser", "protobuf-build", "dep:prost"]
658+
sources-dnstap = ["sources-utils-net-tcp", "dep:base64", "dep:hickory-proto", "dep:dnsmsg-parser", "dep:dnstap-parser", "protobuf-build", "dep:prost", "vector-vrl-functions/dnstap"]
658659
sources-docker_logs = ["docker"]
659660
sources-eventstoredb_metrics = []
660661
sources-exec = []
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Vector-specific VRL functions are now available everywhere. Previously some functions were not
2+
available inside codec VRL transforms and in the VRL cli (via `vector vrl`).
3+
4+
authors: thomasqueirozb

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ allow-unwrap-in-tests = true
55
# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
66
disallowed-methods = [
77
{ path = "std::io::Write::write", reason = "This doesn't handle short writes, use `write_all` instead." },
8+
{ path = "vrl::stdlib::all", reason = "Use `vector_vrl_functions::all()` instead for consistency across all Vector VRL functions." },
89
]
910

1011
disallowed-types = [

lib/codecs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ vector-common = { path = "../vector-common", default-features = false }
4646
vector-config = { path = "../vector-config", default-features = false }
4747
vector-config-macros = { path = "../vector-config-macros", default-features = false }
4848
vector-core = { path = "../vector-core", default-features = false, features = ["vrl"] }
49+
vector-vrl-functions.workspace = true
4950

5051
[dev-dependencies]
5152
futures.workspace = true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl VrlDeserializerConfig {
5959

6060
match compile_vrl(
6161
&self.vrl.source,
62-
&vrl::stdlib::all(),
62+
&vector_vrl_functions::all(),
6363
&state,
6464
CompileConfig::default(),
6565
) {

lib/dnstap-parser/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ hickory-proto.workspace = true
1515
prost.workspace = true
1616
snafu.workspace = true
1717
tracing.workspace = true
18-
vector-lib.workspace = true
18+
vector-config.workspace = true
19+
vector-common = { path = "../vector-common" }
20+
vector-lookup = { path = "../vector-lookup", features = ["test"] }
21+
vector-core = { path = "../vector-core" }
1922
vrl.workspace = true
2023
paste.workspace = true
2124

lib/dnstap-parser/src/internal_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use tracing::warn;
2-
use vector_lib::{
2+
use vector_common::{
33
NamedInternalEvent,
44
internal_event::{InternalEvent, error_stage, error_type},
55
};

lib/dnstap-parser/src/parser.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ use hickory_proto::{
1616
};
1717
use prost::Message;
1818
use snafu::Snafu;
19-
use vector_lib::{
20-
Error, Result, emit,
21-
event::{LogEvent, Value},
22-
};
19+
use vector_common::{Error, Result, internal_event::emit};
20+
use vector_core::event::{LogEvent, Value};
2321
use vrl::{owned_value_path, path};
2422

2523
#[allow(warnings, clippy::all, clippy::pedantic, clippy::nursery)]
@@ -38,10 +36,8 @@ use dnstap_proto::{
3836
Dnstap, Message as DnstapMessage, SocketFamily, SocketProtocol,
3937
message::Type as DnstapMessageType,
4038
};
41-
use vector_lib::{
42-
config::log_schema,
43-
lookup::{PathPrefix, lookup_v2::ValuePath},
44-
};
39+
use vector_core::config::log_schema;
40+
use vector_lookup::{PathPrefix, lookup_v2::ValuePath};
4541

4642
use crate::{internal_events::DnstapParseWarning, schema::DNSTAP_VALUE_PATHS};
4743

@@ -151,13 +147,13 @@ impl DnstapParser {
151147
&& let Err(err) =
152148
DnstapParser::parse_dnstap_message(event, &root, message, parsing_options)
153149
{
154-
emit!(DnstapParseWarning { error: &err });
150+
emit(DnstapParseWarning { error: &err });
155151
need_raw_data = true;
156152
DnstapParser::insert(event, &root, &DNSTAP_VALUE_PATHS.error, err.to_string());
157153
}
158154
} else {
159-
emit!(DnstapParseWarning {
160-
error: format!("Unknown dnstap data type: {dnstap_data_type_id}")
155+
emit(DnstapParseWarning {
156+
error: format!("Unknown dnstap data type: {dnstap_data_type_id}"),
161157
});
162158
need_raw_data = true;
163159
}

lib/dnstap-parser/src/schema.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{collections::BTreeMap, sync::LazyLock};
22

3-
use vector_lib::lookup::{OwnedValuePath, owned_value_path};
3+
use vector_lookup::{OwnedValuePath, owned_value_path};
44
use vrl::{
55
btreemap,
66
value::{
@@ -135,8 +135,8 @@ impl DnstapEventSchema {
135135
/// Schema definition for fields stored in the root.
136136
fn root_schema_definition(
137137
&self,
138-
schema: vector_lib::schema::Definition,
139-
) -> vector_lib::schema::Definition {
138+
schema: vector_core::schema::Definition,
139+
) -> vector_core::schema::Definition {
140140
schema
141141
.optional_field(&DNSTAP_VALUE_PATHS.server_identity, Kind::bytes(), None)
142142
.optional_field(&DNSTAP_VALUE_PATHS.server_version, Kind::bytes(), None)
@@ -152,8 +152,8 @@ impl DnstapEventSchema {
152152
/// Schema definition from the message.
153153
pub fn message_schema_definition(
154154
&self,
155-
schema: vector_lib::schema::Definition,
156-
) -> vector_lib::schema::Definition {
155+
schema: vector_core::schema::Definition,
156+
) -> vector_core::schema::Definition {
157157
schema
158158
.optional_field(&DNSTAP_VALUE_PATHS.socket_family, Kind::bytes(), None)
159159
.optional_field(&DNSTAP_VALUE_PATHS.socket_protocol, Kind::bytes(), None)
@@ -179,8 +179,8 @@ impl DnstapEventSchema {
179179
/// The schema definition for a dns tap message.
180180
pub fn schema_definition(
181181
&self,
182-
schema: vector_lib::schema::Definition,
183-
) -> vector_lib::schema::Definition {
182+
schema: vector_core::schema::Definition,
183+
) -> vector_core::schema::Definition {
184184
self.root_schema_definition(self.message_schema_definition(schema))
185185
}
186186
}

0 commit comments

Comments
 (0)