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

enhancement(remap transform): Rename and document drop_on_error #6750

Merged
merged 4 commits into from Mar 12, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions benches/remap.rs
Expand Up @@ -46,7 +46,7 @@ fn benchmark_remap(c: &mut Criterion) {
.copy = string!(.copy_from)
"#}
.to_string(),
drop_on_err: true,
drop_on_error: true,
})
.unwrap(),
);
Expand Down Expand Up @@ -106,7 +106,7 @@ fn benchmark_remap(c: &mut Criterion) {
let mut tform: Box<dyn FunctionTransform> = Box::new(
Remap::new(RemapConfig {
source: ".bar = parse_json!(string!(.foo))".to_owned(),
drop_on_err: false,
drop_on_error: false,
})
.unwrap(),
);
Expand Down Expand Up @@ -175,7 +175,7 @@ fn benchmark_remap(c: &mut Criterion) {
.timestamp = parse_timestamp!(string!(.timestamp), format: "%d/%m/%Y:%H:%M:%S %z")
"#}
.to_owned(),
drop_on_err: true,
drop_on_error: true,
})
.unwrap(),
);
Expand Down
2 changes: 1 addition & 1 deletion benches/wasm/mod.rs
Expand Up @@ -83,7 +83,7 @@ pub fn add_fields(criterion: &mut Criterion) {
.test_key2 = "test_value2"
"#}
.to_string(),
drop_on_err: false,
drop_on_error: false,
})
.unwrap(),
),
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/components/transforms/remap.cue
Expand Up @@ -64,6 +64,16 @@ components: transforms: "remap": {
syntax: "remap_program"
}
}
drop_on_error: {
common: false
required: false
description: """
Drop the event if the VRL program returns an error at runtime.
"""
type: bool: {
default: false
}
}
}

input: {
Expand Down
20 changes: 10 additions & 10 deletions src/transforms/remap.rs
Expand Up @@ -14,7 +14,7 @@ use vrl::{Program, Runtime};
#[derivative(Default)]
pub struct RemapConfig {
pub source: String,
pub drop_on_err: bool,
pub drop_on_error: bool,
}

inventory::submit! {
Expand Down Expand Up @@ -46,7 +46,7 @@ impl TransformConfig for RemapConfig {
#[derive(Debug, Clone)]
pub struct Remap {
program: Program,
drop_on_err: bool,
drop_on_error: bool,
}

impl Remap {
Expand All @@ -59,14 +59,14 @@ impl Remap {

Ok(Remap {
program,
drop_on_err: config.drop_on_err,
drop_on_error: config.drop_on_error,
})
}
}

impl FunctionTransform for Remap {
fn transform(&mut self, output: &mut Vec<Event>, mut event: Event) {
let original_event = if !self.drop_on_err && self.program.is_fallible() {
let original_event = if !self.drop_on_error && self.program.is_fallible() {
// We need to clone the original event, since it might be mutated by
// the program before it aborts, while we want to return the
// unmodified event when an error occurs.
Expand All @@ -87,10 +87,10 @@ impl FunctionTransform for Remap {
Err(error) => {
emit!(RemapMappingError {
error: error.to_string(),
event_dropped: self.drop_on_err,
event_dropped: self.drop_on_error,
});

if self.drop_on_err {
if self.drop_on_error {
return;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ mod tests {
.copy = .copy_from
"#
.to_string(),
drop_on_err: true,
drop_on_error: true,
};
let mut tform = Remap::new(conf).unwrap();

Expand All @@ -159,7 +159,7 @@ mod tests {
.not_an_int = int!(.bar)
.baz = 12
"#},
drop_on_err: false,
drop_on_error: false,
};
let mut tform = Remap::new(conf).unwrap();

Expand All @@ -184,7 +184,7 @@ mod tests {
.foo = "foo"
.baz = 12
"#},
drop_on_err: false,
drop_on_error: false,
};
let mut tform = Remap::new(conf).unwrap();

Expand All @@ -209,7 +209,7 @@ mod tests {
.namespace = "zerk"
.kind = "incremental""#
.to_string(),
drop_on_err: true,
drop_on_error: true,
};
let mut tform = Remap::new(conf).unwrap();

Expand Down
16 changes: 8 additions & 8 deletions tests/behavior/transforms/remap.toml
Expand Up @@ -83,7 +83,7 @@
[transforms.remap_arithmetic_error]
inputs = []
type = "remap"
drop_on_err = true
drop_on_error = true
source = """
a = 10
b = 0
Expand Down Expand Up @@ -319,7 +319,7 @@
[transforms.remap_function_upcase_error]
inputs = []
type = "remap"
drop_on_err = true
drop_on_error = true
source = """
.a = upcase(string!(.a))
.b = upcase(string!(.b))
Expand All @@ -337,7 +337,7 @@
[transforms.remap_function_downcase]
inputs = []
type = "remap"
drop_on_err = true
drop_on_error = true
source = """
.a = downcase(string!(.a))
.b = downcase(string!(.b))
Expand Down Expand Up @@ -371,7 +371,7 @@
[transforms.remap_function_downcase_error]
inputs = []
type = "remap"
drop_on_err = true
drop_on_error = true
source = """
.a = downcase(string!(.a))
.b = downcase(string!(.b))
Expand Down Expand Up @@ -442,7 +442,7 @@
[transforms.remap_function_sha1_error]
inputs = []
type = "remap"
drop_on_err = true
drop_on_error = true
source = """
.a = sha1(string!(.a))
.b = sha1(string!(.b))
Expand Down Expand Up @@ -487,7 +487,7 @@
[transforms.remap_function_md5_error]
inputs = []
type = "remap"
drop_on_err = true
drop_on_error = true
source = """
.a = md5(string!(.a))
.b = md5(string!(.b))
Expand Down Expand Up @@ -1331,7 +1331,7 @@
# [transforms.remap_function_assert_pass]
# inputs = []
# type = "remap"
# drop_on_err = true
# drop_on_error = true
# source = """
# assert!(.foo, message: "assert failed")
# .check = "checked"
Expand All @@ -1354,7 +1354,7 @@
# [transforms.remap_function_assert_fail]
# inputs = []
# type = "remap"
# drop_on_err = true
# drop_on_error = true
# source = """
# assert!(.foo, message: "assert failed")
# """
Expand Down