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

feat: enabled sorting in compressed files #577

Merged
merged 8 commits into from
Dec 18, 2024
Merged
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
195 changes: 144 additions & 51 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <[email protected]>"]
version = "0.30.0-alpha.3"
version = "0.30.0-alpha.4"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -43,27 +43,29 @@ crossbeam-channel = "0"
crossbeam-queue = "0"
crossbeam-utils = "0"
deko = "0"
derive_deref = "1"
derive_more = {version="1", features = ["deref", "from"]}
dirs = "5"
dirs-sys = "0"
encstr = { path = "./crate/encstr" }
enum-map = "2"
enumset = "1"
enumset-ext = { path = "./crate/enumset-ext" }
env_logger = "0"
flate2 = "1"
heapless = "0"
hex = "0"
htp = { git = "https://github.com/pamburus/htp.git" }
humantime = "2"
itertools = "0.13"
itoa = { version = "1", default-features = false }
log = "0"
nonzero_ext = "0"
notify = { version = "7", features = ["macos_kqueue"] }
nu-ansi-term = "0"
num_cpus = "1"
once_cell = "1"
pest = "2"
pest_derive = "2"
phf = { version = "0", features = ["macros"] }
regex = "1"
rust-embed = "8"
serde = { version = "1", features = ["derive"] }
Expand All @@ -88,8 +90,10 @@ kqueue = "1"

[dev-dependencies]
byte-strings = "0"
clean-path = "0"
criterion = "0"
maplit = "1"
mockall = "0"
stats_alloc = "0"
regex = "1"
wildmatch = "2"
Expand Down
15 changes: 6 additions & 9 deletions build/ci/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ function clean() {
function test() {
cargo test --tests --workspace
cargo build
${MAIN_EXECUTABLE:?} > /dev/null
${MAIN_EXECUTABLE:?} --config= > /dev/null
${MAIN_EXECUTABLE:?} --config= --help > /dev/null
${MAIN_EXECUTABLE:?} --config=etc/defaults/config-k8s.yaml > /dev/null
${MAIN_EXECUTABLE:?} --config=etc/defaults/config-ecs.yaml > /dev/null
${MAIN_EXECUTABLE:?} --shell-completions bash > /dev/null
${MAIN_EXECUTABLE:?} --man-page > /dev/null
${MAIN_EXECUTABLE:?} --list-themes > /dev/null
echo "" | ${MAIN_EXECUTABLE:?} --concurrency 4 > /dev/null
if ${MAIN_EXECUTABLE:?} -s test.log.gz 2>/dev/null > /dev/null; then
echo "Expected combination of options `-s 1234.log.gz` to fail"
exit 1
fi
${MAIN_EXECUTABLE:?} --config= --shell-completions bash > /dev/null
${MAIN_EXECUTABLE:?} --config= --man-page > /dev/null
${MAIN_EXECUTABLE:?} --config= --list-themes > /dev/null
${MAIN_EXECUTABLE:?} --config= sample/prometheus.log -P > /dev/null
echo "" | ${MAIN_EXECUTABLE:?} --config= --concurrency 4 > /dev/null
}

function merge() {
Expand Down
2 changes: 2 additions & 0 deletions sample/test.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"ts":"2024-10-01T01:02:04Z","level":"info","msg":"latest test message"}
{"ts":"2024-10-01T01:02:03Z","level":"info","msg":"earlier test message"}
20 changes: 11 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
settings::{FieldShowOption, Fields, Formatting},
theme::{Element, StylingPush, Theme},
timezone::Tz,
vfs::LocalFileSystem,
IncludeExcludeKeyFilter,
{error::*, QueryNone},
};
Expand Down Expand Up @@ -219,7 +220,7 @@
let mut tx = StripedSender::new(txi);
let scanner = Scanner::new(sfi, &self.options.delimiter);
for (i, mut input) in inputs.into_iter().enumerate() {
for item in scanner.items(&mut input.stream).with_max_segment_size(self.options.max_message_size.into()) {
for item in scanner.items(&mut input.stream.as_sequential()).with_max_segment_size(self.options.max_message_size.into()) {
if tx.send((i, item?)).is_none() {
break;
}
Expand Down Expand Up @@ -272,6 +273,7 @@
fn sort(&self, inputs: Vec<InputHolder>, output: &mut Output) -> Result<()> {
let mut output = BufWriter::new(output);
let indexer_settings = IndexerSettings::new(
LocalFileSystem,
self.options.buffer_size.try_into()?,
self.options.max_message_size.try_into()?,
&self.options.fields.settings.predefined,
Expand Down Expand Up @@ -499,14 +501,14 @@
let reader = scope.spawn(closure!(clone sfi, clone txi, |_| -> Result<()> {
let scanner = Scanner::new(sfi.clone(), &self.options.delimiter);
let mut meta = None;
if let InputReference::File(filename) = &input_ref {
meta = Some(fs::metadata(filename)?);
if let InputReference::File(path) = &input_ref {
meta = Some(fs::metadata(&path.canonical)?);

Check warning on line 505 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L504-L505

Added lines #L504 - L505 were not covered by tests
}
let mut input = Some(input_ref.open_tail(self.options.tail)?);
let mut input = Some(input_ref.open()?.tail(self.options.tail)?);

Check warning on line 507 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L507

Added line #L507 was not covered by tests
let is_file = |meta: &Option<fs::Metadata>| meta.as_ref().map(|m|m.is_file()).unwrap_or(false);
let process = |input: &mut Option<Input>, is_file: bool| {
if let Some(input) = input {
for (j, item) in scanner.items(&mut input.stream).with_max_segment_size(self.options.max_message_size.into()).enumerate() {
for (j, item) in scanner.items(&mut input.stream.as_sequential()).with_max_segment_size(self.options.max_message_size.into()).enumerate() {

Check warning on line 511 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L511

Added line #L511 was not covered by tests
if txi.send((i, j, item?)).is_err() {
break;
}
Expand All @@ -516,14 +518,14 @@
Ok(false)
}
};
if let InputReference::File(filename) = &input_ref {
if let InputReference::File(path) = &input_ref {

Check warning on line 521 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L521

Added line #L521 was not covered by tests
if process(&mut input, is_file(&meta))? {
return Ok(())
}
fsmon::run(vec![filename.clone()], |event| {
fsmon::run(vec![path.canonical.clone()], |event| {

Check warning on line 525 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L525

Added line #L525 was not covered by tests
match event.kind {
EventKind::Modify(_) | EventKind::Create(_) | EventKind::Any | EventKind::Other => {
if let (Some(old_meta), Ok(new_meta)) = (&meta, fs::metadata(&filename)) {
if let (Some(old_meta), Ok(new_meta)) = (&meta, fs::metadata(&path.canonical)) {

Check warning on line 528 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L528

Added line #L528 was not covered by tests
if old_meta.len() > new_meta.len() {
input = None;
}
Expand Down Expand Up @@ -691,7 +693,7 @@
fn input_badges<'a, I: IntoIterator<Item = &'a InputReference>>(&self, inputs: I) -> Option<Vec<String>> {
let name = |input: &InputReference| match input {
InputReference::Stdin => "<stdin>".to_owned(),
InputReference::File(path) => path.to_string_lossy().to_string(),
InputReference::File(path) => path.original.to_string_lossy().to_string(),
};

let mut badges = inputs.into_iter().map(|x| name(x).chars().collect_vec()).collect_vec();
Expand Down
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ pub enum Error {
},
#[error("invalid index header")]
InvalidIndexHeader,
#[error("requested sorting of messages in {}-compressed file '{}' that is not currently supported", HILITE.paint(.format), HILITE.paint(.path.to_string_lossy()))]
UnsupportedFormatForIndexing { path: PathBuf, format: String },
#[error("failed to parse json: {0}")]
JsonParseError(#[from] serde_json::Error),
#[error("failed to parse logfmt: {0}")]
Expand Down
Loading
Loading