feat: implement drain3 based generic log-parser

This commit is contained in:
Patryk Hegenberg 2026-01-18 16:51:44 +01:00
parent 1d1568e3ee
commit 5af49f926a
17 changed files with 612 additions and 220 deletions

17
main.go
View file

@ -1,6 +1,7 @@
package main
import (
"codeberg.org/pata1704/drain3"
"context"
"log/slog"
"os"
@ -39,6 +40,18 @@ func main() {
}
slog.Info("Regex patterns loaded successfully", "file", cfg.PatternsFile)
var d3Cfg *drain3.Config
if cfg.Drain3.Enabled {
d3Cfg = &drain3.Config{
Depth: cfg.Drain3.Depth,
SimTh: cfg.Drain3.SimThreshold,
MaxChildren: cfg.Drain3.MaxChildren,
}
slog.Info("Drain3 anomaly detection enabled", "state_dir", cfg.Drain3.StateDir)
} else {
slog.Info("Drain3 anomaly detection disabled")
}
var storage StorageInterface
if cfg.LocalStorage.Enable {
rotationConfig := StorageRotationConfig{
@ -123,7 +136,7 @@ func main() {
helpers.SafeGo(ctx, "ServiceMonitor-"+srv.Name, func() {
defer wg.Done()
monitor := NewServiceMonitor(srv, currentHostname)
monitor := NewServiceMonitor(srv, currentHostname, d3Cfg, cfg.Drain3.StateDir)
if err := monitor.Start(ctx, logChan); err != nil {
slog.Error("Error watching service", "service", srv.Name, "error", err)
@ -145,7 +158,7 @@ func main() {
helpers.SafeGo(ctx, "FileMonitor-"+t.Name, func() {
defer wg.Done()
monitor := NewFileMonitor(t, currentHostname)
monitor := NewFileMonitor(t, currentHostname, d3Cfg, cfg.Drain3.StateDir)
if err := monitor.Start(ctx, logChan); err != nil {
slog.Error("Error watching tool", "tool", t.Name, "error", err)