fix: renforcer corrélation A/B et sorties stdout/fichier
Some checks failed
Build and Test / test (push) Has been cancelled
Build and Test / build (push) Has been cancelled
Build and Test / docker (push) Has been cancelled

Co-authored-by: aider (openrouter/openai/gpt-5.3-codex) <aider@aider.chat>
This commit is contained in:
Jacquin Antoine
2026-03-01 12:10:17 +01:00
parent d3436f6245
commit 27c7659397
13 changed files with 441 additions and 259 deletions

View File

@ -12,10 +12,10 @@ import (
// Config holds the complete application configuration.
type Config struct {
Log LogConfig `yaml:"log"`
Inputs InputsConfig `yaml:"inputs"`
Outputs OutputsConfig `yaml:"outputs"`
Correlation CorrelationConfig `yaml:"correlation"`
Log LogConfig `yaml:"log"`
Inputs InputsConfig `yaml:"inputs"`
Outputs OutputsConfig `yaml:"outputs"`
Correlation CorrelationConfig `yaml:"correlation"`
}
// LogConfig holds logging configuration.
@ -44,10 +44,10 @@ type InputsConfig struct {
// UnixSocketConfig holds a Unix socket source configuration.
type UnixSocketConfig struct {
Name string `yaml:"name"`
Path string `yaml:"path"`
Format string `yaml:"format"`
SourceType string `yaml:"source_type"` // "A" for Apache/HTTP, "B" for Network
Name string `yaml:"name"`
Path string `yaml:"path"`
Format string `yaml:"format"`
SourceType string `yaml:"source_type"` // "A" for Apache/HTTP, "B" for Network
SocketPermissions string `yaml:"socket_permissions"` // octal string, e.g., "0660", "0666"
}
@ -55,7 +55,7 @@ type UnixSocketConfig struct {
type OutputsConfig struct {
File FileOutputConfig `yaml:"file"`
ClickHouse ClickHouseOutputConfig `yaml:"clickhouse"`
Stdout bool `yaml:"stdout"`
Stdout StdoutOutputConfig `yaml:"stdout"`
}
// FileOutputConfig holds file sink configuration.
@ -77,15 +77,14 @@ type ClickHouseOutputConfig struct {
}
// StdoutOutputConfig holds stdout sink configuration.
// Deprecated: stdout is now a boolean flag in OutputsConfig.
type StdoutOutputConfig struct {
Enabled bool `yaml:"enabled"`
}
// CorrelationConfig holds correlation configuration.
type CorrelationConfig struct {
TimeWindowS int `yaml:"time_window_s"`
EmitOrphans bool `yaml:"emit_orphans"`
TimeWindowS int `yaml:"time_window_s"`
EmitOrphans bool `yaml:"emit_orphans"`
}
// Load loads configuration from a YAML file.
@ -130,7 +129,7 @@ func defaultConfig() *Config {
AsyncInsert: true,
TimeoutMs: 1000,
},
Stdout: false,
Stdout: StdoutOutputConfig{Enabled: false},
},
Correlation: CorrelationConfig{
TimeWindowS: 1,
@ -175,7 +174,7 @@ func (c *Config) Validate() error {
if c.Outputs.ClickHouse.Enabled {
hasOutput = true
}
if c.Outputs.Stdout {
if c.Outputs.Stdout.Enabled {
hasOutput = true
}
@ -220,12 +219,13 @@ func (c *CorrelationConfig) GetTimeWindow() time.Duration {
// GetSocketPermissions returns the socket permissions as os.FileMode.
// Default is 0660 (owner + group read/write).
func (c *UnixSocketConfig) GetSocketPermissions() os.FileMode {
if c.SocketPermissions == "" {
trimmed := strings.TrimSpace(c.SocketPermissions)
if trimmed == "" {
return 0660
}
// Parse octal string (e.g., "0660", "660", "0666")
perms, err := strconv.ParseUint(strings.TrimPrefix(c.SocketPermissions, "0"), 8, 32)
perms, err := strconv.ParseUint(trimmed, 8, 32)
if err != nil {
return 0660
}

View File

@ -131,7 +131,7 @@ func TestValidate_AtLeastOneOutput(t *testing.T) {
Outputs: OutputsConfig{
File: FileOutputConfig{},
ClickHouse: ClickHouseOutputConfig{Enabled: false},
Stdout: false,
Stdout: StdoutOutputConfig{Enabled: false},
},
}
@ -554,3 +554,37 @@ correlation:
t.Errorf("expected log level DEBUG, got %s", cfg.Log.GetLevel())
}
}
func TestLoad_StdoutEnabledObject(t *testing.T) {
content := `
inputs:
unix_sockets:
- name: http
path: /var/run/logcorrelator/http.socket
- name: network
path: /var/run/logcorrelator/network.socket
outputs:
stdout:
enabled: true
correlation:
time_window_s: 1
emit_orphans: true
`
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config.yml")
if err := os.WriteFile(configPath, []byte(content), 0644); err != nil {
t.Fatalf("failed to write config: %v", err)
}
cfg, err := Load(configPath)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !cfg.Outputs.Stdout.Enabled {
t.Error("expected outputs.stdout.enabled to be true")
}
}