Skip to content

Commit

Permalink
chore(vrl): re-enable parse_dnstap without VRL playground support (#…
Browse files Browse the repository at this point in the history
…22124)

* chore(vrl): Revert `parse_dnstap` function removal

Revert "chore(vrl): Revert add `parse_dnstap` function (#22114)"

This reverts commit f3549db.

* Remove `dnstap-parser` from VRL playground
  • Loading branch information
esensar authored Jan 6, 2025
1 parent 3b90e26 commit 29ecaac
Show file tree
Hide file tree
Showing 25 changed files with 669 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/actions/spelling/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ user:P@ssw0rd
/.+@base64/.+

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

# ignore uuid_from_friendly_id argument
uuid_from_friendly_id!\(".*"\)
Expand Down
22 changes: 21 additions & 1 deletion Cargo.lock

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

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ members = [
".",
"lib/codecs",
"lib/dnsmsg-parser",
"lib/dnstap-parser",
"lib/docs-renderer",
"lib/enrichment",
"lib/fakedata",
Expand Down Expand Up @@ -133,13 +134,15 @@ members = [
]

[workspace.dependencies]
anyhow = "1.0.94"
cfg-if = { version = "1.0.0", default-features = false }
chrono = { version = "0.4.38", default-features = false, features = ["clock", "serde"] }
chrono-tz = { version = "0.10.0", default-features = false, features = ["serde"] }
clap = { version = "4.5.22", default-features = false, features = ["derive", "error-context", "env", "help", "std", "string", "usage", "wrap_help"] }
flate2 = { version = "1.0.35", default-features = false, features = ["default"] }
futures = { version = "0.3.31", default-features = false, features = ["compat", "io-compat", "std"], package = "futures" }
glob = { version = "0.3.1", default-features = false }
hickory-proto = { version = "0.24.1", default-features = false, features = ["dnssec"] }
indexmap = { version = "2.7.0", default-features = false, features = ["serde", "std"] }
metrics = "0.24.1"
metrics-tracing-context = { version = "0.17.0", default-features = false }
Expand Down Expand Up @@ -177,6 +180,7 @@ snafu.workspace = true

# Internal libs
dnsmsg-parser = { path = "lib/dnsmsg-parser", optional = true }
dnstap-parser = { path = "lib/dnstap-parser", optional = true }
fakedata = { path = "lib/fakedata", optional = true }
portpicker = { path = "lib/portpicker" }
tracing-limit = { path = "lib/tracing-limit" }
Expand Down Expand Up @@ -366,7 +370,7 @@ tokio-postgres = { version = "0.7.12", default-features = false, features = ["ru
tokio-tungstenite = { version = "0.20.1", default-features = false, features = ["connect"], optional = true }
toml.workspace = true
tonic = { workspace = true, optional = true }
hickory-proto = { version = "0.24.1", default-features = false, features = ["dnssec"], optional = true }
hickory-proto = { workspace = true, optional = true }
typetag = { version = "0.2.18", default-features = false }
url = { version = "2.5.4", default-features = false, features = ["serde"] }
warp = { version = "0.3.7", default-features = false }
Expand Down Expand Up @@ -582,7 +586,7 @@ sources-aws_s3 = ["aws-core", "dep:aws-sdk-sqs", "dep:aws-sdk-s3", "dep:semver",
sources-aws_sqs = ["aws-core", "dep:aws-sdk-sqs"]
sources-datadog_agent = ["sources-utils-http-error", "protobuf-build", "dep:prost"]
sources-demo_logs = ["dep:fakedata"]
sources-dnstap = ["sources-utils-net-tcp", "dep:base64", "dep:hickory-proto", "dep:dnsmsg-parser", "protobuf-build", "dep:prost"]
sources-dnstap = ["sources-utils-net-tcp", "dep:base64", "dep:hickory-proto", "dep:dnsmsg-parser", "dep:dnstap-parser", "protobuf-build", "dep:prost"]
sources-docker_logs = ["docker"]
sources-eventstoredb_metrics = []
sources-exec = []
Expand Down
1 change: 1 addition & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ modules:
- path: lib/vector-core/proto
- path: proto/third-party
- path: proto/vector
- path: lib/dnstap-parser/proto
lint:
use:
- DEFAULT
Expand Down
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ fn main() {

#[cfg(feature = "protobuf-build")]
{
println!("cargo:rerun-if-changed=proto/third-party/dnstap.proto");
println!("cargo:rerun-if-changed=proto/third-party/google/pubsub/v1/pubsub.proto");
println!("cargo:rerun-if-changed=proto/third-party/google/rpc/status.proto");
println!("cargo:rerun-if-changed=proto/vector/dd_metric.proto");
Expand Down Expand Up @@ -144,7 +143,6 @@ fn main() {
prost_build,
&[
"lib/vector-core/proto/event.proto",
"proto/third-party/dnstap.proto",
"proto/vector/ddsketch_full.proto",
"proto/vector/dd_metric.proto",
"proto/vector/dd_trace.proto",
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/21985_parse_dnstap.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add VRL function `parse_dnstap` that can parse dnstap data and produce output in the same format as `dnstap` source.

authors: esensar
2 changes: 1 addition & 1 deletion lib/dnsmsg-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"

[dependencies]
data-encoding = "2.6"
hickory-proto = { version = "0.24", features = ["dnssec"] }
hickory-proto.workspace = true
snafu.workspace = true

[dev-dependencies]
Expand Down
26 changes: 26 additions & 0 deletions lib/dnstap-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "dnstap-parser"
version = "0.1.0"
authors = ["Vector Contributors <vector@datadoghq.com>"]
edition = "2021"
publish = false
license = "MIT"

[dependencies]
base64 = { version = "0.22.1", default-features = false }
bytes = { version = "1.9.0", default-features = false, features = ["serde"] }
chrono.workspace = true
dnsmsg-parser = { path = "../dnsmsg-parser" }
hickory-proto.workspace = true
prost.workspace = true
snafu.workspace = true
tracing = { version = "0.1.34", default-features = false }
vector-lib = { path = "../vector-lib" }
vrl.workspace = true

[build-dependencies]
prost-build.workspace = true

[dev-dependencies]
anyhow.workspace = true
chrono-tz.workspace = true
8 changes: 8 additions & 0 deletions lib/dnstap-parser/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
println!("cargo:rerun-if-changed=proto/dnstap.proto");
let mut prost_build = prost_build::Config::new();
prost_build.btree_map(["."]);
prost_build
.compile_protos(&["proto/dnstap.proto"], &["proto"])
.expect("Failed to compile proto files");
}
File renamed without changes.
20 changes: 20 additions & 0 deletions lib/dnstap-parser/src/internal_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use tracing::warn;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
pub(crate) struct DnstapParseWarning<E> {
pub error: E,
}

impl<E: std::fmt::Display> InternalEvent for DnstapParseWarning<E> {
fn emit(self) {
warn!(
message = "Recoverable error occurred while parsing dnstap data.",
error = %self.error,
stage = error_stage::PROCESSING,
error_type = error_type::PARSER_FAILED,
internal_log_rate_limit = true,
);
}
}
12 changes: 12 additions & 0 deletions lib/dnstap-parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![deny(warnings)]

use vrl::compiler::Function;

mod internal_events;
pub mod parser;
pub mod schema;
mod vrl_functions;

pub fn vrl_functions() -> Vec<Box<dyn Function>> {
vrl_functions::all()
}
14 changes: 7 additions & 7 deletions src/sources/dnstap/parser.rs → lib/dnstap-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr},
sync::LazyLock,
};
use vector_lib::emit;

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

use crate::{
use vector_lib::{
event::{LogEvent, Value},
internal_events::DnstapParseWarning,
Error, Result,
};

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

use crate::sources::dnstap::schema::DNSTAP_VALUE_PATHS;
use crate::{internal_events::DnstapParseWarning, schema::DNSTAP_VALUE_PATHS};
use dnstap_proto::{
message::Type as DnstapMessageType, Dnstap, Message as DnstapMessage, SocketFamily,
SocketProtocol,
Expand All @@ -38,7 +38,7 @@ use vector_lib::config::log_schema;
use vector_lib::lookup::lookup_v2::ValuePath;
use vector_lib::lookup::PathPrefix;

use super::{
use dnsmsg_parser::{
dns_message::{
DnsRecord, EdnsOptionEntry, OptPseudoSection, QueryHeader, QueryQuestion, UpdateHeader,
ZoneInfo,
Expand Down Expand Up @@ -459,14 +459,15 @@ impl DnstapParser {
);
}

Ok(if let Some(response_port) = dnstap_message.response_port {
if let Some(response_port) = dnstap_message.response_port {
DnstapParser::insert(
event,
prefix.clone(),
&DNSTAP_VALUE_PATHS.response_port,
response_port,
);
})
};
Ok(())
}

fn log_time<'a>(
Expand Down Expand Up @@ -1015,7 +1016,6 @@ fn to_dnstap_message_type(type_id: i32) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::event::Value;
use chrono::DateTime;
use dnsmsg_parser::dns_message_parser::DnsParserOptions;
use std::collections::BTreeMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct DnstapEventSchema;

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

/// Lazily initialized singleton.
pub(crate) static DNSTAP_VALUE_PATHS: LazyLock<DnstapPaths> = LazyLock::new(|| DnstapPaths {
pub static DNSTAP_VALUE_PATHS: LazyLock<DnstapPaths> = LazyLock::new(|| DnstapPaths {
server_identity: owned_value_path!("serverId"),
server_version: owned_value_path!("serverVersion"),
extra: owned_value_path!("extraInfo"),
Expand Down
7 changes: 7 additions & 0 deletions lib/dnstap-parser/src/vrl_functions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use vrl::compiler::Function;

pub mod parse_dnstap;

pub fn all() -> Vec<Box<dyn Function>> {
vec![Box::new(parse_dnstap::ParseDnstap) as _]
}
Loading

0 comments on commit 29ecaac

Please sign in to comment.