forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: A new internal lookup (vectordotdev#4066)
* wip Signed-off-by: Ana Hobden <[email protected]> * Refine new lookup a bunch, handle indexes Signed-off-by: Ana Hobden <[email protected]> * Better logging Signed-off-by: Ana Hobden <[email protected]> * Better logging Signed-off-by: Ana Hobden <[email protected]> * wip Signed-off-by: Ana Hobden <[email protected]> * add files I forgot Signed-off-by: Ana Hobden <[email protected]> * More Signed-off-by: Ana Hobden <[email protected]> * Fixup Signed-off-by: Ana Hobden <[email protected]> * I MADE AN ICE Signed-off-by: Ana Hobden <[email protected]> * Start adding to add_fields Signed-off-by: Ana Hobden <[email protected]> * Integrate with add_fields Signed-off-by: Ana Hobden <[email protected]> * Add fixture tests Signed-off-by: Ana Hobden <[email protected]> * Add a test Signed-off-by: Ana Hobden <[email protected]> * Add serializing and deserializing Signed-off-by: Ana Hobden <[email protected]> * add some benches Signed-off-by: Ana Hobden <[email protected]> * Finalize benches Signed-off-by: Ana Hobden <[email protected]> * fmt Signed-off-by: Ana Hobden <[email protected]> * Handle rename Signed-off-by: Ana Hobden <[email protected]> * Fix lints Signed-off-by: Ana Hobden <[email protected]> * Update RFC Signed-off-by: Ana Hobden <[email protected]> * Fix tests Signed-off-by: Ana Hobden <[email protected]> * Add a bit more API Signed-off-by: Ana Hobden <[email protected]> * Comments Signed-off-by: Ana Hobden <[email protected]> * Fixup Signed-off-by: Ana Hobden <[email protected]> * fmt Signed-off-by: Ana Hobden <[email protected]> * touchups Signed-off-by: Ana Hobden <[email protected]> * Clean up some lints Signed-off-by: Ana Hobden <[email protected]> * Fmt Signed-off-by: Ana Hobden <[email protected]> * Fixups of clippy Signed-off-by: Ana Hobden <[email protected]> * fmt Signed-off-by: Ana Hobden <[email protected]> * Lint fixups Signed-off-by: Ana Hobden <[email protected]> * Fixup Signed-off-by: Ana Hobden <[email protected]>
- Loading branch information
Showing
41 changed files
with
983 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
use indexmap::map::IndexMap; | ||
use std::convert::TryFrom; | ||
use std::{fs, io::Read, path::Path}; | ||
use vector::event::Lookup; | ||
|
||
const FIXTURE_ROOT: &str = "tests/data/fixtures/lookup"; | ||
|
||
fn parse_artifact(path: impl AsRef<Path>) -> std::io::Result<String> { | ||
let mut test_file = match fs::File::open(path) { | ||
Ok(file) => file, | ||
Err(e) => return Err(e), | ||
}; | ||
|
||
let mut buf = Vec::new(); | ||
test_file.read_to_end(&mut buf)?; | ||
let string = String::from_utf8(buf).unwrap(); | ||
Ok(string) | ||
} | ||
|
||
// This test iterates over the `tests/data/fixtures/lookup` folder and ensures the lookup parsed, | ||
// then turned into a string again is the same. | ||
fn lookup_to_string(c: &mut Criterion) { | ||
vector::test_util::trace_init(); | ||
let mut fixtures = IndexMap::new(); | ||
|
||
std::fs::read_dir(FIXTURE_ROOT) | ||
.unwrap() | ||
.for_each(|fixture_file| match fixture_file { | ||
Ok(fixture_file) => { | ||
let path = fixture_file.path(); | ||
tracing::trace!(?path, "Opening."); | ||
let buf = parse_artifact(&path).unwrap(); | ||
fixtures.insert(path, buf); | ||
} | ||
_ => panic!("This test should never read Err'ing test fixtures."), | ||
}); | ||
|
||
let mut group_from_elem = c.benchmark_group("from_string"); | ||
for (_path, fixture) in fixtures.iter() { | ||
group_from_elem.throughput(Throughput::Bytes(fixture.clone().into_bytes().len() as u64)); | ||
group_from_elem.bench_with_input( | ||
BenchmarkId::from_parameter(&fixture), | ||
&fixture.clone(), | ||
move |b, ref param| { | ||
let input = &(*param).clone(); | ||
b.iter_with_setup( | ||
|| input.clone(), | ||
|input| { | ||
let lookup = Lookup::try_from(input).unwrap(); | ||
black_box(lookup) | ||
}, | ||
) | ||
}, | ||
); | ||
} | ||
group_from_elem.finish(); | ||
|
||
let mut group_to_string = c.benchmark_group("to_string"); | ||
for (_path, fixture) in fixtures.iter() { | ||
group_to_string.throughput(Throughput::Bytes(fixture.clone().into_bytes().len() as u64)); | ||
group_to_string.bench_with_input( | ||
BenchmarkId::from_parameter(&fixture), | ||
&fixture.clone(), | ||
move |b, ref param| { | ||
let input = &(*param).clone(); | ||
b.iter_with_setup( | ||
|| Lookup::try_from(input.clone()).unwrap(), | ||
|input| { | ||
let string = input.to_string(); | ||
black_box(string) | ||
}, | ||
) | ||
}, | ||
); | ||
} | ||
group_to_string.finish(); | ||
|
||
let mut group_serialize = c.benchmark_group("serialize"); | ||
for (_path, fixture) in fixtures.iter() { | ||
group_serialize.throughput(Throughput::Bytes(fixture.clone().into_bytes().len() as u64)); | ||
group_serialize.bench_with_input( | ||
BenchmarkId::from_parameter(&fixture), | ||
&fixture.clone(), | ||
move |b, ref param| { | ||
let input = &(*param).clone(); | ||
b.iter_with_setup( | ||
|| Lookup::try_from(input.clone()).unwrap(), | ||
|input| { | ||
let string = serde_json::to_string(&input); | ||
black_box(string) | ||
}, | ||
) | ||
}, | ||
); | ||
} | ||
group_serialize.finish(); | ||
|
||
let mut group_deserialize = c.benchmark_group("deserialize"); | ||
for (_path, fixture) in fixtures.iter() { | ||
group_deserialize.throughput(Throughput::Bytes(fixture.clone().into_bytes().len() as u64)); | ||
group_deserialize.bench_with_input( | ||
BenchmarkId::from_parameter(&fixture), | ||
&fixture.clone(), | ||
move |b, ref param| { | ||
let input = &(*param).clone(); | ||
b.iter_with_setup( | ||
|| serde_json::to_string(&Lookup::try_from(input.clone()).unwrap()).unwrap(), | ||
|input| { | ||
let lookup: Lookup = serde_json::from_str(&input).unwrap(); | ||
black_box(lookup) | ||
}, | ||
) | ||
}, | ||
); | ||
} | ||
group_deserialize.finish(); | ||
} | ||
|
||
criterion_group!(lookup, lookup_to_string); | ||
criterion_main!(lookup); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.