Skip to content

feat: optimize Loki query performance with chunking and server-side filtering#28

Merged
noexecstack merged 1 commit intomainfrom
feat/loki-query-performance
Apr 1, 2026
Merged

feat: optimize Loki query performance with chunking and server-side filtering#28
noexecstack merged 1 commit intomainfrom
feat/loki-query-performance

Conversation

@noexecstack
Copy link
Copy Markdown
Owner

Summary

  • Split Loki time ranges into small chunks (default 5s) processed by a configurable thread pool (default 8 workers), replacing the old N-segments-equal-to-thread-count approach. Reduces per-request load and avoids timeouts on large time ranges (hours/days).
  • Add server-side namespace filtering: when -n/--namespace is used with --from loki, injects LogQL line filters (e.g. |= "\"namespace\":\"argocd\"") so Loki skips irrelevant lines before sending. Chunk size auto-scales to 5m when filters are active.
  • Graceful Ctrl+C during Loki fetches: cancels pending chunks and continues with partial results. TUI shows a yellow "Partial results (interrupted)" badge.
  • New CLI flags: --loki-chunk (max time window per request), --loki-timeout (per-request HTTP timeout).
  • Progress indicator now shows percentage. TUI header shows total load time.

Test plan

  • All 140 existing tests pass
  • Manual: --since 2m completes in seconds (was 10s+)
  • Manual: --since 4h -n argocd completes fast with server-side filtering
  • Manual: Ctrl+C during fetch shows partial results in TUI with yellow badge
  • Manual: --loki-chunk and --loki-timeout flags work as documented

…iltering

Split Loki time ranges into small chunks (default 5s) processed by a
configurable thread pool (default 8 workers), replacing the old approach
of splitting into N segments equal to the thread count. This dramatically
reduces per-request load and avoids timeouts on large time ranges.

Add server-side namespace filtering by injecting LogQL line filters
(e.g. |= "\"namespace\":\"argocd\"") when -n/--namespace is used with
--from loki, so Loki skips irrelevant log lines before sending them.
Chunk size auto-scales to 5m when namespace filters are active to
reduce HTTP round-trip overhead.

Add graceful Ctrl+C handling during Loki fetches -- cancels pending
chunks and continues with partial results. The TUI header shows a
yellow "Partial results (interrupted)" badge.

New CLI flags: --loki-chunk, --loki-timeout.
Progress indicator now shows percentage.
TUI header shows total load time.
@noexecstack noexecstack merged commit c36265b into main Apr 1, 2026
4 of 5 checks passed
@noexecstack noexecstack deleted the feat/loki-query-performance branch April 1, 2026 20:04
@noexecstack noexecstack mentioned this pull request Apr 1, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant