feat: 1.2.0 attack intelligence, replay, 30-day history and new interface
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 27s
CI / Dependency audit (push) Successful in 18s
CI / Tests (Linux, race detector) (push) Successful in 58s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 5s

Intelligence: attack families mapped to MITRE ATT&CK, network type from
ASN/rDNS without external APIs, request cadence, sessions with
recon/probe/exploit/access/banned stages, campaigns across IPs, verdict
with reasons, recommended actions, exposure detection (2xx with a body
on sensitive paths), STIX 2.1 export, FCrDNS for search engine bots,
optional Tor exit list.

Data: 30-day retention, twelve ranges plus custom from/to, an on-disk
event log (daily files, hourly gzip members, size cap, corruption and
disk-full tolerant), /events, /period, /metrics with stable per-hour
metrics, an extended /ip/{ip}, and peer /period merged on the hub.

Interface: layout system with fixed card sizes, range picker in the
URL, IP analysis page, Replay page, Geography down to state and city
(Natural Earth admin-1), Live page redesigned with stable metrics and a
reusable attack map. Demo data and documentation screenshots.

Security: bounded and deadline-limited period computations, linear
campaign clustering, singleflight caches, sanitized peer studies, event
query budgets, gzip bomb guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 21:45:59 -03:00
1 parent 8f1ac462d1
commit b7462c14fa
325 files changed
+19117 -1307

No files matched your search

+40 -4
View File
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
@@ -42,9 +43,37 @@ type Config struct {
PeerAllow string // CIDRs allowed to call /api/v1/peer/export (empty: any source with the token)
TrustedProxy string // proxies whose X-Forwarded-For is believed
Retention time.Duration
TorExits string // file with Tor exit addresses, one per line; empty disables the check
EventsMax string // size cap of the event registry ("512MB", "0" disables it)
NoAuth bool
}
// DefaultEventsMax is the default size cap of the event registry.
const DefaultEventsMax = "512MB"
// ParseSize reads "512MB", "1GiB", "2g", "1048576" (bytes) into bytes.
func ParseSize(v string) (int64, error) {
v = strings.TrimSpace(strings.ToLower(v))
if v == "" {
return 0, fmt.Errorf("empty size")
}
mult := int64(1)
for _, u := range []struct {
suf string
m int64
}{{"gib", 1 << 30}, {"mib", 1 << 20}, {"kib", 1 << 10}, {"gb", 1 << 30}, {"mb", 1 << 20}, {"kb", 1 << 10}, {"g", 1 << 30}, {"m", 1 << 20}, {"k", 1 << 10}, {"b", 1}} {
if strings.HasSuffix(v, u.suf) {
mult, v = u.m, strings.TrimSpace(strings.TrimSuffix(v, u.suf))
break
}
}
n, err := strconv.ParseFloat(v, 64)
if err != nil || n < 0 || n > 1<<40 {
return 0, fmt.Errorf("invalid size %q", v)
}
return int64(n * float64(mult)), nil
}
type listFlag []string
func (l *listFlag) String() string { return strings.Join(*l, ",") }
@@ -106,7 +135,7 @@ func ParseFlags(name string, args []string) (Config, error) {
mfrom := &csvFlag{val: env("URUTAU_MONITOR_FROM", "")}
doms := &csvFlag{val: env("URUTAU_DOMAINS", "")}
admins := &csvFlag{val: env("URUTAU_ADMIN_USERS", "")}
fs.Var(admins, "admin-users", "SSH users whose successful logins keep their IP out of the blocklist for 24 h; empty means any user (URUTAU_ADMIN_USERS)")
fs.Var(admins, "admin-users", "SSH users whose successful logins keep their IP out of the blocklist for 24 h; empty means nobody is immune (URUTAU_ADMIN_USERS)")
fs.Var(mfrom, "monitor-from", "networks the monitoring User-Agents come from; empty trusts the User-Agent alone for benign hits (URUTAU_MONITOR_FROM)")
fs.Var(doms, "domains", "analytics domain allowlist, exact names or *.example.com; empty tracks every domain that answers 2xx/3xx (URUTAU_DOMAINS)")
fs.StringVar(&c.GeoDir, "geo-dir", env("URUTAU_GEO_DIR", ""), "geo database directory, default <data-dir>/geo (URUTAU_GEO_DIR)")
@@ -120,7 +149,9 @@ func ParseFlags(name string, args []string) (Config, error) {
fs.Var(tproxy, "trusted-proxy", "reverse proxies whose X-Forwarded-For is trusted for the real client IP (URUTAU_TRUSTED_PROXY)")
fs.StringVar(&c.Location, "location", env("URUTAU_LOCATION", ""), `where this instance lives, "lat,lon" or "lat,lon,label"; shown as the destination of live arcs (URUTAU_LOCATION)`)
fs.StringVar(&c.PeerBlocklist, "peer-blocklist", env("URUTAU_PEER_BLOCKLIST", "on"), "on: the blocklist also lists strong hostile IPs seen only by peers; off: local IPs only (URUTAU_PEER_BLOCKLIST)")
fs.DurationVar(&c.Retention, "retention", 7*24*time.Hour, "how long data is kept, at most 168h (URUTAU_RETENTION)")
fs.DurationVar(&c.Retention, "retention", store.DefaultRetention, "how long data is kept, at most 720h (URUTAU_RETENTION)")
fs.StringVar(&c.TorExits, "tor-exits", env("URUTAU_TOR_EXITS", ""), "file with Tor exit node addresses, one per line, reloaded every 24 h when it changes; empty disables (URUTAU_TOR_EXITS)")
fs.StringVar(&c.EventsMax, "events-max", env("URUTAU_EVENTS_MAX", DefaultEventsMax), "size cap of the event registry in <data-dir>/events, 0 disables it (URUTAU_EVENTS_MAX)")
fs.BoolVar(&c.NoAuth, "insecure-no-auth", false, "disable authentication; only allowed on a loopback bind")
if v := os.Getenv("URUTAU_GEO_UPDATE"); v != "" {
if d, err := time.ParseDuration(v); err == nil {
@@ -205,8 +236,13 @@ func (c Config) Validate(token string) ([]fed.Peer, error) {
return nil, fmt.Errorf("--monitor-ua: %w", err)
}
}
if c.Retention < time.Hour {
return nil, fmt.Errorf("--retention must be at least 1h")
if c.Retention < time.Hour || c.Retention > store.DefaultRetention {
return nil, fmt.Errorf("--retention must be between 1h and 720h")
}
if c.EventsMax != "" {
if _, err := ParseSize(c.EventsMax); err != nil {
return nil, fmt.Errorf("--events-max: %w", err)
}
}
if c.NoAuth {
if !loopbackBind(c.Bind) {
+29 -1
View File
@@ -9,6 +9,7 @@ import (
"net/http"
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"strings"
"sync"
@@ -16,6 +17,7 @@ import (
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/fed"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/geo"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/rdns"
@@ -35,7 +37,7 @@ func Serve(c Config) error {
return err
}
if os.Getenv("GOMEMLIMIT") == "" {
debug.SetMemoryLimit(160 << 20)
debug.SetMemoryLimit(SoftMemoryLimit)
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
@@ -43,6 +45,16 @@ func Serve(c Config) error {
loc, _ := store.ParseLocation(c.Location) // validated above
st := store.New(store.Config{Name: c.Name, Version: Version, Retention: c.Retention, AdminUsers: c.AdminUserList(), Location: loc})
st.SetDomains(splitList(c.Domains))
watchTorExits(ctx, c.TorExits, 24*time.Hour, log)
var elog *evlog.Log
if max, err := ParseSize(orDefault(c.EventsMax, DefaultEventsMax)); err == nil && max > 0 {
if elog, err = evlog.Open(evlog.Options{Dir: filepath.Join(c.DataDir, "events"), MaxBytes: max, Retention: c.Retention, Log: log}); err != nil {
log.Warn("event registry unavailable, replay disabled", "err", err)
elog = nil
} else {
st.SetEventLog(elog)
}
}
rd := rdns.New()
st.SetRDNS(rd)
offsets := LoadState(st, c.DataDir, log)
@@ -63,6 +75,7 @@ func Serve(c Config) error {
var hub *fed.Hub
if len(peers) > 0 {
hub = fed.NewHub(peers, c.PeerToken)
hub.OnLive = st.RecordPeerEvent
}
allow, _ := core.ParseCIDRs(c.PeerAllow)
tproxy, _ := core.ParseCIDRs(c.TrustedProxy)
@@ -77,6 +90,10 @@ func Serve(c Config) error {
srv := server.HTTPServer(h, ctx)
var wg sync.WaitGroup
if elog != nil {
wg.Add(1)
go func() { defer wg.Done(); elog.Run(ctx) }()
}
runner.Start(ctx, offsets, &wg)
wg.Add(2)
go func() { defer wg.Done(); rd.Run(ctx) }()
@@ -160,3 +177,14 @@ func splitList(s string) []string {
}
return out
}
// SoftMemoryLimit is the Go soft memory limit when GOMEMLIMIT is not set; see
// the worst case measurements in the store tests.
const SoftMemoryLimit = 256 << 20
func orDefault(v, def string) string {
if v == "" {
return def
}
return v
}
+89
View File
@@ -0,0 +1,89 @@
package app
import (
"bufio"
"context"
"errors"
"fmt"
"log/slog"
"net/netip"
"os"
"strings"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/intel"
)
const (
maxTorFile = 8 << 20
maxTorExits = 100000
)
// LoadTorExits reads a file with one address per line (blank lines and #
// comments are skipped, invalid lines ignored, at most 100000 addresses).
func LoadTorExits(path string) ([]netip.Addr, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
if st, err := f.Stat(); err != nil || !st.Mode().IsRegular() {
return nil, errors.New("not a regular file")
} else if st.Size() > maxTorFile {
return nil, fmt.Errorf("file larger than %d bytes", maxTorFile)
}
var out []netip.Addr
sc := bufio.NewScanner(f)
sc.Buffer(make([]byte, 0, 4096), 4096)
for sc.Scan() && len(out) < maxTorExits {
l := strings.TrimSpace(sc.Text())
if i := strings.IndexByte(l, '#'); i >= 0 {
l = strings.TrimSpace(l[:i])
}
if a, err := netip.ParseAddr(l); err == nil && a.Zone() == "" {
out = append(out, a.Unmap())
}
}
return out, sc.Err()
}
// watchTorExits loads the list now and again every interval when the file
// changed. An empty path keeps the feature off.
func watchTorExits(ctx context.Context, path string, every time.Duration, log *slog.Logger) {
if path == "" {
return
}
var lastMod time.Time
var lastSize int64 = -1
load := func() {
st, err := os.Stat(path)
if err != nil {
log.Warn("tor exit list unavailable", "err", err)
return
}
if st.ModTime().Equal(lastMod) && st.Size() == lastSize {
return
}
addrs, err := LoadTorExits(path)
if err != nil {
log.Warn("tor exit list unreadable", "err", err)
return
}
intel.SetTorExits(addrs)
lastMod, lastSize = st.ModTime(), st.Size()
log.Info("tor exit list loaded", "n", len(addrs))
}
load()
go func() {
t := time.NewTicker(every)
defer t.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
load()
}
}
}()
}
+45
View File
@@ -0,0 +1,45 @@
package app
import (
"testing"
"time"
)
func TestRetentionEventsMaxFlags(t *testing.T) {
c, err := ParseFlags("serve", nil)
if err != nil || c.Retention != 720*time.Hour || c.EventsMax != "512MB" {
t.Fatalf("defaults %v %+v", err, c)
}
c, _ = ParseFlags("serve", []string{"--events-max", "1GiB", "--retention", "100h"})
if n, err := ParseSize(c.EventsMax); err != nil || n != 1<<30 || c.Retention != 100*time.Hour {
t.Fatal(c.EventsMax, c.Retention)
}
t.Setenv("URUTAU_EVENTS_MAX", "64m")
c, _ = ParseFlags("serve", nil)
if n, _ := ParseSize(c.EventsMax); n != 64<<20 {
t.Fatal("env")
}
tok := "tok-0123456789-abcdefghijklmnopqrstuvwxyz-QWERTY"
base := Config{Bind: "0.0.0.0:1", Ignore: DefaultIgnore, TrustedProxy: DefaultTrustedProxy, Retention: 720 * time.Hour}
if _, err := base.Validate(tok); err != nil {
t.Fatal(err)
}
base.Retention = 721 * time.Hour
if _, err := base.Validate(tok); err == nil {
t.Fatal("retention over 720h must be refused")
}
base.Retention, base.EventsMax = 720*time.Hour, "lots"
if _, err := base.Validate(tok); err == nil {
t.Fatal("bad --events-max must be refused")
}
for in, want := range map[string]int64{"512MB": 512 << 20, "0": 0, "2g": 2 << 30, "1048576": 1 << 20, "1.5kb": 1536} {
if n, err := ParseSize(in); err != nil || n != want {
t.Errorf("%s: %d %v", in, n, err)
}
}
for _, bad := range []string{"", "-1", "x", "1xb"} {
if _, err := ParseSize(bad); err == nil {
t.Errorf("%q must fail", bad)
}
}
}
+106
View File
@@ -0,0 +1,106 @@
package app
import (
"context"
"encoding/json"
"log/slog"
"net/http"
"net/http/httptest"
"net/netip"
"os"
"path/filepath"
"strings"
"testing"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/geo"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/intel"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/server"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
)
const realGeo = "/tmp/claude-1000/-home-lucas-Documents-Pessoal-keys/cd25aef5-8f8d-45f2-8ce0-f6644a45cb62/scratchpad/geo/real"
// Known addresses against the real DB-IP Lite databases: the ASN is filled and
// the network type follows. Skipped where the databases are not available.
func TestNetTypeWithRealGeoDatabases(t *testing.T) {
if _, err := os.Stat(realGeo); err != nil {
t.Skip("real geo databases not available")
}
gr, err := geo.Open(realGeo)
if err != nil {
t.Fatal(err)
}
st := store.New(store.Config{Name: "o", Retention: 720 * time.Hour})
st.SetEnricher(enricher{g: gr})
h := server.New(server.Options{Token: "user-token-0123456789-abcdefghijklmnop", Version: "t", Store: st})
cases := []struct {
ip string
asn float64
typ string
orgPart string
}{
{"159.89.1.1", 14061, "hosting", "DigitalOcean"},
{"78.46.1.1", 24940, "hosting", "Hetzner"},
{"129.146.1.1", 31898, "hosting", "Oracle"},
{"189.6.1.1", 28573, "isp/mobile", "Claro"}, // Brazilian residential/mobile operator
{"71.6.135.131", 10439, "research-scanner", "CariNet"},
}
for _, c := range cases {
st.Ingest(core.Event{Time: time.Now(), IP: c.ip, Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/.env", Status: 404})
r := httptest.NewRequest("GET", "/api/v1/ip/"+c.ip, nil)
r.Header.Set("Authorization", "Bearer user-token-0123456789-abcdefghijklmnop")
r.RemoteAddr = "198.51.100.1:1"
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
var d map[string]any
if err := json.Unmarshal(w.Body.Bytes(), &d); err != nil || w.Code != 200 {
t.Fatalf("%s: %d %s", c.ip, w.Code, w.Body)
}
id := d["identity"].(map[string]any)
if id["asn"].(float64) != c.asn || id["net_type"] != c.typ || !strings.Contains(id["as_org"].(string), c.orgPart) || id["net_type_reason"] == "" {
t.Errorf("%s: %v", c.ip, id)
}
if d["geo"].(map[string]any)["cc"] == "" {
t.Errorf("%s: no country", c.ip)
}
}
// the Tor exit list changes the type of a listed address
a := netip.MustParseAddr("159.89.1.1")
intel.SetTorExits([]netip.Addr{a})
defer intel.SetTorExits(nil)
if typ, _ := intel.NetTypeIP(a, 14061, "DigitalOcean, LLC", ""); typ != "tor" {
t.Fatalf("tor exit: %s", typ)
}
}
func TestTorExitsFile(t *testing.T) {
p := filepath.Join(t.TempDir(), "tor.txt")
os.WriteFile(p, []byte("# exits\n185.220.101.1\n\n 2001:db8::5 # v6\nnot-an-ip\n10.0.0.1%eth0\n185.220.101.2\n"), 0o600)
l, err := LoadTorExits(p)
if err != nil || len(l) != 3 {
t.Fatalf("%v %v", l, err)
}
big := filepath.Join(t.TempDir(), "big.txt")
os.WriteFile(big, []byte(strings.Repeat("1.2.3.4\n", 2<<20)), 0o600)
if _, err := LoadTorExits(big); err == nil {
t.Fatal("oversized file must be refused")
}
if _, err := LoadTorExits(t.TempDir()); err == nil {
t.Fatal("a directory is not a list")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
defer intel.SetTorExits(nil)
watchTorExits(ctx, p, time.Hour, slog.New(slog.NewTextHandler(os.Stderr, nil)))
if !intel.IsTorExit(netip.MustParseAddr("185.220.101.1")) {
t.Fatal("exit list not applied")
}
watchTorExits(ctx, "", time.Hour, nil) // off: nothing happens
c, _ := ParseFlags("serve", []string{"--tor-exits", p})
if c.TorExits != p {
t.Fatal("flag")
}
_ = http.StatusOK
}
+197
View File
@@ -0,0 +1,197 @@
package app
import (
"encoding/json"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/server"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/tail"
)
const (
scratch = "/tmp/claude-1000/-home-lucas-Documents-Pessoal-keys/cd25aef5-8f8d-45f2-8ce0-f6644a45cb62/scratchpad"
tokV4 = "user-token-0123456789-abcdefghijklmnop"
)
// ingestLogs feeds the three log files through the runner, like a backfill.
func ingestLogs(t *testing.T, st *store.Store, dir string) {
t.Helper()
c := Config{Name: st.Name(), Ignore: DefaultIgnore, MonitorUA: DefaultMonitorUA, Retention: 720 * time.Hour, TrustedProxy: DefaultTrustedProxy,
TraefikLog: filepath.Join(dir, "access.log"), AuthLog: filepath.Join(dir, "auth.log"), Fail2banLog: filepath.Join(dir, "fail2ban.log")}
r, err := NewRunner(c, st, slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Fatal(err)
}
for _, s := range r.Sources {
if _, err := os.Stat(s.path); err != nil {
continue
}
if err := tail.ReadAll(s.path, maxLine, r.handle(s), func() {}); err != nil {
t.Fatal(err)
}
}
}
func newLogged(t *testing.T) *store.Store {
st := store.New(store.Config{Name: "edge-1", Version: "t", Retention: 720 * time.Hour})
l, err := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "events")})
if err != nil {
t.Fatal(err)
}
st.SetEventLog(l)
return st
}
func detail(t *testing.T, st *store.Store, ip string) map[string]any {
h := server.New(server.Options{Token: tokV4, Version: "t", Store: st})
r := httptest.NewRequest("GET", "/api/v1/ip/"+ip, nil)
r.Header.Set("Authorization", "Bearer "+tokV4)
r.RemoteAddr = "198.51.100.1:1"
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Code != http.StatusOK {
t.Fatalf("%s: %d %s", ip, w.Code, w.Body)
}
var m map[string]any
if err := json.Unmarshal(w.Body.Bytes(), &m); err != nil {
t.Fatal(err)
}
return m
}
func sum(series map[string]any) (total float64, buckets int) {
var rows [][]any
for _, v := range series {
rows = append(rows, v.([]any))
}
if len(rows) == 0 {
return
}
for i := range rows[0] {
var b float64
for _, r := range rows {
b += r[i].(float64)
}
total += b
if b > 0 {
buckets++
}
}
return
}
func num(m map[string]any, k string) float64 { f, _ := m[k].(float64); return f }
// checkConsistent asserts that every section of the detail view of the most
// hostile address of a data set tells the same story.
func checkConsistent(t *testing.T, st *store.Store, wantEvents bool) {
t.Helper()
ips := st.AllIPs(store.Ranges["30d"], false)
if len(ips) == 0 {
t.Fatal("no addresses")
}
top := ips[0].IP
d := detail(t, st, top)
counts := d["counts"].(map[string]any)
first, last := num(d, "first"), num(d, "last")
tm := d["time"].(map[string]any)
if ad, span := num(tm, "active_days"), num(tm, "span_days"); ad < 1 || ad > span || span != float64(int((last-first)/86400)+1) {
t.Errorf("%s: active_days %v span_days %v first %v last %v", top, ad, span, first, last)
}
ssh := d["ssh"].(map[string]any)
if num(ssh, "fails") != num(counts, "ssh-fail") {
t.Errorf("%s: ssh.fails %v vs counter %v", top, ssh["fails"], counts["ssh-fail"])
}
if num(counts, "ssh-fail") > 0 && len(ssh["users"].([]any)) == 0 && num(d, "events") == 0 {
t.Errorf("%s: ssh failures but no users", top)
}
if jails, _ := d["jails"].([]any); len(jails) > 0 {
active := 0
for _, b := range d["bans"].([]any) {
if b.(map[string]any)["active"] == true {
active++
}
}
if active != len(jails) {
t.Errorf("%s: %d active bans for %d jails: %v", top, active, len(jails), d["bans"])
}
}
if len(d["sessions"].([]any)) == 0 {
t.Errorf("%s: no sessions for an address with %v events", top, counts)
}
if len(d["techniques"].([]any)) == 0 || len(d["families"].([]any)) == 0 {
t.Errorf("%s: techniques/families empty: %v / %v", top, d["techniques"], d["families"])
}
if len(d["events"].([]any)) == 0 {
t.Errorf("%s: events empty", top)
}
tl := d["timeline"].(map[string]any)
total, buckets := sum(tl["series"].(map[string]any))
if total == 0 {
t.Errorf("%s: timeline is empty", top)
}
if wantEvents {
if d["timeline_source"] != "events" || d["sessions_source"] != "events" || d["events_source"] != "events" {
t.Errorf("%s: sources %v %v %v", top, d["timeline_source"], d["sessions_source"], d["events_source"])
}
lg := d["log"].(map[string]any)
logEvents, n := num(lg, "events"), num(lg, "sessions_events")
if n != logEvents || total != logEvents || num(tm, "sessions_n") != num(lg, "sessions_n") {
t.Errorf("%s: sessions %v timeline %v log %v must agree", top, n, total, logEvents)
}
if tm["active_days"].(float64) > 1 && buckets < 2 {
t.Errorf("%s: timeline in %d bucket(s) for %v active days", top, buckets, tm["active_days"])
}
// the timeline sits at the hours of the events, not at the time of the ingestion
step, start := num(tl, "step"), num(tl, "start")
for i, v := range tl["series"].(map[string]any)["scanner"].([]any) {
if v.(float64) > 0 {
if at := start + float64(i)*step; at < first-3600 || at > last+3600 {
t.Errorf("%s: bar at %v outside [%v, %v]", top, at, first, last)
}
}
}
} else if d["sessions_source"] != "counters" || d["events_source"] != "counters" {
t.Errorf("%s: without a registry the sections must say counters: %v %v", top, d["sessions_source"], d["events_source"])
}
// a snapshot restored next to an empty registry (events before the registry existed)
if wantEvents {
p := filepath.Join(t.TempDir(), "s.gob")
if err := st.Save(p, nil); err != nil {
t.Fatal(err)
}
st2 := newLogged(t)
if _, err := st2.Load(p); err != nil {
t.Fatal(err)
}
checkConsistent(t, st2, false)
}
}
func TestIPDetailConsistentOnSyntheticLogs(t *testing.T) {
dirs := map[string]string{"ui-shell": scratch + "/ui-shell/logs", "demo": scratch + "/demo/logs"}
ran := 0
for name, dir := range dirs {
if _, err := os.Stat(filepath.Join(dir, "access.log")); err != nil {
continue
}
ran++
t.Run(name, func(t *testing.T) {
st := newLogged(t)
ingestLogs(t, st, dir)
checkConsistent(t, st, true)
})
}
if ran == 0 {
t.Skip("synthetic data sets not available")
}
}
+1 -1
View File
@@ -2,4 +2,4 @@ package app
// Version is the release version (SemVer). Release builds may override it with
// -ldflags "-X .../internal/app.Version=...".
var Version = "1.1.1"
var Version = "1.2.0"