Show HN: Ctrlb-decompose:在发送给 LLM 之前去除日志中的冗余信息
Show HN: Ctrlb-decompose: Strip the noise from logs before sending to LLMs

原始链接: https://github.com/ctrlb-hq/ctrlb-decompose

**ctrlb-decompose** 是一款高性能日志分析工具,能够将数百万行非结构化日志转换为精简且具可操作性的结构化模式。通过结合 CLP 编码、Drain3 聚类以及统计估算(DDSketch 和 HyperLogLog)的流式处理管线,它无需多轮处理即可将日志数据量减少 99% 以上。 **主要功能:** * **智能解析:** 自动提取并识别变量类型(如 IP、UUID、持续时间、枚举),提供细粒度的洞察。 * **可操作统计:** 识别每种模式的异常标志、错误级联、频率峰值及分位数分布(p50/p99)。 * **灵活部署:** 提供命令行工具 (CLI)、Rust 库或 WebAssembly 支持。 * **大模型友好:** 支持专为大模型 (LLM) 摄入优化的 JSON 和精简 Markdown 输出格式。 * **无缝集成:** 提供 Claude Code 插件,支持用户使用自然语言查询(如“总结这些日志并高亮显示异常”)来分析日志。 ctrlb-decompose 专为高效率和低内存开销设计,是开发者和 SRE 将嘈杂的日志流转化为清晰、结构化诊断信息的理想工具。

Hacker News 的这篇帖子介绍了 “Ctrlb-decompose”,这是一款旨在将日志发送给大语言模型(LLM)前去除噪声的工具。该项目旨在提高 AI 处理日志数据时的效率和相关性。 一位评论者对这一概念表示赞赏,并建议通过与 OpenTelemetry 集成来进一步增强该工具。通过提取属性、对日志进行分组,并将行关联为追踪(traces)或跨度(spans),用户可以将海量难以阅读的日志转换为可操作的指标。这种方法不仅能改善可观测性和告警能力,还能在日志到达 Datadog 或 Grafana 等可视化平台之前进行预处理,从而显著降低数据传输成本。
相关文章

原文

Compress raw log lines into structural patterns with statistics, anomalies, and correlations.

Turn millions of noisy log lines into a handful of actionable patterns — with typed variables, quantile stats, anomaly flags, and severity scoring. Runs as a CLI, in the browser via WASM, or as a Rust library.

$ cat server.log | ctrlb-decompose

┌────────────────────────────────────────────────────────────────────┐
│ ctrlb-decompose: 1,247,831 lines -> 43 patterns (99.9% reduction) │
└────────────────────────────────────────────────────────────────────┘

#1  [ERROR]  ██████████████████████  18,402 (1.5%)
    <TS> ERROR [<*>] Connection to <ip> timed out after <duration>

    ip          IPv4    unique=12     top: 10.0.1.15 (34%), 10.0.1.22 (28%)
    duration    Duration               p50=120ms  p99=4.8s

#2  [INFO]   ████████████████████    904,221 (72.5%)
    <TS> INFO  [<*>] Request from <ip> completed in <duration> status=<status>

    ip          IPv4    unique=1,847  top: 10.0.1.15 (12%), 10.0.1.22 (8%)
    duration    Duration               p50=23ms   p99=312ms
    status      Enum    unique=3      values: 200 (91%), 404 (6%), 500 (3%)

Website coming soon.


ctrlb-decompose uses a two-stage normalization and clustering pipeline that processes logs in a single streaming pass with minimal memory footprint.

                         ┌──────────────────────────────────────────────┐
                         │            ctrlb-decompose pipeline          │
                         └──────────────────────────────────────────────┘

  Raw Log Lines
       │
       ▼
┌──────────────┐    Strip & parse timestamps (ISO 8601, Apache,
│  Timestamp   │    syslog, Unix epoch, etc.) into normalized
│  Extraction  │    <TS> markers with DateTime values.
└──────┬───────┘
       │
       ▼
┌──────────────┐    Replace integers, floats, IPs, and strings
│     CLP      │    with compact placeholder bytes. Structurally
│   Encoding   │    identical lines now produce the same "logtype."
└──────┬───────┘
       │
       ▼
┌──────────────┐    Tree-based similarity clustering (Drain3) groups
│   Drain3     │    logtypes into patterns. Differing tokens become
│  Clustering  │    <*> wildcards. Incremental — no second pass needed.
└──────┬───────┘
       │
       ▼
┌──────────────┐    Merge CLP-decoded values with Drain3 wildcard
│   Variable   │    positions. Classify each variable into semantic
│  Extraction  │    types: IPv4, UUID, Duration, Enum, Integer, etc.
│  & Typing    │
└──────┬───────┘
       │
       ▼
┌──────────────┐    DDSketch quantiles (p50/p99), HyperLogLog
│  Statistics  │    cardinality estimation, top-k values, temporal
│ Accumulation │    bucketing, and reservoir-sampled example lines.
└──────┬───────┘
       │
       ▼
┌──────────────┐    Frequency spikes, error cascades, low-cardinality
│   Anomaly    │    flags, bimodal distributions, and clustered
│  Detection   │    numeric detection.
└──────┬───────┘
       │
       ▼
┌──────────────┐    Keyword-based severity (ERROR > WARN > INFO > DEBUG),
│   Scoring    │    temporal co-occurrence, shared variable correlation,
│ & Correlation│    and error cascade detection across patterns.
└──────┬───────┘
       │
       ▼
┌──────────────┐
│    Output    │──── Human (ANSI terminal) / LLM (compact markdown) / JSON
└──────────────┘

CLP (Compressed Log Processor) encoding normalizes variable tokens into typed placeholders, so structurally identical lines produce identical logtypes regardless of the actual values:

Input:   "Request from 10.0.1.15 completed in 45ms status=200"
Logtype: "Request from <dict> completed in <float>ms status=<int>"

Stage 2 — Drain3 Clustering

The Drain algorithm builds a prefix tree over logtypes and groups them by token similarity (configurable threshold, default 0.4). Where tokens diverge, the template gains a <*> wildcard. This runs incrementally — each line is processed once with no second pass.

Extracted variables are classified into semantic types for richer analysis:

Type Example Detection
IPv4 / IPv6 10.0.1.15 CIDR pattern match
UUID 550e8400-e29b-... 8-4-4-4-12 hex format
Duration 45ms, 3.2s Numeric + time unit suffix
HexID 0x1a2b3c 4+ hex digits
Integer 200 Parses as i64
Float 3.14 Contains ., parses as f64
Enum ERROR Low cardinality (<=20 unique, top-3 >= 80%)
Timestamp 2024-01-15T14:22:01Z RFC 3339 pattern
String anything else Fallback
  • Drain3 clusters: O(k) with LRU eviction (default 10k max)
  • Quantiles: DDSketch — fixed ~200 bytes per numeric slot, no raw value storage
  • Cardinality: HyperLogLog++ — ~200 bytes per high-cardinality variable
  • Examples: Reservoir sampling — bounded buffer per pattern

brew tap ctrlb-hq/tap
brew install ctrlb-decompose
curl -LO https://github.com/ctrlb-hq/ctrlb-decompose/releases/download/v0.1.0/ctrlb-decompose_0.1.0-1_amd64.deb
sudo dpkg -i ctrlb-decompose_0.1.0-1_amd64.deb
git clone https://github.com/ctrlb-hq/ctrlb-decompose.git
cd ctrlb-decompose
cargo build --release
# Binary at target/release/ctrlb-decompose

# Pipe from stdin
cat /var/log/syslog | ctrlb-decompose

# Read from file
ctrlb-decompose server.log

# LLM-optimized output (compact, token-efficient)
ctrlb-decompose --llm app.log

# JSON output
ctrlb-decompose --json app.log

# Top 10 patterns with 3 example lines each
ctrlb-decompose --top 10 --context 3 app.log
ctrlb-decompose [OPTIONS] [FILE]

Arguments:
  [FILE]          Log file path (reads stdin if omitted or "-")

Options:
      --human         Human-readable output with colors (default)
      --llm           LLM-optimized compact markdown
      --json          Structured JSON output
      --top <N>       Show top N patterns (default: 20)
      --context <N>   Example lines per pattern (default: 0)
      --no-color      Disable ANSI colors
      --no-banner     Suppress header/footer
  -q, --quiet         Suppress progress messages
  -h, --help          Show help
  -V, --version       Show version

Format Flag Best for
Human --human (default) Terminal investigation — colored, visual bars
LLM --llm Feeding into LLMs — compact, token-efficient markdown
JSON --json Programmatic consumption — structured, machine-readable

Use ctrlb-decompose directly from Claude Code — no CLI knowledge needed. The plugin installs ctrlb-decompose automatically and lets you analyze logs just by asking.

/plugin marketplace add ctrlb-hq/ctrlb-decompose
/plugin install ctrlb-decompose@ctrlb-hq

Just describe what you want in plain language:

  • "Analyze the errors in /var/log/app.log"
  • "What are the most common patterns in this log file?"
  • "Summarize these logs and highlight anomalies"

Claude will check if ctrlb-decompose is installed (and walk you through installation if not), run the analysis, and explain the results — surfacing errors first, calling out anomalies, and suggesting what to investigate next.

See plugin/README.md for full details.


MIT

联系我们 contact @ memedata.com