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
+10
View File
@@ -0,0 +1,10 @@
$ java QuickStart.java
normal lines: 6, normal templates: 4
Order <*> placed by customer c-<*>
Payment approved for order <*> in <*> ms
Reserved <*> units of SKU-<*>
Token validated for user u-<*>
0.000 known template Order <*> placed by customer c-<*>
0.764 NEW and FAR from normal HikariPool-<*> - Connection is not available, request timed out after <*>ms.
0.225 new but close to normal Payment approved for order <*> in <*> ms but ledger write failed
+21
View File
@@ -0,0 +1,21 @@
# Parsing Spring Boot log lines
## First lines of the baseline
2026-11-30T09:00:00.000+05:30 INFO 4121 --- [shop] [nio-8080-exec-6] c.a.shop.CatalogController : GET /api/products/884 200 in 13 ms
2026-11-30T09:00:01.843+05:30 INFO 4121 --- [shop] [nio-8080-exec-6] c.a.shop.OrderController : Order 77525 placed by customer c-519 total=8093.82
2026-11-30T09:00:03.687+05:30 INFO 4121 --- [shop] [nio-8080-exec-4] c.a.shop.CatalogController : GET /api/products/476 200 in 35 ms
## An ERROR with a stack trace: one event, several physical lines
2026-11-30T11:12:30.421+05:30 ERROR 4121 --- [shop] [nio-8080-exec-8] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Connection is not available, request timed out after 30000ms.
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:686)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:179)
## Counts
baseline: 3947 physical lines, 3857 events, 0 orphan lines
target: 2196 physical lines, 1524 events, 0 orphan lines
that ERROR event: level=ERROR logger=HikariPool continuation lines=3
exception line: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
## The same line without the application name bracket
parsed: level=INFO thread=nio-8080-exec-1 logger=OrderController message=Order 42 placed
+20
View File
@@ -0,0 +1,20 @@
# Template mining
## Baseline: 3857 events become 10 templates
791 INFO CatalogController GET /api/products/<*> <*> in <*> ms
746 INFO AuthFilter Token validated for user u-<*>
715 INFO OrderController Order <*> placed by customer c-<*> total=<*>
695 INFO InventoryService Reserved <*> units of SKU-<*>
653 INFO PaymentService Payment approved for order <*> in <*> ms
120 INFO HikariPool HikariPool-<*> - Pool stats (total=<*>, active=<*>, idle=<*>, waiting=<*>)
62 WARN PaymentService Payment declined for order <*>: insufficient funds
43 WARN SlowQueryDetector Slow query (<*> ms): select * from orders where customer_id = ?
30 ERROR OrderController Failed to process order <*>: validation failed
2 INFO CacheRefresher Nightly cache refresh completed in <*> ms
## Failure: words that are not numbers. Same traffic, real user names instead of u-1042
AuthFilter templates, digits-only masking: 20
AuthFilter templates, with the second pass: 1
all templates, digits-only masking: 29
all templates, with the second pass: 10
746 Token validated for user <*>
+21
View File
@@ -0,0 +1,21 @@
# What a hashing embedder considers close (distance = 1 - cosine)
distance 0.415
A: WARN PaymentService Payment declined for order <*>: insufficient funds
B: INFO PaymentService Payment approved for order <*> in <*> ms
distance 0.249
A: ERROR OrderController Failed to process order <*>: Unable to acquire JDBC Connection
B: ERROR OrderController Failed to process order <*>: validation failed
distance 0.853
A: ERROR OrderController Failed to process order <*>: Unable to acquire JDBC Connection
B: ERROR HikariPool Could not get a database connection from the pool
distance 0.118
A: INFO PaymentService Payment approved for order <*> in <*> ms
B: INFO PaymentService Payment approved for order <*> in <*> ms but ledger write failed
distance 1.000
A: INFO AuthFilter Token validated for user u-<*>
B: ERROR HikariPool HikariPool-<*> - Connection is not available, request timed out after <*>ms.
+25
View File
@@ -0,0 +1,25 @@
# k decides how far from normal a template can be
## Baseline templates grouped with k = 4
cluster 0:
INFO CatalogController GET /api/products/<*> <*> in <*> ms (distance to centre 0.325)
INFO InventoryService Reserved <*> units of SKU-<*> (distance to centre 0.325)
INFO CacheRefresher Nightly cache refresh completed in <*> ms (distance to centre 0.321)
cluster 1:
INFO OrderController Order <*> placed by customer c-<*> total=<*> (distance to centre 0.343)
INFO PaymentService Payment approved for order <*> in <*> ms (distance to centre 0.212)
WARN PaymentService Payment declined for order <*>: insufficient funds (distance to centre 0.315)
ERROR OrderController Failed to process order <*>: validation failed (distance to centre 0.339)
cluster 2:
INFO AuthFilter Token validated for user u-<*> (distance to centre 0.239)
INFO HikariPool HikariPool-<*> - Pool stats (total=<*>, active=<*>, idle=<*>, waiting=<*>) (distance to centre 0.239)
cluster 3:
WARN SlowQueryDetector Slow query (<*> ms): select * from orders where customer_id = ? (distance to centre 0.000)
## Distance of the five new templates, and the threshold, for different k (threshold = worst baseline distance + 0.05)
k worst-normal threshold | hikari jdbc gateway reword ledger-fail
1 0.677 0.727 | 0.747* 0.629 0.623 0.470 0.368
2 0.564 0.614 | 0.726* 0.477 0.471 0.410 0.305
4 0.343 0.393 | 0.678* 0.434* 0.459* 0.394* 0.256
10 0.000 0.050 | 0.510* 0.249* 0.401* 0.101* 0.118*
(* = flagged at that threshold)
+18
View File
@@ -0,0 +1,18 @@
# Findings for the 30-minute target window (incident starts at minute 12)
threshold 0.393 (worst baseline distance 0.343 + margin 0.05), k = 4
## Flagged
NOVEL_TEMPLATE ERROR HikariPool HikariPool-<*> - Connection is not available, request timed out after <*>ms. x144 new template, distance 0.678 > 0.393
NOVEL_TEMPLATE WARN PaymentService Payment gateway timeout after <*> ms for order <*>, retry <*> of <*> x90 new template, distance 0.459 > 0.393
NOVEL_TEMPLATE ERROR OrderController Failed to process order <*>: Unable to acquire JDBC Connection x108 new template, distance 0.434 > 0.393
NOVEL_TEMPLATE INFO OrderController Order <*> placed by customer c-<*> total=<*> currency=INR x156 new template, distance 0.394 > 0.393
RATE_SPIKE WARN PaymentService Payment declined for order <*>: insufficient funds x44 peak 44 per 5 min vs baseline mean 2.6 (std 0.9), z = 45.6
## Not flagged, although something is wrong
pool stats template known to the baseline: true
during the incident: HikariPool-1 - Pool stats (total=10, active=10, idle=0, waiting=32)
during normal times: HikariPool-1 - Pool stats (total=10, active=2, idle=8, waiting=0)
'but ledger write failed' has distance 0.256, threshold 0.393, so it is NOT flagged
## Flagged, although nothing is wrong
the deployment's reworded order line has distance 0.394 against threshold 0.393
+11
View File
@@ -0,0 +1,11 @@
# What each margin flags, k = 4
worst baseline distance: 0.343
margin 0.00 -> threshold 0.343 -> 4 of 5 new templates flagged: Order <*> | HikariPool-<*> - | Failed to | Payment gateway
margin 0.05 -> threshold 0.393 -> 4 of 5 new templates flagged: Order <*> | HikariPool-<*> - | Failed to | Payment gateway
margin 0.10 -> threshold 0.443 -> 2 of 5 new templates flagged: HikariPool-<*> - | Payment gateway
margin 0.20 -> threshold 0.543 -> 1 of 5 new templates flagged: HikariPool-<*> -
## Ranking is more trustworthy than the cut-off
the three real new templates score 0.678, 0.434, 0.459
the harmless reword scores 0.394, so it ranks below all three
a threshold between 0.394 and 0.434 would split them, but it is chosen after seeing the answer
+22
View File
@@ -0,0 +1,22 @@
# From findings to one incident and one summary
5 findings -> 1 incident(s)
window 2026-11-30 11:05:13 +05:30 to 2026-11-30 11:29:46 +05:30, 5 findings, 542 events
## Summary without a model
ERROR incident from 2026-11-30 11:05:13 +05:30 to 2026-11-30 11:29:46 +05:30: 4 new message kinds and 1 known messages surging, 542 events in all. Top: "HikariPool-<*> - Connection is not available, request timed out after <*>ms." (HikariPool, 144x); "Payment gateway timeout after <*> ms for order <*>, retry <*> of <*>" (PaymentService, 90x); "Failed to process order <*>: Unable to acquire JDBC Connection" (OrderController, 108x).
## The prompt a model would receive
You are helping an on-call engineer. Below are the anomalous log templates from one incident.
Write 3 sentences: what changed, the likely cause, and what to check first.
Only use facts from the list; do not invent hosts, versions or numbers.
Window: 2026-11-30 11:05:13 +05:30 to 2026-11-30 11:29:46 +05:30
1. [ERROR] HikariPool: HikariPool-<*> - Connection is not available, request timed out after <*>ms. (NOVEL_TEMPLATE, 144 events, new template, distance 0.678 > 0.393)
2. [WARN] PaymentService: Payment gateway timeout after <*> ms for order <*>, retry <*> of <*> (NOVEL_TEMPLATE, 90 events, new template, distance 0.459 > 0.393)
3. [ERROR] OrderController: Failed to process order <*>: Unable to acquire JDBC Connection (NOVEL_TEMPLATE, 108 events, new template, distance 0.434 > 0.393)
4. [INFO] OrderController: Order <*> placed by customer c-<*> total=<*> currency=INR (NOVEL_TEMPLATE, 156 events, new template, distance 0.394 > 0.393)
5. [WARN] PaymentService: Payment declined for order <*>: insufficient funds (RATE_SPIKE, 44 events, peak 44 per 5 min vs baseline mean 2.6 (std 0.9), z = 45.6)
## Size
raw target window: 2196 physical lines, 310589 characters
prompt: 1112 characters (0.4% of the raw window)
+6
View File
@@ -0,0 +1,6 @@
# The embedder is a seam: a remote one behind a stub /v1/embeddings
embedder: openai-compatible:stub-model, dimensions: 32
HTTP requests while fitting 10 baseline templates: 2
first request body: {"model":"stub-model","input":["INFO CatalogController GET /api/products/<*> <*> in <*> ms","INFO AuthFilter Token validated for user u-<*>","INFO Ord...
distance of the pool-timeout template through the stub: 0.520
The stub returns the hashing embedder's own vectors, so this shows the plumbing and says nothing about any real model.
@@ -0,0 +1,3 @@
# A model that returns a different vector length
configured dimensions: 32, stub returned 3
error: expected 32 dimensions but the model returned 3
+6
View File
@@ -0,0 +1,6 @@
# What the summariser sends to a chat endpoint (stub server)
request model: stub-model, temperature: 0, messages: 1
request content characters: 1112
contains a stack-trace line: false
reply: STUB REPLY: the pool ran out of connections.
Not run against a real model. The stub proves the request shape and the reply parsing.
+10
View File
@@ -0,0 +1,10 @@
# GET /api/incidents on a running Spring Boot application
HTTP 200
baselineLines=3947 targetLines=2196 baselineTemplates=10 targetTemplates=14 clusters=4 threshold=0.393
incidents: 1
NOVEL_TEMPLATE ERROR x144 HikariPool-<*> - Connection is not available, request timed out after <*>ms.
NOVEL_TEMPLATE WARN x90 Payment gateway timeout after <*> ms for order <*>, retry <*> of <*>
NOVEL_TEMPLATE ERROR x108 Failed to process order <*>: Unable to acquire JDBC Connection
NOVEL_TEMPLATE INFO x156 Order <*> placed by customer c-<*> total=<*> currency=INR
RATE_SPIKE WARN x44 Payment declined for order <*>: insufficient funds
summary: ERROR incident from 2026-11-30 11:05:13 +05:30 to 2026-11-30 11:29:46 +05:30: 4 new message kinds and 1 known messages surging, 542 events in all. Top: "HikariPool-<*> - Connection is not available, request timed out after <*>ms." (HikariPool, 144x); "Payment gateway timeout after <*> ms for order <*>, retry <*> of <*>" (PaymentService, 90x); "Failed to process order <*>: Unable to acquire JDBC Connection" (OrderController, 108x).
@@ -0,0 +1,15 @@
# A log file written by Spring Boot 4.2.0 itself (spring.application.name=shop)
## The first three lines, and the ERROR with its first stack-trace lines
2026-12-01T23:53:34.953+05:30 INFO 12412 --- [shop] [main] o.a.maven.surefire.booter.ForkedBooter : Starting ForkedBooter v3.5.4 using Java 25.0.5.1 with PID 12412 (started by root in /tmp/work/java-ai-agents/log-anomaly)
2026-12-01T23:53:34.975+05:30 INFO 12412 --- [shop] [main] o.a.maven.surefire.booter.ForkedBooter : No active profile set, falling back to 1 default profile: "default"
2026-12-01T23:53:37.369+05:30 INFO 12412 --- [shop] [main] o.s.boot.tomcat.TomcatWebServer : Tomcat initialized with port 0 (http)
2026-12-01T23:53:38.561+05:30 ERROR 12412 --- [shop] [main] com.ankurm.shop.OrderController : Failed to process order 42
java.lang.IllegalStateException: quantity must be greater than 0
at com.ankurm.logs.RealSpringBootLogTest.theParserReadsWhatSpringBootActuallyWrites(RealSpringBootLogTest.java:23) ~[test-classes/:na]
## Parsed
96 physical lines, 11 events, 0 orphan lines
ERROR event: logger=OrderController message=Failed to process order 42 continuation lines=85
exception line: java.lang.IllegalStateException: quantity must be greater than 0
+14
View File
@@ -0,0 +1,14 @@
# The packaged jar answering curl
$ java -jar target/log-anomaly.jar --server.port=18080 &
$ curl -s "localhost:18080/api/incidents?baseline=target/sample-logs/baseline.log&target=target/sample-logs/target.log"
{
"baselineLines": 3947,
"targetLines": 2196,
"baselineTemplates": 10,
"targetTemplates": 14,
"clusters": 4
}
ERROR incident from 2026-11-30 11:05:13 +05:30 to 2026-11-30 11:29:46 +05:30: 4 new message kinds and 1 known messages surging, 542 events in all. Top: "HikariPool-<*> - Connection is not available, request timed out after <*>ms." (HikariPool, 144x); "Payment gateway timeout after <*> ms for order <*>, retry <*> of <*>" (PaymentService, 90x); "Failed to process order <*>: Unable to acquire JDBC Connection" (OrderController, 108x).
$ curl -s -o /dev/null -w "%{http_code}" "localhost:18080/api/incidents?baseline=missing.log&target=missing.log"
500