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

ref(pattern): Replace regex based matching #4073

Merged
merged 16 commits into from
Oct 2, 2024
Merged
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Rust
**/*.rs.bk
target
**/fuzz/corpus
**/fuzz/artifacts
**/fuzz/coverage
**/fuzz/*.html
*.pending-snap

# Python
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
**Internal:**

- Add the dynamic sampling rate to standalone spans as a measurement so that it can be stored, queried, and used for extrapolation. ([#4063](https://github.com/getsentry/relay/pull/4063))
- Use custom wildcard matching instead of regular expressions. ([#4073](https://github.com/getsentry/relay/pull/4073))
- Allowlist the SentryUptimeBot user-agent. ([#4068](https://github.com/getsentry/relay/pull/4068))

## 24.9.0
Expand Down
26 changes: 25 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["relay", "relay-*", "tools/*"]
members = ["relay", "relay-*", "relay-*/fuzz/", "tools/*"]
default-members = ["relay"]
resolver = "2"

Expand Down
1 change: 0 additions & 1 deletion relay-pattern/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ serde = ["dep:serde"]

[dependencies]
memchr = { workspace = true }
regex-lite = { workspace = true }
serde = { workspace = true, optional = true}

[dev-dependencies]
Expand Down
23 changes: 22 additions & 1 deletion relay-pattern/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ use criterion::{criterion_group, criterion_main, BenchmarkGroup, Criterion};
use relay_pattern::Pattern;

fn bench(group: &mut BenchmarkGroup<'_, WallTime>, haystack: &str, needle: &str) {
group.bench_function("pattern", |b| {
group.bench_function("case_sensitive", |b| {
let pattern = Pattern::new(needle).unwrap();
b.iter(|| assert!(pattern.is_match(haystack)))
});

group.bench_function("case_insensitive", |b| {
let pattern = Pattern::builder(needle)
.case_insensitive(true)
.build()
.unwrap();
b.iter(|| assert!(pattern.is_match(haystack)))
});
}

fn literal_match(c: &mut Criterion) {
Expand Down Expand Up @@ -64,12 +72,25 @@ fn wildcard_match(c: &mut Criterion) {
group.finish();
}

fn complex_match(c: &mut Criterion) {
let mut group = c.benchmark_group("complex_match");

const HAYSTACK: &str = "foobarwithacrazylongprefixandanditactuallymatches";
const NEEDLE: &str =
"*b??{foo,bar,baz,with}*cr{x,y,z,?}zyl[a-z]ng{suffix,pr?*ix}*it?**?uallymatches";

bench(&mut group, HAYSTACK, NEEDLE);

group.finish();
}

criterion_group!(
benches,
literal_match,
prefix_match,
suffix_match,
contains_match,
wildcard_match,
complex_match,
);
criterion_main!(benches);
26 changes: 26 additions & 0 deletions relay-pattern/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "relay-pattern-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
relay-pattern = { path = ".." }

[[bin]]
name = "is_match_case_sensitive"
path = "fuzz_targets/is_match_case_sensitive.rs"
test = false
doc = false
bench = false

[[bin]]
name = "is_match_case_insensitive"
path = "fuzz_targets/is_match_case_insensitive.rs"
test = false
doc = false
bench = false
13 changes: 13 additions & 0 deletions relay-pattern/fuzz/fuzz_targets/is_match_case_insensitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

fuzz_target!(|input: (&str, &str)| {
let (pattern, haystack) = input;
if let Ok(pattern) = relay_pattern::Pattern::builder(pattern)
.case_insensitive(true)
.build()
{
std::hint::black_box(pattern.is_match(haystack));
}
});
10 changes: 10 additions & 0 deletions relay-pattern/fuzz/fuzz_targets/is_match_case_sensitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

fuzz_target!(|input: (&str, &str)| {
let (pattern, haystack) = input;
if let Ok(pattern) = relay_pattern::Pattern::new(pattern) {
std::hint::black_box(pattern.is_match(haystack));
}
});
Loading
Loading