Add log-anomaly module: Spring Boot log parser, template mining, swappable embedder, k-means baseline, novel-template and rate-spike detectors with measured blind spots, incidents and a template-only summary prompt on Spring Boot 4.2.0

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b69H5rTewUKPyhGS8r
This commit is contained in:
2026-12-01 23:57:00 +05:30
co-authored by Claude Sonnet 5.5
parent 943351bccb
commit dc94d7fece
46 changed files with 2048 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
# log-anomaly
Log anomaly detection for a Spring Boot application, in plain Java 25 and Spring Boot 4.2.0. A baseline log is parsed,
reduced to message templates, embedded, and grouped with k-means. A new log is then checked two ways: a template that
never occurred and is far from every normal cluster is a **novel template**; a template that did occur but arrives far
above its baseline rate is a **rate spike**. Findings that overlap in time become one incident with a short summary.
```bash
export JAVA_HOME=/path/to/jdk-25
mvn test -pl log-anomaly # writes output/01..12 (00 is the QuickStart run)
bash log-anomaly/scripts/run-all.sh # also packages the jar and writes output/13 with curl
java log-anomaly/quickstart/QuickStart.java # the whole idea in one file, no Maven
```
| Class | Role |
|---|---|
| `LogParser`, `LogEvent` | Spring Boot's default layout, with or without the application name; stack traces folded into one event |
| `TemplateMiner` | masks numbers and ids; an optional second pass wildcards words that vary (user names) |
| `Embedder`, `HashingEmbedder`, `OpenAiCompatibleEmbedder` | the seam: offline word hashing, or any `/v1/embeddings` endpoint |
| `KMeans`, `BaselineModel` | spherical k-means over baseline templates; distance = 1 - cosine to the nearest centre |
| `AnomalyDetector`, `Finding` | the novel-template and rate-spike detectors |
| `IncidentBuilder`, `Incident` | findings close in time become one incident |
| `IncidentSummarizer`, `TemplateSummarizer`, `LlmSummarizer` | a no-model summary, and a chat-endpoint summary that is sent templates, never raw lines |
| `SyntheticLogs`, `SampleLogWriter` | the seeded generator behind the tests (synthetic: see the class Javadoc) |
| `AnalysisService`, `AnomalyController`, `LogAnomalyApplication` | `GET /api/incidents?baseline=&target=` (demo only, it reads any path the server can read) |
`output/` holds the transcripts the tests write; every figure in the post is quoted from there. Files 12 and 13 contain
timestamps and process ids that change on every run. The hashing embedder compares words, not meaning, so the numbers
in `output/03` and `output/04` describe that embedder only. `OpenAiCompatibleEmbedder` and `LlmSummarizer` were tested
against stub servers and have not been run against a real model.