Parse error breakdown, polish warnings
This commit is contained in:
@@ -47,7 +47,6 @@ impl LogFileDiscovery {
|
||||
return Ok(Some(LogFile {
|
||||
path: gz_path,
|
||||
compressed: true,
|
||||
date,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -57,7 +56,6 @@ impl LogFileDiscovery {
|
||||
return Ok(Some(LogFile {
|
||||
path: plain_path,
|
||||
compressed: false,
|
||||
date,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -70,7 +68,6 @@ impl LogFileDiscovery {
|
||||
pub struct LogFile {
|
||||
pub path: PathBuf,
|
||||
pub compressed: bool,
|
||||
pub date: NaiveDate,
|
||||
}
|
||||
|
||||
impl LogFile {
|
||||
|
||||
24
src/main.rs
24
src/main.rs
@@ -1,6 +1,7 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use chrono::NaiveDate;
|
||||
use clap::Parser;
|
||||
use std::collections::HashMap;
|
||||
use std::io::BufRead;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -119,7 +120,7 @@ fn process_reader(
|
||||
let mut signature_batch: Vec<SignatureEntry> = Vec::with_capacity(batch_size);
|
||||
let mut total_lines = 0u64;
|
||||
let mut parsed_lines = 0u64;
|
||||
let mut error_lines = 0u64;
|
||||
let mut error_counts: HashMap<String, u64> = HashMap::new();
|
||||
|
||||
for line_result in reader.lines() {
|
||||
let line = line_result?;
|
||||
@@ -136,18 +137,16 @@ fn process_reader(
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error_lines += 1;
|
||||
if error_lines <= 10 {
|
||||
eprintln!("Parse error: {}", e);
|
||||
}
|
||||
*error_counts.entry(e.to_string()).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if total_lines % 100_000 == 0 {
|
||||
let total_errors: u64 = error_counts.values().sum();
|
||||
eprintln!(
|
||||
"Progress: {} lines read, {} parsed, {} errors",
|
||||
total_lines, parsed_lines, error_lines
|
||||
total_lines, parsed_lines, total_errors
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -157,11 +156,22 @@ fn process_reader(
|
||||
flush_signature_batch(db, &mut signature_batch)?;
|
||||
}
|
||||
|
||||
let total_errors: u64 = error_counts.values().sum();
|
||||
eprintln!(
|
||||
"File complete: {} lines read, {} parsed, {} errors",
|
||||
total_lines, parsed_lines, error_lines
|
||||
total_lines, parsed_lines, total_errors
|
||||
);
|
||||
|
||||
// Print error summary
|
||||
if !error_counts.is_empty() {
|
||||
eprintln!("\nParse errors breakdown:");
|
||||
let mut errors: Vec<_> = error_counts.into_iter().collect();
|
||||
errors.sort_by(|a, b| b.1.cmp(&a.1)); // Sort by count descending
|
||||
for (error, count) in errors {
|
||||
eprintln!(" {} ({}x)", error, count);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,6 @@ pub struct SignatureEntry {
|
||||
/// Trait for parsing different message types from logs.
|
||||
/// Implement this trait to add support for new message formats.
|
||||
pub trait MessageParser: Send + Sync {
|
||||
/// Returns the message type identifier (e.g., "signature")
|
||||
fn message_type(&self) -> &'static str;
|
||||
|
||||
/// Attempts to parse a log line. Returns None if this parser doesn't handle this message type.
|
||||
fn parse(&self, line: &str) -> Option<Result<ParsedMessage>>;
|
||||
}
|
||||
@@ -49,10 +46,6 @@ static SIGNATURE_RE: LazyLock<Regex> =
|
||||
pub struct SignatureParser;
|
||||
|
||||
impl MessageParser for SignatureParser {
|
||||
fn message_type(&self) -> &'static str {
|
||||
"signature"
|
||||
}
|
||||
|
||||
fn parse(&self, line: &str) -> Option<Result<ParsedMessage>> {
|
||||
// Check if this line contains a signature message
|
||||
if !line.contains("msg=\"signature:") {
|
||||
|
||||
Reference in New Issue
Block a user