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
@@ -0,0 +1,53 @@
package com.ankurm.logs;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.json.JsonMapper;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class EndpointTest {
@LocalServerPort int port;
@TempDir Path tmp;
@Test
void theEndpointReportsTheIncident() throws Exception {
Fixtures f = new Fixtures();
Path base = Files.write(tmp.resolve("baseline.log"), f.baselineLines);
Path target = Files.write(tmp.resolve("target.log"), f.targetLines);
String url = "http://localhost:%d/api/incidents?baseline=%s&target=%s".formatted(port,
URLEncoder.encode(base.toString(), StandardCharsets.UTF_8), URLEncoder.encode(target.toString(), StandardCharsets.UTF_8));
HttpResponse<String> res = HttpClient.newHttpClient().send(HttpRequest.newBuilder(URI.create(url)).GET().build(), HttpResponse.BodyHandlers.ofString());
JsonNode body = JsonMapper.builder().build().readTree(res.body());
Transcript t = new Transcript("11-endpoint.txt", "GET /api/incidents on a running Spring Boot application");
t.line("HTTP %d", res.statusCode());
t.line("baselineLines=%s targetLines=%s baselineTemplates=%s targetTemplates=%s clusters=%s threshold=%.3f",
body.get("baselineLines"), body.get("targetLines"), body.get("baselineTemplates"), body.get("targetTemplates"), body.get("clusters"), body.get("threshold").asDouble());
t.line("incidents: %d", body.get("incidents").size());
body.get("incidents").get(0).get("findings").forEach(x -> t.line(" %s %s x%s %s", x.get("kind").asString(), x.get("template").get("level").asString(), x.get("count"), x.get("template").get("text").asString()));
t.line("summary: %s", body.get("summaries").get(0).asString());
t.write();
assertThat(res.statusCode()).isEqualTo(200);
assertThat(body.get("incidents")).hasSize(1);
assertThat(body.get("incidents").get(0).get("findings")).hasSize(5);
assertThat(body.get("summaries").get(0).asString()).contains("ERROR incident");
}
}