Skip to content

Commit 08303a1

Browse files
authored
chore(vrl): re-enable parse_dnstap without VRL playground support (vectordotdev#22124)
* chore(vrl): Revert `parse_dnstap` function removal Revert "chore(vrl): Revert add `parse_dnstap` function (vectordotdev#22114)" This reverts commit f3549db. * Remove `dnstap-parser` from VRL playground * Add dnstap_parser vrl_functions only when `sources-dnstap` feature is enabled
1 parent d78f968 commit 08303a1

File tree

25 files changed

+670
-43
lines changed

25 files changed

+670
-43
lines changed

.github/actions/spelling/patterns.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ user:P@ssw0rd
226226
/.+@base64/.+
227227

228228
# Ignore base64 encoded values in VRL examples (requires padding to avoid false positives)
229-
"[A-Za-z0-9]*=="
229+
"[A-Za-z0-9+\/]*=="
230230

231231
# ignore uuid_from_friendly_id argument
232232
uuid_from_friendly_id!\(".*"\)

Cargo.lock

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

Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ members = [
103103
".",
104104
"lib/codecs",
105105
"lib/dnsmsg-parser",
106+
"lib/dnstap-parser",
106107
"lib/docs-renderer",
107108
"lib/enrichment",
108109
"lib/fakedata",
@@ -133,13 +134,15 @@ members = [
133134
]
134135

135136
[workspace.dependencies]
137+
anyhow = "1.0.94"
136138
cfg-if = { version = "1.0.0", default-features = false }
137139
chrono = { version = "0.4.38", default-features = false, features = ["clock", "serde"] }
138140
chrono-tz = { version = "0.10.0", default-features = false, features = ["serde"] }
139141
clap = { version = "4.5.22", default-features = false, features = ["derive", "error-context", "env", "help", "std", "string", "usage", "wrap_help"] }
140142
flate2 = { version = "1.0.35", default-features = false, features = ["default"] }
141143
futures = { version = "0.3.31", default-features = false, features = ["compat", "io-compat", "std"], package = "futures" }
142144
glob = { version = "0.3.1", default-features = false }
145+
hickory-proto = { version = "0.24.1", default-features = false, features = ["dnssec"] }
143146
indexmap = { version = "2.7.0", default-features = false, features = ["serde", "std"] }
144147
metrics = "0.24.1"
145148
metrics-tracing-context = { version = "0.17.0", default-features = false }
@@ -177,6 +180,7 @@ snafu.workspace = true
177180

178181
# Internal libs
179182
dnsmsg-parser = { path = "lib/dnsmsg-parser", optional = true }
183+
dnstap-parser = { path = "lib/dnstap-parser", optional = true }
180184
fakedata = { path = "lib/fakedata", optional = true }
181185
portpicker = { path = "lib/portpicker" }
182186
tracing-limit = { path = "lib/tracing-limit" }
@@ -366,7 +370,7 @@ tokio-postgres = { version = "0.7.12", default-features = false, features = ["ru
366370
tokio-tungstenite = { version = "0.20.1", default-features = false, features = ["connect"], optional = true }
367371
toml.workspace = true
368372
tonic = { workspace = true, optional = true }
369-
hickory-proto = { version = "0.24.1", default-features = false, features = ["dnssec"], optional = true }
373+
hickory-proto = { workspace = true, optional = true }
370374
typetag = { version = "0.2.18", default-features = false }
371375
url = { version = "2.5.4", default-features = false, features = ["serde"] }
372376
warp = { version = "0.3.7", default-features = false }
@@ -582,7 +586,7 @@ sources-aws_s3 = ["aws-core", "dep:aws-sdk-sqs", "dep:aws-sdk-s3", "dep:semver",
582586
sources-aws_sqs = ["aws-core", "dep:aws-sdk-sqs"]
583587
sources-datadog_agent = ["sources-utils-http-error", "protobuf-build", "dep:prost"]
584588
sources-demo_logs = ["dep:fakedata"]
585-
sources-dnstap = ["sources-utils-net-tcp", "dep:base64", "dep:hickory-proto", "dep:dnsmsg-parser", "protobuf-build", "dep:prost"]
589+
sources-dnstap = ["sources-utils-net-tcp", "dep:base64", "dep:hickory-proto", "dep:dnsmsg-parser", "dep:dnstap-parser", "protobuf-build", "dep:prost"]
586590
sources-docker_logs = ["docker"]
587591
sources-eventstoredb_metrics = []
588592
sources-exec = []

buf.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ modules:
33
- path: lib/vector-core/proto
44
- path: proto/third-party
55
- path: proto/vector
6+
- path: lib/dnstap-parser/proto
67
lint:
78
use:
89
- DEFAULT

build.rs

-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ fn main() {
116116

117117
#[cfg(feature = "protobuf-build")]
118118
{
119-
println!("cargo:rerun-if-changed=proto/third-party/dnstap.proto");
120119
println!("cargo:rerun-if-changed=proto/third-party/google/pubsub/v1/pubsub.proto");
121120
println!("cargo:rerun-if-changed=proto/third-party/google/rpc/status.proto");
122121
println!("cargo:rerun-if-changed=proto/vector/dd_metric.proto");
@@ -144,7 +143,6 @@ fn main() {
144143
prost_build,
145144
&[
146145
"lib/vector-core/proto/event.proto",
147-
"proto/third-party/dnstap.proto",
148146
"proto/vector/ddsketch_full.proto",
149147
"proto/vector/dd_metric.proto",
150148
"proto/vector/dd_trace.proto",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add VRL function `parse_dnstap` that can parse dnstap data and produce output in the same format as `dnstap` source.
2+
3+
authors: esensar

lib/dnsmsg-parser/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT"
88

99
[dependencies]
1010
data-encoding = "2.6"
11-
hickory-proto = { version = "0.24", features = ["dnssec"] }
11+
hickory-proto.workspace = true
1212
snafu.workspace = true
1313

1414
[dev-dependencies]

lib/dnstap-parser/Cargo.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "dnstap-parser"
3+
version = "0.1.0"
4+
authors = ["Vector Contributors <[email protected]>"]
5+
edition = "2021"
6+
publish = false
7+
license = "MIT"
8+
9+
[dependencies]
10+
base64 = { version = "0.22.1", default-features = false }
11+
bytes = { version = "1.9.0", default-features = false, features = ["serde"] }
12+
chrono.workspace = true
13+
dnsmsg-parser = { path = "../dnsmsg-parser" }
14+
hickory-proto.workspace = true
15+
prost.workspace = true
16+
snafu.workspace = true
17+
tracing = { version = "0.1.34", default-features = false }
18+
vector-lib = { path = "../vector-lib" }
19+
vrl.workspace = true
20+
21+
[build-dependencies]
22+
prost-build.workspace = true
23+
24+
[dev-dependencies]
25+
anyhow.workspace = true
26+
chrono-tz.workspace = true

lib/dnstap-parser/build.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
println!("cargo:rerun-if-changed=proto/dnstap.proto");
3+
let mut prost_build = prost_build::Config::new();
4+
prost_build.btree_map(["."]);
5+
prost_build
6+
.compile_protos(&["proto/dnstap.proto"], &["proto"])
7+
.expect("Failed to compile proto files");
8+
}
File renamed without changes.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use tracing::warn;
2+
use vector_lib::internal_event::InternalEvent;
3+
use vector_lib::internal_event::{error_stage, error_type};
4+
5+
#[derive(Debug)]
6+
pub(crate) struct DnstapParseWarning<E> {
7+
pub error: E,
8+
}
9+
10+
impl<E: std::fmt::Display> InternalEvent for DnstapParseWarning<E> {
11+
fn emit(self) {
12+
warn!(
13+
message = "Recoverable error occurred while parsing dnstap data.",
14+
error = %self.error,
15+
stage = error_stage::PROCESSING,
16+
error_type = error_type::PARSER_FAILED,
17+
internal_log_rate_limit = true,
18+
);
19+
}
20+
}

lib/dnstap-parser/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![deny(warnings)]
2+
3+
use vrl::compiler::Function;
4+
5+
mod internal_events;
6+
pub mod parser;
7+
pub mod schema;
8+
mod vrl_functions;
9+
10+
pub fn vrl_functions() -> Vec<Box<dyn Function>> {
11+
vrl_functions::all()
12+
}

src/sources/dnstap/parser.rs lib/dnstap-parser/src/parser.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
net::{IpAddr, Ipv4Addr, Ipv6Addr},
66
sync::LazyLock,
77
};
8+
use vector_lib::emit;
89

910
use base64::prelude::{Engine as _, BASE64_STANDARD};
1011
use bytes::Bytes;
@@ -18,9 +19,8 @@ use prost::Message;
1819
use snafu::Snafu;
1920
use vrl::{owned_value_path, path};
2021

21-
use crate::{
22+
use vector_lib::{
2223
event::{LogEvent, Value},
23-
internal_events::DnstapParseWarning,
2424
Error, Result,
2525
};
2626

@@ -29,7 +29,7 @@ mod dnstap_proto {
2929
include!(concat!(env!("OUT_DIR"), "/dnstap.rs"));
3030
}
3131

32-
use crate::sources::dnstap::schema::DNSTAP_VALUE_PATHS;
32+
use crate::{internal_events::DnstapParseWarning, schema::DNSTAP_VALUE_PATHS};
3333
use dnstap_proto::{
3434
message::Type as DnstapMessageType, Dnstap, Message as DnstapMessage, SocketFamily,
3535
SocketProtocol,
@@ -38,7 +38,7 @@ use vector_lib::config::log_schema;
3838
use vector_lib::lookup::lookup_v2::ValuePath;
3939
use vector_lib::lookup::PathPrefix;
4040

41-
use super::{
41+
use dnsmsg_parser::{
4242
dns_message::{
4343
DnsRecord, EdnsOptionEntry, OptPseudoSection, QueryHeader, QueryQuestion, UpdateHeader,
4444
ZoneInfo,
@@ -459,14 +459,15 @@ impl DnstapParser {
459459
);
460460
}
461461

462-
Ok(if let Some(response_port) = dnstap_message.response_port {
462+
if let Some(response_port) = dnstap_message.response_port {
463463
DnstapParser::insert(
464464
event,
465465
prefix.clone(),
466466
&DNSTAP_VALUE_PATHS.response_port,
467467
response_port,
468468
);
469-
})
469+
};
470+
Ok(())
470471
}
471472

472473
fn log_time<'a>(
@@ -1015,7 +1016,6 @@ fn to_dnstap_message_type(type_id: i32) -> String {
10151016
#[cfg(test)]
10161017
mod tests {
10171018
use super::*;
1018-
use crate::event::Value;
10191019
use chrono::DateTime;
10201020
use dnsmsg_parser::dns_message_parser::DnsParserOptions;
10211021
use std::collections::BTreeMap;

src/sources/dnstap/schema.rs lib/dnstap-parser/src/schema.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct DnstapEventSchema;
1212

1313
impl DnstapEventSchema {
1414
/// The message schema for the request and response message fields
15-
fn request_message_schema_definition(&self) -> Collection<Field> {
15+
pub(crate) fn request_message_schema_definition(&self) -> Collection<Field> {
1616
let mut result: BTreeMap<Field, Kind> = BTreeMap::new();
1717
result.insert(
1818
DNSTAP_VALUE_PATHS.time.to_string().into(),
@@ -288,7 +288,7 @@ pub struct DnstapPaths {
288288
}
289289

290290
/// Lazily initialized singleton.
291-
pub(crate) static DNSTAP_VALUE_PATHS: LazyLock<DnstapPaths> = LazyLock::new(|| DnstapPaths {
291+
pub static DNSTAP_VALUE_PATHS: LazyLock<DnstapPaths> = LazyLock::new(|| DnstapPaths {
292292
server_identity: owned_value_path!("serverId"),
293293
server_version: owned_value_path!("serverVersion"),
294294
extra: owned_value_path!("extraInfo"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use vrl::compiler::Function;
2+
3+
pub mod parse_dnstap;
4+
5+
pub fn all() -> Vec<Box<dyn Function>> {
6+
vec![Box::new(parse_dnstap::ParseDnstap) as _]
7+
}

0 commit comments

Comments
 (0)