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(sources): Allow line aggregation to never timeout #4951

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/reference/components/sources.cue
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ components: sources: [Name=string]: {
}
timeout_ms: {
description: "The maximum time to wait for the continuation. Once this timeout is reached, the buffered message is guaranteed to be flushed, even if incomplete."
required: true
required: false
common: true
sort: 4
type: uint: {
default: null
examples: [1_000, 600_000]
unit: "milliseconds"
}
Expand Down
25 changes: 13 additions & 12 deletions src/line_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Config {
/// The maximum time to wait for the continuation. Once this timeout is
/// reached, the buffered message is guaranteed to be flushed, even if
/// incomplete.
pub timeout: Duration,
pub timeout: Option<Duration>,
}

impl Config {
Expand All @@ -70,7 +70,7 @@ impl Config {
let start_pattern = marker;
let condition_pattern = start_pattern.clone();
let mode = Mode::HaltBefore;
let timeout = Duration::from_millis(timeout_ms);
let timeout = Some(Duration::from_millis(timeout_ms));

Self {
start_pattern,
Expand Down Expand Up @@ -351,8 +351,9 @@ where
if self.config.start_pattern.is_match(line.as_ref()) {
// It was indeed a new line we need to filter.
// Set the timeout and buffer this line.
self.timeouts
.insert(entry.key().clone(), self.config.timeout);
if let Some(timeout) = self.config.timeout {
self.timeouts.insert(entry.key().clone(), timeout);
}
entry.insert(Aggregate::new(line, context));
None
} else {
Expand Down Expand Up @@ -419,7 +420,7 @@ mod tests {
start_pattern: Regex::new("^[^\\s]").unwrap(),
condition_pattern: Regex::new("^[\\s]+").unwrap(),
mode: Mode::ContinueThrough,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![
"some usual line",
Expand Down Expand Up @@ -450,7 +451,7 @@ mod tests {
start_pattern: Regex::new("\\\\$").unwrap(),
condition_pattern: Regex::new("\\\\$").unwrap(),
mode: Mode::ContinuePast,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![
"some usual line",
Expand Down Expand Up @@ -481,7 +482,7 @@ mod tests {
start_pattern: Regex::new("").unwrap(),
condition_pattern: Regex::new("^(INFO|ERROR) ").unwrap(),
mode: Mode::HaltBefore,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![
"INFO some usual line",
Expand Down Expand Up @@ -512,7 +513,7 @@ mod tests {
start_pattern: Regex::new("[^;]$").unwrap(),
condition_pattern: Regex::new(";$").unwrap(),
mode: Mode::HaltWith,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![
"some usual line;",
Expand All @@ -538,7 +539,7 @@ mod tests {
start_pattern: Regex::new("^[^\\s]").unwrap(),
condition_pattern: Regex::new("^[\\s]+at").unwrap(),
mode: Mode::ContinueThrough,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![concat!(
"java.lang.Exception\n",
Expand All @@ -560,7 +561,7 @@ mod tests {
start_pattern: Regex::new("^[^\\s]").unwrap(),
condition_pattern: Regex::new("^[\\s]+from").unwrap(),
mode: Mode::ContinueThrough,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![concat!(
"foobar.rb:6:in `/': divided by 0 (ZeroDivisionError)\n",
Expand Down Expand Up @@ -594,7 +595,7 @@ mod tests {
start_pattern: Regex::new("^\\s").unwrap(),
condition_pattern: Regex::new("^\\s").unwrap(),
mode: Mode::ContinueThrough,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![
"not merged 1",
Expand Down Expand Up @@ -632,7 +633,7 @@ mod tests {
start_pattern: Regex::new("").unwrap(),
condition_pattern: Regex::new("^START ").unwrap(),
mode: Mode::HaltBefore,
timeout: Duration::from_millis(10),
timeout: Some(Duration::from_millis(10)),
};
let expected = vec![
"part 0.1\npart 0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/sources/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ mod integration_tests {
start_pattern: "^[^\\s]".to_owned(),
condition_pattern: "^[\\s]+at".to_owned(),
mode: line_agg::Mode::ContinueThrough,
timeout_ms: 10,
timeout_ms: Some(10),
}),
..DockerConfig::default()
};
Expand Down
2 changes: 1 addition & 1 deletion src/sources/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ mod tests {
start_pattern: "INFO".to_owned(),
condition_pattern: "INFO".to_owned(),
mode: line_agg::Mode::HaltBefore,
timeout_ms: 25, // less than 50 in sleep()
timeout_ms: Some(25), // less than 50 in sleep()
}),
..test_default_file_config(&dir)
};
Expand Down
4 changes: 2 additions & 2 deletions src/sources/util/multiline_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct MultilineConfig {
pub start_pattern: String,
pub condition_pattern: String,
pub mode: line_agg::Mode,
pub timeout_ms: u64,
pub timeout_ms: Option<u64>,
}

impl TryFrom<&MultilineConfig> for line_agg::Config {
Expand All @@ -31,7 +31,7 @@ impl TryFrom<&MultilineConfig> for line_agg::Config {
let condition_pattern = Regex::new(condition_pattern)
.with_context(|| InvalidMultilineConditionPattern { condition_pattern })?;
let mode = mode.clone();
let timeout = Duration::from_millis(*timeout_ms);
let timeout = timeout_ms.map(Duration::from_millis);

Ok(Self {
start_pattern,
Expand Down