package com.ankurm.logs; /** Turns an incident into a few sentences for a human on call. */ public interface IncidentSummarizer { String summarise(Incident incident); /** Log times are shown the way the log wrote them, in the application's own offset, not in UTC. */ static String at(java.time.Instant t) { return java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(t.atOffset(java.time.ZoneOffset.ofHoursMinutes(5, 30))) + " +05:30"; } /** The text a model would be sent, so its size can be measured without calling one. */ default String promptFor(Incident incident) { StringBuilder b = new StringBuilder(""" 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. """); b.append("Window: ").append(at(incident.start())).append(" to ").append(at(incident.end())).append('\n'); int i = 1; for (Finding f : incident.findings()) { b.append(i++).append(". [").append(f.template().level()).append("] ").append(f.template().logger()) .append(": ").append(f.template().text()).append(" (").append(f.kind()).append(", ") .append(f.count()).append(" events, ").append(f.reason()).append(")\n"); } return b.toString(); } }