Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changelog.d/1065-empty-file-fingerprint-warning.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid emitting a warning for empty files that are too small to fingerprint.
30 changes: 29 additions & 1 deletion lib/file-source-common/src/fingerprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ impl Fingerprinter {
known_small_files: &mut HashMap<PathBuf, time::Instant>,
emitter: &impl FileSourceInternalEvents,
) -> Option<FileFingerprint> {
let mut file_size = None;

let metadata = match fs::metadata(path).await {
Ok(metadata) => {
if !metadata.is_dir() {
file_size = Some(metadata.len());
self.fingerprint(path).await.map(Some)
} else {
Ok(None)
Expand All @@ -221,7 +224,7 @@ impl Fingerprinter {
.map_err(|error| {
match error.kind() {
ErrorKind::UnexpectedEof => {
if !known_small_files.contains_key(path) {
if file_size != Some(0) && !known_small_files.contains_key(path) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep remove_after tracking for empty files

When the file source uses checksum fingerprinting with remove_after_secs, this branch now suppresses both the warning and the insertion into known_small_files for zero-byte files. The cleanup path deletes only entries from known_small_files after the grace period (lib/file-source/src/file_server.rs cleanup loop), so an empty matched file is no longer removed even though it is already at EOF and previously was tracked for removal. Suppress emit_file_checksum_failed separately while still recording the path for remove_after_secs cleanup.

Useful? React with 👍 / 👎.

emitter.emit_file_checksum_failed(path);
known_small_files.insert(path.to_path_buf(), time::Instant::now());
}
Expand Down Expand Up @@ -638,6 +641,31 @@ mod test {
);
}

#[tokio::test]
async fn no_error_on_empty_file() {
let target_dir = tempdir().unwrap();
let empty_path = target_dir.path().join("empty.log");
fs::write(&empty_path, []).unwrap();

let mut fingerprinter = Fingerprinter::new(
FingerprintStrategy::FirstLinesChecksum {
ignored_header_bytes: 0,
lines: 1,
},
1024,
false,
);

let mut small_files = HashMap::new();
assert!(
fingerprinter
.fingerprint_or_emit(&empty_path, &mut small_files, &NoErrors)
.await
.is_none()
);
assert!(!small_files.contains_key(&empty_path));
}

#[test]
fn test_monotonic_compression_algorithms() {
// This test is necessary to handle an edge case where when assessing the magic header
Expand Down
Loading