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

feat(new transform): New remap transform #3341

Merged
merged 33 commits into from
Sep 9, 2020
Merged

feat(new transform): New remap transform #3341

merged 33 commits into from
Sep 9, 2020

Conversation

Jeffail
Copy link
Contributor

@Jeffail Jeffail commented Aug 4, 2020

Implements a new remap transform following https://github.com/timberio/vector/blob/master/rfcs/2020-07-21-2744-remapping-syntax.md, which provides a mapping language for expressing a series of translations for events:

[transforms.mapper]
  inputs = [ "foo" ]
  type = "remap"
  mapping = """
    .foo = .bar
    del(.bar)
    .baz = "something literal"
  """

In order to mutate events with the existing API I've had to make a few value utility functions public, I'm hoping this is only temporary and that https://github.com/timberio/vector/blob/master/rfcs/2020-05-25-2692-more-usable-logevents.md will address some of the oddness of the API.

I've added TODO comments anywhere that uses event API's that are obsolete or just seem wrong to me, but in terms of functionality we seem to be okay for now, so no need to rush in those changes.

Path escaping is not currently implemented, my goal was to implement quoted segments like .foo."bar.baz".buz but I haven't dug into the event APIs enough to see if that's convenient. I'll take another look after arithmetic is added but from what I've seen thus far it looks like we're only able to use slash escapes like .foo.bar\.baz.buz so I'll need to translate manually.

Closes #3119
Closes #3467
Closes #3722
Closes https://github.com/timberio/vector-product/issues/70

@binarylogic
Copy link
Contributor

Nice work!

@Jeffail if there was anything obviously wrong with the data model, could you open issues and add them to https://github.com/timberio/vector-product/issues/8?

src/transforms/remap.rs Outdated Show resolved Hide resolved
src/mapping/query/path.rs Show resolved Hide resolved
src/mapping/mod.rs Outdated Show resolved Hide resolved
src/mapping/mod.rs Show resolved Hide resolved
src/mapping/parser/mod.rs Outdated Show resolved Hide resolved
src/mapping/query/path.rs Outdated Show resolved Hide resolved
@Jeffail Jeffail force-pushed the remap-transform branch 2 times, most recently from 3eed634 to b48d2b0 Compare August 11, 2020 09:56
@Jeffail Jeffail marked this pull request as ready for review August 11, 2020 14:30
@Hoverbear
Copy link
Contributor

Where is the CI on this? 🤔

@@ -665,6 +673,90 @@ fn bench_elasticsearch_index(c: &mut Criterion) {
);
}

fn benchmark_remap(c: &mut Criterion) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/release/deps/bench-0f9a98460f4dba0d
add fields with remap   time:   [1.3603 us 1.3614 us 1.3625 us]                                   
                        change: [-1.5879% +0.1667% +1.5785%] (p = 0.84 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

add fields with add_fields                                                                             
                        time:   [2.2038 us 2.2086 us 2.2152 us]
                        change: [-0.9292% -0.6531% -0.2980%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  3 (3.00%) high severe

Very nice. Good job. :)

use serde_json::json;

#[test]
fn check_path_query() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be useful to see whitespace including tests. Eg .foo\ bar\ baz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realised from this that I hadn't even implemented quoted path segments yet so good catch!

Jeffail added 13 commits August 18, 2020 10:07
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
Signed-off-by: Ashley Jeffs <[email protected]>
@binarylogic binarylogic changed the title feat(new transform): Add remap transform feat(new transform): New remap transform Sep 7, 2020
@JeanMertz JeanMertz requested a review from bruceg September 8, 2020 13:31
statement ~
NEWLINE* ~ "}" )?
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth putting NEWLINE* on either side of the brackets so people can indent Allman style? Someone is inevitably going to try.

Copy link
Member

@bruceg bruceg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments for cleanups you could consider, but they shouldn't change behavior or correctness.

src/mapping/parser/mod.rs Outdated Show resolved Hide resolved
src/mapping/parser/mod.rs Outdated Show resolved Hide resolved
src/mapping/parser/mod.rs Outdated Show resolved Hide resolved
src/mapping/parser/mod.rs Outdated Show resolved Hide resolved
Comment on lines +84 to +104
let (left, right) = coerce_number_types(left?, right?);
match left {
Value::Float(fl) => match right {
Value::Float(fr) => Value::Float(fl * fr),
vr => {
return Err(format!(
"unable to multiply right-hand field type {:?}",
vr
))
}
},
Value::Integer(il) => match right {
Value::Integer(ir) => Value::Integer(il * ir),
vr => {
return Err(format!(
"unable to multiply right-hand field type {:?}",
vr
))
}
},
vl => return Err(format!("unable to multiply left-hand field type {:?}", vl)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the rest of the arms of this could use the match coerce_number_types(left?, right?) treatment.

src/mapping/query/functions.rs Outdated Show resolved Hide resolved
src/mapping/query/functions.rs Outdated Show resolved Hide resolved
use string_cache::DefaultAtom as Atom;

#[derive(Debug)]
pub(in crate::mapping) struct Path {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of annoying how much logic gets duplicated with https://github.com/timberio/vector/blob/master/src/event/util/log/path_iter.rs but I understand why

JeanMertz and others added 5 commits September 9, 2020 12:38
Co-authored-by: Bruce Guenter <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Co-authored-by: Bruce Guenter <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Co-authored-by: Bruce Guenter <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Co-authored-by: Bruce Guenter <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Co-authored-by: Bruce Guenter <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
Signed-off-by: Jean Mertz <[email protected]>
@JeanMertz JeanMertz merged commit 7c5aecb into master Sep 9, 2020
@JeanMertz JeanMertz deleted the remap-transform branch September 9, 2020 14:36
@binarylogic
Copy link
Contributor

Nice work 🎉

@JeanMertz JeanMertz added type: tech debt A code change that does not add user value. and removed type: tech debt A code change that does not add user value. labels Sep 14, 2020
@vector-vic vector-vic mentioned this pull request Sep 16, 2020
mengesb pushed a commit to jacobbraaten/vector that referenced this pull request Dec 9, 2020
Co-authored-by: Bruce Guenter <[email protected]>
Co-authored-by: Jean Mertz <[email protected]>
Signed-off-by: Brian Menges <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: transforms Anything related to Vector's transform components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add coercion functions to the remap syntax Transform to allowlist fields New remap transform v1
8 participants