Skip to content

Commit 1cf67a9

Browse files
committed
Rename regexes to patterns
1 parent 51faace commit 1cf67a9

File tree

12 files changed

+30203
-32034
lines changed

12 files changed

+30203
-32034
lines changed

.meta/transforms/regex_parser.toml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If `target_field` is set and the log contains a field of the same name \
3838
as the target, it will only be overwritten if this is set to `true`.\
3939
"""
4040

41-
[transforms.regex_parser.options.regexes]
41+
[transforms.regex_parser.options.patterns]
4242
type = "string"
4343
common = true
4444
examples = [
@@ -85,7 +85,7 @@ And the following configuration:
8585
[transforms.<transform-id>]
8686
type = "regex_parser"
8787
field = "message"
88-
regexes = ['^(?P<host>[\w\.]+) - (?P<user>[\w]+) (?P<bytes_in>[\d]+) \[(?P<timestamp>.*)\] "(?P<method>[\w]+) (?P<path>.*)" (?P<status>[\d]+) (?P<bytes_out>[\d]+)$']
88+
patterns = ['^(?P<host>[\w\.]+) - (?P<user>[\w]+) (?P<bytes_in>[\d]+) \[(?P<timestamp>.*)\] "(?P<method>[\w]+) (?P<path>.*)" (?P<status>[\d]+) (?P<bytes_out>[\d]+)$']
8989

9090
[transforms.<transform-id>.types]
9191
bytes_in = "int"

benches/bench.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn benchmark_transforms(c: &mut Criterion) {
346346
"parser",
347347
&["in"],
348348
transforms::regex_parser::RegexParserConfig {
349-
regexes: vec![r"status=(?P<status>\d+)".to_string()],
349+
patterns: vec![r"status=(?P<status>\d+)".to_string()],
350350
field: None,
351351
..Default::default()
352352
},
@@ -410,7 +410,7 @@ fn benchmark_regex(c: &mut Criterion) {
410410
let rt = vector::runtime::Runtime::single_threaded().unwrap();
411411
let parser =transforms::regex_parser::RegexParserConfig {
412412
// Many captures to stress the regex parser
413-
regexes: vec![r#"^(?P<addr>\d+\.\d+\.\d+\.\d+) (?P<user>\S+) (?P<auth>\S+) \[(?P<date>\d+/[A-Za-z]+/\d+:\d+:\d+:\d+ [+-]\d{4})\] "(?P<method>[A-Z]+) (?P<uri>[^"]+) HTTP/\d\.\d" (?P<code>\d+) (?P<size>\d+) "(?P<referrer>[^"]+)" "(?P<browser>[^"]+)""#.into()],
413+
patterns: vec![r#"^(?P<addr>\d+\.\d+\.\d+\.\d+) (?P<user>\S+) (?P<auth>\S+) \[(?P<date>\d+/[A-Za-z]+/\d+:\d+:\d+:\d+ [+-]\d{4})\] "(?P<method>[A-Z]+) (?P<uri>[^"]+) HTTP/\d\.\d" (?P<code>\d+) (?P<size>\d+) "(?P<referrer>[^"]+)" "(?P<browser>[^"]+)""#.into()],
414414
field: None,
415415
drop_failed: true,
416416
..Default::default()
@@ -465,7 +465,7 @@ fn benchmark_complex(c: &mut Criterion) {
465465
"parser",
466466
&["in1", "in2"],
467467
transforms::regex_parser::RegexParserConfig {
468-
regexes: vec![r"status=(?P<status>\d+)".to_string()],
468+
patterns: vec![r"status=(?P<status>\d+)".to_string()],
469469
field: None,
470470
..Default::default()
471471
},

config/examples/docs_example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ data_dir = "/var/lib/vector"
1111
[transforms.apache_parser]
1212
inputs = ["apache_logs"]
1313
type = "regex_parser" # fast/powerful regex
14-
regexes = ['^(?P<host>[w.]+) - (?P<user>[w]+) (?P<bytes_in>[d]+) [(?P<timestamp>.*)] "(?P<method>[w]+) (?P<path>.*)" (?P<status>[d]+) (?P<bytes_out>[d]+)$']
14+
patterns = ['^(?P<host>[w.]+) - (?P<user>[w]+) (?P<bytes_in>[d]+) [(?P<timestamp>.*)] "(?P<method>[w]+) (?P<path>.*)" (?P<status>[d]+) (?P<bytes_out>[d]+)$']
1515

1616
# Sample the data to save on cost
1717
[transforms.apache_sampler]

config/examples/file_to_cloudwatch_metrics.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ start_at_beginning = true
1414
[transforms.regex_parser]
1515
inputs = ["file"]
1616
type = "regex_parser"
17-
regexes = ['^(?P<host>[\w\.]+) - (?P<user>[\w-]+) \[(?P<timestamp>.*)\] "(?P<method>[\w]+) (?P<path>.*)" (?P<status>[\d]+) (?P<bytes_out>[\d]+)$']
17+
patterns = ['^(?P<host>[\w\.]+) - (?P<user>[\w-]+) \[(?P<timestamp>.*)\] "(?P<method>[\w]+) (?P<path>.*)" (?P<status>[\d]+) (?P<bytes_out>[\d]+)$']
1818

1919
# Transform into metrics
2020
[transforms.log_to_metric]

config/examples/file_to_prometheus.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ start_at_beginning = true
1414
[transforms.regex_parser]
1515
inputs = ["file"]
1616
type = "regex_parser"
17-
regexes = ['^(?P<host>[\w\.]+) - (?P<user>[\w-]+) \[(?P<timestamp>.*)\] "(?P<method>[\w]+) (?P<path>.*)" (?P<status>[\d]+) (?P<bytes_out>[\d]+)$']
17+
patterns = ['^(?P<host>[\w\.]+) - (?P<user>[\w-]+) \[(?P<timestamp>.*)\] "(?P<method>[\w]+) (?P<path>.*)" (?P<status>[\d]+) (?P<bytes_out>[\d]+)$']
1818

1919
# Transform into metrics
2020
[transforms.log_to_metric]

config/vector.spec.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,7 @@ require('custom_module')
22072207
#
22082208
# * required
22092209
# * type: string
2210-
regexes = "['^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$']"
2210+
patterns = "['^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$']"
22112211

22122212
# If this setting is present, the parsed fields will be inserted into the log
22132213
# as a sub-object with this name. If a field with the same name already exists,

src/transforms/regex_parser.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use string_cache::DefaultAtom as Atom;
1616
#[derivative(Default)]
1717
#[serde(default, deny_unknown_fields)]
1818
pub struct RegexParserConfig {
19-
/// Deprecated. Use `regexes` instead.
19+
/// Deprecated. Use `patterns` instead.
2020
/// See #2469.
2121
/// TODO: Remove at a future point in time.
2222
regex: Option<String>,
23-
pub regexes: Vec<String>,
23+
pub patterns: Vec<String>,
2424
pub field: Option<Atom>,
2525
#[derivative(Default(value = "true"))]
2626
pub drop_field: bool,
@@ -56,7 +56,7 @@ impl TransformConfig for RegexParserConfig {
5656

5757
pub struct RegexParser {
5858
regexset: RegexSet,
59-
regexes: Vec<Regex>,
59+
patterns: Vec<Regex>,
6060
field: Atom,
6161
drop_field: bool,
6262
drop_failed: bool,
@@ -73,41 +73,41 @@ impl RegexParser {
7373
.as_ref()
7474
.unwrap_or(&event::log_schema().message_key());
7575

76-
let regexes = match (&config.regex, &config.regexes.len()) {
76+
let patterns = match (&config.regex, &config.patterns.len()) {
7777
(None, 0) => {
7878
return Err(
79-
"At least one regular expression must be defined, but `regexes` is empty"
79+
"At least one regular expression must be defined, but `patterns` is empty"
8080
.into(),
8181
);
8282
}
83-
(None, _) => config.regexes.clone(),
83+
(None, _) => config.patterns.clone(),
8484
(Some(regex), 0) => {
8585
// Still using the old `regex` syntax.
8686
// Printing a warning and wrapping input in a `vec`.
8787
warn!(
8888
"Usage of `regex` is deprecated and will be removed in a future version. \
89-
Please upgrade your config to use `regexes` instead: \
90-
`regexes = ['{}']`",
89+
Please upgrade your config to use `patterns` instead: \
90+
`patterns = ['{}']`",
9191
&regex
9292
);
9393
vec![regex.clone()]
9494
}
9595
_ => {
96-
return Err("`regexes = [...]` is not defined".into());
96+
return Err("`patterns = [...]` is not defined".into());
9797
}
9898
};
9999

100-
let regexset = RegexSet::new(&regexes).context(super::InvalidRegex)?;
100+
let regexset = RegexSet::new(&patterns).context(super::InvalidRegex)?;
101101

102-
// Pre-compile individual regexes
103-
let regexes: Result<Vec<Regex>, _> = regexset
102+
// Pre-compile individual patterns
103+
let patterns: Result<Vec<Regex>, _> = regexset
104104
.patterns()
105105
.iter()
106106
.map(|pattern| Regex::new(pattern))
107107
.collect();
108-
let regexes = regexes.context(super::InvalidRegex)?;
108+
let patterns = patterns.context(super::InvalidRegex)?;
109109

110-
let names = &regexes
110+
let names = &patterns
111111
.iter()
112112
.map(|regex| {
113113
regex
@@ -122,7 +122,7 @@ impl RegexParser {
122122

123123
Ok(Box::new(RegexParser::new(
124124
regexset,
125-
regexes,
125+
patterns,
126126
field.clone(),
127127
config.drop_field,
128128
config.drop_failed,
@@ -134,7 +134,7 @@ impl RegexParser {
134134

135135
pub fn new(
136136
regexset: RegexSet,
137-
regexes: Vec<Regex>,
137+
patterns: Vec<Regex>,
138138
field: Atom,
139139
mut drop_field: bool,
140140
drop_failed: bool,
@@ -144,14 +144,14 @@ impl RegexParser {
144144
) -> Self {
145145
// Build a buffer of the regex capture locations to avoid
146146
// repeated allocations.
147-
let capture_locs = regexes
147+
let capture_locs = patterns
148148
.iter()
149149
.map(|regex| regex.capture_locations())
150150
.collect();
151151

152152
// Calculate the location (index into the capture locations) of
153153
// each named capture, and the required type coercion.
154-
let capture_names: Vec<(usize, Atom, Conversion)> = regexes
154+
let capture_names: Vec<(usize, Atom, Conversion)> = patterns
155155
.iter()
156156
.map(|regex| {
157157
let capture_names: Vec<(usize, Atom, Conversion)> = regex
@@ -175,7 +175,7 @@ impl RegexParser {
175175

176176
Self {
177177
regexset,
178-
regexes,
178+
patterns,
179179
field,
180180
drop_field,
181181
drop_failed,
@@ -215,7 +215,7 @@ impl Transform for RegexParser {
215215
}
216216
};
217217

218-
if self.regexes[id]
218+
if self.patterns[id]
219219
.captures_read(&mut capture_locs, &value)
220220
.is_some()
221221
{
@@ -281,15 +281,15 @@ mod tests {
281281
Event,
282282
};
283283

284-
fn do_transform(event: &str, regexes: &str, config: &str) -> Option<LogEvent> {
284+
fn do_transform(event: &str, patterns: &str, config: &str) -> Option<LogEvent> {
285285
let rt = crate::runtime::Runtime::single_threaded().unwrap();
286286
let event = Event::from(event);
287287
let mut parser = toml::from_str::<RegexParserConfig>(&format!(
288288
r#"
289-
regexes = {}
289+
patterns = {}
290290
{}
291291
"#,
292-
regexes, config
292+
patterns, config
293293
))
294294
.unwrap()
295295
.build(TransformContext::new_test(rt.executor()))

tests/behavior/transforms/regex_parser.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[transforms.regex_parser_simple]
22
inputs = []
33
type = "regex_parser"
4-
regexes = ["^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$"]
4+
patterns = ["^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$"]
55
[[tests]]
66
name = "regex_parser_simple"
77
[tests.input]
@@ -18,7 +18,7 @@
1818
[transforms.regex_parser_target]
1919
inputs = []
2020
type = "regex_parser"
21-
regexes = ["^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$"]
21+
patterns = ["^(?P<timestamp>[\\w\\-:\\+]+) (?P<level>\\w+) (?P<message>.*)$"]
2222
target_field = "something"
2323
[[tests]]
2424
name = "regex_parser_target"

tests/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn bad_regex() {
214214
[transforms.parser]
215215
type = "regex_parser"
216216
inputs = ["in"]
217-
regexes = ["(["]
217+
patterns = ["(["]
218218
219219
[sinks.out]
220220
type = "socket"

0 commit comments

Comments
 (0)