Log_parser

AI log analysis v2: persona

Phase 0: Repo findings

Stack: Python 3 / FastAPI server (logpipe/server/app.py, core.py), React+TS UI (web/src), pytest (tests/). Stores: memory (SQLite-on-demand for queries), ClickHouse, MongoDB (logpipe/storage/*, reads in logpipe/server/reads.py, reads_mongo.py).

  1. Parsed logs / templates
    • Rows: iot_logs (log_id, timestamp, device_id=host, service, source, template_id, log_status, payload JSON, raw_message, tags). Schema logpipe/storage/schema.sql.
    • Templates: versioned registry file (logpipe/registry.py, server.registry.current → templates, canonical_id, key_vocab). Per-template metadata docs in control store (server.tmeta, kind template). /api/templates exposes counts. No per-template first_seen/baseline-frequency table.
    • Level is computed from the line (reads.LEVEL_SQL, reads.level()), not stored.
  2. LogBERT scores
    • Per window (detector.sliding_windows, server.window), per stream model (server.scorers[stream], LogBERTScorer).
    • Only windows over threshold are persisted: anomaly_alerts (miss_ratio, novelty_ratio, template_ids, reasons). No table of all window scores.
    • Mispredicted keys: recomputed on demand by LogBERTScorer.explain(window) → per-event expected | unexpected | unseen + expected template IDs (used by Server.incident(), core.py:1254).
    • Incidents = alerts on one service grouped by INCIDENT_GAP (5 min) (Server.incidents()).
  3. Existing AI code
    • logpipe/enrich/llm.py: LLMAdapter protocol, OfflineAdapter (deterministic fallbacks), ChatAdapter (langchain structured output via deepparse providers; anthropic/openai/web). _Traced wrapper in core.py records prompts into job detail.
    • Ask in English (POST /api/query/ask): one LLM call writes raw SQL (CH/SQLite) or a builder spec (Mongo). Guard = startswith(select|with); execution guard = CH readonly=2, SQLite PRAGMA query_only on a throwaway in-memory DB, Mongo querybuild_mongo.check(). UI already shows SQL in the SQL tab before the user presses Run.
    • Incident explain (POST /api/incidents/{id}/explain → job _job_explain, core.py:1325): builds a text of ≤60 incident events (marked * / ?) + ≤20 warn/error lines from other services ±1 min, one LLM call → {summary, likely_cause, next_steps}. No citations, no evidence ranking, no baseline, no “insufficient evidence” path. Offline fallback points at first unusual line.
    • No embeddings/vector index for templates in server path (logpipe/learning/similarity.py, enrich/similarity.py exist — to check whether reusable).
  4. Missing for the feature: per-window score history, template baseline frequencies / first_seen, heartbeat/silence detection, vector index, QuerySpec validation for the LLM path (raw SQL today), citations, eval harness with fault-injection scenarios.

Answers

Persona