feat!: Urutau 2.0.0, ultralight probes and a single analysis hub
CI / Format and vet (pull_request) Failing after 53s
CI / Dependency audit (pull_request) Successful in 33s
CI / Tests (Linux, race detector) (pull_request) Successful in 2m1s
CI / Docker images (build and smoke test) (pull_request) Failing after 47s

Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that
tails the logs, ships raw lines to the hub over HTTPS with an on-disk
spool, and applies enforce decisions locally. The hub keeps one node per
probe (primary node = the 1.x data dir, unchanged), does all analysis and
serves the UI. Peer federation is removed. 'urutau import' brings 1.x
data dirs in with hash and count verification. UI: probes page, host
qualified incidents, IPs never wrap, egress heatmap labels, live and
replay globes no longer auto-rotate, replay repeat, live traffic metrics.

BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone;
log path variables move from the hub to the probe. See docs/migration-2.0.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 22:14:50 -03:00
1 parent 23a7a5963a
commit 8546d14cef
130 files changed
+9396 -3311

No files matched your search

+212 -20
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"net/http"
"sort"
"strconv"
"strings"
"sync"
@@ -25,6 +26,10 @@ func init() {
registerUserRoute("POST /api/v1/incidents", func(s *Server) http.HandlerFunc { return s.incidentCreate })
registerUserRoute("PATCH /api/v1/incidents/{id}", func(s *Server) http.HandlerFunc { return s.incidentPatch })
registerUserRoute("POST /api/v1/incidents/{id}/comments", func(s *Server) http.HandlerFunc { return s.incidentComment })
// host/INC-n written as two path segments
registerUserRoute("GET /api/v1/incidents/{host}/{id}", func(s *Server) http.HandlerFunc { return s.incidentGet })
registerUserRoute("PATCH /api/v1/incidents/{host}/{id}", func(s *Server) http.HandlerFunc { return s.incidentPatch })
registerUserRoute("POST /api/v1/incidents/{host}/{id}/comments", func(s *Server) http.HandlerFunc { return s.incidentComment })
}
var incidentServer atomic.Pointer[Server]
@@ -55,14 +60,31 @@ func StartIncidentSync(ctx context.Context, wg *sync.WaitGroup) {
}
func (s *Server) syncNow(ctx context.Context) {
if s.opt.Incidents == nil || egressEngine.Load() == nil {
if s.opt.Incidents == nil {
return
}
now := s.opt.Store.Now().Unix()
if s.opt.Nodes != nil { // one store per node, fed by that node's own egress
for _, h := range s.opt.Nodes.Hosts() {
eng, st := s.opt.Nodes.Egress(h), s.opt.Nodes.Incidents(h)
if eng == nil || st == nil {
continue
}
rep := eng.Report(now-24*3600, now)
for i := range rep.Findings {
rep.Findings[i].Host = h
}
s.syncInto(st, rep)
}
return
}
if egressEngine.Load() == nil {
return
}
cctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
rep, _ := s.egressReport(cctx, now-24*3600, now, true, s.opt.Hub != nil, "")
s.syncIncidents(rep)
s.syncInto(s.opt.Incidents, rep)
}
func (s *Server) findingHost(f egress.Finding) string {
@@ -76,8 +98,10 @@ func (s *Server) findingKey(f egress.Finding) string {
return incidents.Key(s.findingHost(f), f.Kind, f.Workload, f.Dst, f.DPort, f.Proto)
}
func (s *Server) syncIncidents(rep egress.Report) {
if s.opt.Incidents == nil {
func (s *Server) syncIncidents(rep egress.Report) { s.syncInto(s.opt.Incidents, rep) }
func (s *Server) syncInto(st *incidents.Store, rep egress.Report) {
if st == nil {
return
}
fs := make([]incidents.Finding, 0, len(rep.Findings))
@@ -85,7 +109,7 @@ func (s *Server) syncIncidents(rep egress.Report) {
fs = append(fs, incidents.Finding{Host: s.findingHost(f), Kind: f.Kind, Severity: f.Severity, Workload: f.Workload, Dst: f.Dst,
Proto: f.Proto, Detail: f.Detail, DPort: f.DPort, First: f.First, Last: f.Last, Count: f.Count})
}
s.opt.Incidents.Sync(fs)
st.Sync(fs)
}
// annotateFindings fills ticket_id/ticket_status/suppressed and, unless show
@@ -95,16 +119,35 @@ func (s *Server) annotateFindings(rep *egress.Report, show bool) int {
if s.opt.Incidents == nil || len(rep.Findings) == 0 {
return 0
}
keys := make([]string, len(rep.Findings))
refs := make([]incidents.Ref, len(rep.Findings))
has := make([]bool, len(rep.Findings))
byStore := map[string][]int{}
for i, f := range rep.Findings {
keys[i] = s.findingKey(f)
h := s.findingHost(f)
byStore[h] = append(byStore[h], i)
}
for h, idx := range byStore {
st := s.incStore(h)
if st == nil {
continue
}
keys := make([]string, len(idx))
for j, i := range idx {
keys[j] = s.findingKey(rep.Findings[i])
}
m := st.Lookup(keys)
for j, i := range idx {
if ref, ok := m[keys[j]]; ok {
ref.ID = h + "/" + ref.ID
refs[i], has[i] = ref, true
}
}
}
refs := s.opt.Incidents.Lookup(keys)
out := rep.Findings[:0:0]
n := 0
for i, f := range rep.Findings {
if ref, ok := refs[keys[i]]; ok {
f.TicketID, f.TicketStatus, f.Suppressed = ref.ID, ref.Status, ref.Suppress
if has[i] {
f.TicketID, f.TicketStatus, f.Suppressed = refs[i].ID, refs[i].Status, refs[i].Suppress
}
if f.Suppressed {
n++
@@ -191,6 +234,54 @@ func (s *Server) incidentQuery(w http.ResponseWriter, r *http.Request) (incident
return q, true
}
// qSummary and qTicket carry the id qualified by the node ("hostinger/INC-2")
// and the node as host.
type qSummary struct {
incidents.Summary
ID string `json:"id"`
Host string `json:"host"`
}
type qTicket struct {
incidents.Ticket
ID string `json:"id"`
Host string `json:"host"`
}
type qPage struct {
Items []qSummary `json:"items"`
Total int `json:"total"`
Counts map[string]int `json:"counts"`
Store incidents.Stats `json:"store"`
Hosts []string `json:"hosts"`
}
// splitID reads "INC-n" with an optional host (path segment, "host/INC-n"
// in one segment, or ?host=); without host the primary node is meant.
func (s *Server) splitID(r *http.Request) (host, id string) {
id = r.PathValue("id")
host = r.PathValue("host")
if h, rest, ok := strings.Cut(id, "/"); ok {
host, id = h, rest
}
if host == "" {
host = r.URL.Query().Get("host")
}
if host == "" {
host = s.primaryName()
}
return host, id
}
// storeFor answers 404 itself when the node has no ticket store.
func (s *Server) storeFor(w http.ResponseWriter, host string) *incidents.Store {
if st := s.incStore(host); st != nil {
return st
}
writeJSON(w, http.StatusNotFound, map[string]string{"error": "incident not found"})
return nil
}
func (s *Server) incidentList(w http.ResponseWriter, r *http.Request) {
if !s.incidentsOn(w) {
return
@@ -199,19 +290,93 @@ func (s *Server) incidentList(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
writeJSON(w, 200, s.opt.Incidents.List(q))
hosts := s.incHosts()
if q.Host != "" && q.Host != "all" {
hosts = []string{q.Host}
if s.incStore(q.Host) == nil {
writeJSON(w, 200, qPage{Items: []qSummary{}, Counts: map[string]int{}, Hosts: s.incHosts()})
return
}
}
q.Host = ""
if len(hosts) == 1 {
pg := s.incStore(hosts[0]).List(q)
out := qPage{Items: make([]qSummary, 0, len(pg.Items)), Total: pg.Total, Counts: pg.Counts, Store: pg.Store, Hosts: s.incHosts()}
for _, it := range pg.Items {
out.Items = append(out.Items, qSummary{Summary: it, ID: hosts[0] + "/" + it.ID, Host: hosts[0]})
}
writeJSON(w, 200, out)
return
}
// several nodes: merge, sort and page here
all := []qSummary{}
out := qPage{Counts: map[string]int{}, Hosts: s.incHosts()}
page, per := q.Page, q.PerPage
for _, h := range hosts {
st := s.incStore(h)
if st == nil {
continue
}
pg := st.List(incidents.Query{Status: q.Status, Severity: q.Severity, Q: q.Q, Sort: q.Sort, Page: 1, PerPage: 1})
for k, v := range pg.Counts {
out.Counts[k] += v
}
out.Store.Size += pg.Store.Size
out.Store.Max += pg.Store.Max
out.Store.Untracked += pg.Store.Untracked
for _, it := range st.All(q) {
all = append(all, qSummary{Summary: it, ID: h + "/" + it.ID, Host: h})
}
}
sortSummaries(all, q.Sort)
if per <= 0 {
per = 50
}
per = min(per, 200)
if page < 1 {
page = 1
}
lo := min((page-1)*per, len(all))
hi := min(lo+per, len(all))
out.Total, out.Items = len(all), all[lo:hi]
if out.Items == nil {
out.Items = []qSummary{}
}
writeJSON(w, 200, out)
}
func sortSummaries(l []qSummary, mode string) {
sort.SliceStable(l, func(i, j int) bool {
a, b := l[i], l[j]
switch mode {
case "severity":
if ra, rb := incidents.SevRank(a.Severity), incidents.SevRank(b.Severity); ra != rb {
return ra > rb
}
case "last_seen":
if a.LastSeen != b.LastSeen {
return a.LastSeen > b.LastSeen
}
}
return a.UpdatedAt > b.UpdatedAt
})
}
func (s *Server) incidentGet(w http.ResponseWriter, r *http.Request) {
if !s.incidentsOn(w) {
return
}
t, err := s.opt.Incidents.Get(r.PathValue("id"))
host, id := s.splitID(r)
st := s.storeFor(w, host)
if st == nil {
return
}
t, err := st.Get(id)
if err != nil {
incidentErr(w, err)
return
}
writeJSON(w, 200, t)
writeJSON(w, 200, qTicket{Ticket: t, ID: host + "/" + t.ID, Host: host})
}
func (s *Server) incidentCreate(w http.ResponseWriter, r *http.Request) {
@@ -223,12 +388,16 @@ func (s *Server) incidentCreate(w http.ResponseWriter, r *http.Request) {
return
}
in.Via = s.via(r)
t, err := s.opt.Incidents.Create(in)
host := s.primaryName()
if in.Host != "" && s.incStore(in.Host) != nil {
host = in.Host
}
t, err := s.incStore(host).Create(in)
if err != nil {
incidentErr(w, err)
return
}
writeJSON(w, http.StatusCreated, t)
writeJSON(w, http.StatusCreated, qTicket{Ticket: t, ID: host + "/" + t.ID, Host: host})
}
func (s *Server) incidentPatch(w http.ResponseWriter, r *http.Request) {
@@ -240,12 +409,17 @@ func (s *Server) incidentPatch(w http.ResponseWriter, r *http.Request) {
return
}
p.Via = s.via(r)
t, err := s.opt.Incidents.Update(r.PathValue("id"), p)
host, id := s.splitID(r)
st := s.storeFor(w, host)
if st == nil {
return
}
t, err := st.Update(id, p)
if err != nil {
incidentErr(w, err)
return
}
writeJSON(w, 200, t)
writeJSON(w, 200, qTicket{Ticket: t, ID: host + "/" + t.ID, Host: host})
}
func (s *Server) incidentComment(w http.ResponseWriter, r *http.Request) {
@@ -259,12 +433,17 @@ func (s *Server) incidentComment(w http.ResponseWriter, r *http.Request) {
if !incidentBody(w, r, &in) {
return
}
t, err := s.opt.Incidents.AddComment(r.PathValue("id"), in.Text, in.Author, s.via(r))
host, id := s.splitID(r)
st := s.storeFor(w, host)
if st == nil {
return
}
t, err := st.AddComment(id, in.Text, in.Author, s.via(r))
if err != nil {
incidentErr(w, err)
return
}
writeJSON(w, http.StatusCreated, t)
writeJSON(w, http.StatusCreated, qTicket{Ticket: t, ID: host + "/" + t.ID, Host: host})
}
// csvCell neutralises spreadsheet formulas.
@@ -301,7 +480,20 @@ func (s *Server) incidentCSV(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", `attachment; filename="incidents.csv"`)
cw := csv.NewWriter(w)
cw.Write([]string{"id", "status", "severity", "host", "kind", "workload", "dst", "dport", "proto", "title", "first_seen", "last_seen", "count", "assignee", "tags", "verdict", "suppress", "created_at", "updated_at"})
for _, t := range s.opt.Incidents.All(q) {
hosts := s.incHosts()
if q.Host != "" && q.Host != "all" {
hosts = []string{q.Host}
}
q.Host = ""
var rows []qSummary
for _, h := range hosts {
if st := s.incStore(h); st != nil {
for _, t := range st.All(q) {
rows = append(rows, qSummary{Summary: t, ID: h + "/" + t.ID, Host: h})
}
}
}
for _, t := range rows {
row := []string{t.ID, t.Status, t.Severity, t.Host, t.Kind, t.Workload, t.Dst, strconv.Itoa(int(t.DPort)), t.Proto, t.Title,
strconv.FormatInt(t.FirstSeen, 10), strconv.FormatInt(t.LastSeen, 10), strconv.Itoa(t.Count), t.Assignee, strings.Join(t.Tags, ","), t.Verdict,
strconv.FormatBool(t.Suppress), strconv.FormatInt(t.CreatedAt, 10), strconv.FormatInt(t.UpdatedAt, 10)}