Skip to content
Merged
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions src/sources/journald.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ pub struct JournaldConfig {
#[configurable(metadata(docs::human_name = "Data Directory"))]
pub data_dir: Option<PathBuf>,

/// Extra command line arguments to pass to `journalctl`.
///
/// If specified, it is added to the command line arguments as-is.
#[serde(default)]
#[configurable(metadata(docs::examples = "--merge"))]
pub extra_journalctl_args: Option<String>,

/// The systemd journal is read in batches, and a checkpoint is set at the end of each batch.
///
/// This option limits the size of the batch.
Expand Down Expand Up @@ -297,6 +304,7 @@ impl Default for JournaldConfig {
journalctl_path: None,
journal_directory: None,
journal_namespace: None,
extra_journalctl_args: None,
acknowledgements: Default::default(),
remap_priority: false,
log_namespace: None,
Expand Down Expand Up @@ -351,6 +359,7 @@ impl SourceConfig for JournaldConfig {
self.journal_namespace.clone(),
self.current_boot_only,
self.since_now,
self.extra_journalctl_args.clone()
);

let batch_size = self.batch_size;
Expand Down Expand Up @@ -621,6 +630,7 @@ struct StartJournalctl {
journal_namespace: Option<String>,
current_boot_only: bool,
since_now: bool,
extra_journalctl_args: Option<String>
}

impl StartJournalctl {
Expand All @@ -630,13 +640,15 @@ impl StartJournalctl {
journal_namespace: Option<String>,
current_boot_only: bool,
since_now: bool,
extra_journalctl_args: Option<String>
) -> Self {
Self {
path,
journal_dir,
journal_namespace,
current_boot_only,
since_now,
extra_journalctl_args
}
}

Expand Down Expand Up @@ -669,6 +681,10 @@ impl StartJournalctl {
command.arg("--since=2000-01-01");
}

if let Some(args) = &self.extra_journalctl_args {
command.arg(format!("{}", args));
}
Comment thread
a-bali marked this conversation as resolved.
Outdated

command
}

Expand Down Expand Up @@ -1414,6 +1430,7 @@ mod tests {
let current_boot_only = false;
let cursor = None;
let since_now = false;
let extra_journalctl_args = None;

let command = create_command(
&path,
Expand All @@ -1422,6 +1439,7 @@ mod tests {
current_boot_only,
since_now,
cursor,
extra_journalctl_args
);
let cmd_line = format!("{:?}", command);
assert!(!cmd_line.contains("--directory="));
Expand All @@ -1432,6 +1450,7 @@ mod tests {
let journal_dir = None;
let journal_namespace = None;
let since_now = true;
let extra_journalctl_args = None;

let command = create_command(
&path,
Expand All @@ -1440,6 +1459,7 @@ mod tests {
current_boot_only,
since_now,
cursor,
extra_journalctl_args
);
let cmd_line = format!("{:?}", command);
assert!(cmd_line.contains("--since=now"));
Expand All @@ -1448,6 +1468,7 @@ mod tests {
let journal_namespace = Some(String::from("my_namespace"));
let current_boot_only = true;
let cursor = Some("2021-01-01");
let extra_journalctl_args = Some(String::from("--merge"));

let command = create_command(
&path,
Expand All @@ -1456,12 +1477,14 @@ mod tests {
current_boot_only,
since_now,
cursor,
extra_journalctl_args
);
let cmd_line = format!("{:?}", command);
assert!(cmd_line.contains("--directory=/tmp/journal-dir"));
assert!(cmd_line.contains("--namespace=my_namespace"));
assert!(cmd_line.contains("--boot"));
assert!(cmd_line.contains("--after-cursor="));
assert!(cmd_line.contains("--merge"));
}

fn create_command(
Expand All @@ -1471,13 +1494,15 @@ mod tests {
current_boot_only: bool,
since_now: bool,
cursor: Option<&str>,
extra_journalctl_args: Option<String>
) -> Command {
StartJournalctl::new(
path.into(),
journal_dir,
journal_namespace,
current_boot_only,
since_now,
extra_journalctl_args
)
.make_command(cursor)
}
Expand Down