refactor: remove unused code and fix documentation
- Remove CorrelationKeyFull() alias, use CorrelationKey() everywhere - Remove duplicate TimeProvider interface from ports/source.go - Remove unused time import from ports/source.go - Update README.md: replace ./build.sh and ./test.sh with make commands - Update RPM package names in README to match current version (1.0.3) Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
17
README.md
17
README.md
@ -32,10 +32,10 @@ Tout le build et les tests s'exécutent dans des containers Docker :
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build complet (binaire + tests + RPM)
|
# Build complet (binaire + tests + RPM)
|
||||||
./build.sh
|
make package-rpm
|
||||||
|
|
||||||
# Uniquement les tests
|
# Uniquement les tests
|
||||||
./test.sh
|
make test
|
||||||
|
|
||||||
# Build manuel avec Docker
|
# Build manuel avec Docker
|
||||||
docker build --target builder -t logcorrelator-builder .
|
docker build --target builder -t logcorrelator-builder .
|
||||||
@ -53,7 +53,7 @@ docker build --target runtime -t logcorrelator:latest .
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build de l'image
|
# Build de l'image
|
||||||
./build.sh
|
docker build --target runtime -t logcorrelator:latest .
|
||||||
|
|
||||||
# Exécuter
|
# Exécuter
|
||||||
docker run -d \
|
docker run -d \
|
||||||
@ -68,15 +68,12 @@ docker run -d \
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Générer les packages
|
# Générer les packages
|
||||||
./build.sh
|
make package-rpm
|
||||||
|
|
||||||
# Installer le package RPM (CentOS 7)
|
|
||||||
sudo yum install -y dist/rpm/centos7/logcorrelator-1.0.0-1.el7.x86_64.rpm
|
|
||||||
|
|
||||||
# Installer le package RPM (Rocky Linux 8/9/10)
|
# Installer le package RPM (Rocky Linux 8/9/10)
|
||||||
sudo dnf install -y dist/rpm/rocky8/logcorrelator-1.0.0-1.el8.x86_64.rpm
|
sudo dnf install -y dist/rpm/rocky8/logcorrelator-1.0.3-1.el8.x86_64.rpm
|
||||||
sudo dnf install -y dist/rpm/rocky9/logcorrelator-1.0.0-1.el9.x86_64.rpm
|
sudo dnf install -y dist/rpm/rocky9/logcorrelator-1.0.3-1.el9.x86_64.rpm
|
||||||
sudo dnf install -y dist/rpm/rocky10/logcorrelator-1.0.0-1.el10.x86_64.rpm
|
sudo dnf install -y dist/rpm/almalinux10/logcorrelator-1.0.3-1.el10.x86_64.rpm
|
||||||
|
|
||||||
# Activer et démarrer le service
|
# Activer et démarrer le service
|
||||||
sudo systemctl enable logcorrelator
|
sudo systemctl enable logcorrelator
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNormalizedEvent_CorrelationKeyFull(t *testing.T) {
|
func TestNormalizedEvent_CorrelationKey(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
event *NormalizedEvent
|
event *NormalizedEvent
|
||||||
@ -39,7 +39,7 @@ func TestNormalizedEvent_CorrelationKeyFull(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
key := tt.event.CorrelationKeyFull()
|
key := tt.event.CorrelationKey()
|
||||||
if key != tt.expected {
|
if key != tt.expected {
|
||||||
t.Errorf("expected %s, got %s", tt.expected, key)
|
t.Errorf("expected %s, got %s", tt.expected, key)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,7 +128,7 @@ func (s *CorrelationService) isBufferFull(source EventSource) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *CorrelationService) processSourceA(event *NormalizedEvent) ([]CorrelatedLog, bool) {
|
func (s *CorrelationService) processSourceA(event *NormalizedEvent) ([]CorrelatedLog, bool) {
|
||||||
key := event.CorrelationKeyFull()
|
key := event.CorrelationKey()
|
||||||
|
|
||||||
// Look for the first matching B event (one-to-one first match)
|
// Look for the first matching B event (one-to-one first match)
|
||||||
if bEvent := s.findAndPopFirstMatch(s.bufferB, s.pendingB, key, func(other *NormalizedEvent) bool {
|
if bEvent := s.findAndPopFirstMatch(s.bufferB, s.pendingB, key, func(other *NormalizedEvent) bool {
|
||||||
@ -149,7 +149,7 @@ func (s *CorrelationService) processSourceA(event *NormalizedEvent) ([]Correlate
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *CorrelationService) processSourceB(event *NormalizedEvent) ([]CorrelatedLog, bool) {
|
func (s *CorrelationService) processSourceB(event *NormalizedEvent) ([]CorrelatedLog, bool) {
|
||||||
key := event.CorrelationKeyFull()
|
key := event.CorrelationKey()
|
||||||
|
|
||||||
// Look for the first matching A event (one-to-one first match)
|
// Look for the first matching A event (one-to-one first match)
|
||||||
if aEvent := s.findAndPopFirstMatch(s.bufferA, s.pendingA, key, func(other *NormalizedEvent) bool {
|
if aEvent := s.findAndPopFirstMatch(s.bufferA, s.pendingA, key, func(other *NormalizedEvent) bool {
|
||||||
@ -178,7 +178,7 @@ func (s *CorrelationService) eventsMatch(a, b *NormalizedEvent) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *CorrelationService) addEvent(event *NormalizedEvent) {
|
func (s *CorrelationService) addEvent(event *NormalizedEvent) {
|
||||||
key := event.CorrelationKeyFull()
|
key := event.CorrelationKey()
|
||||||
|
|
||||||
switch event.Source {
|
switch event.Source {
|
||||||
case SourceA:
|
case SourceA:
|
||||||
@ -205,7 +205,7 @@ func (s *CorrelationService) cleanBuffer(buffer *eventBuffer, pending map[string
|
|||||||
event := elem.Value.(*NormalizedEvent)
|
event := elem.Value.(*NormalizedEvent)
|
||||||
if event.Timestamp.Before(cutoff) {
|
if event.Timestamp.Before(cutoff) {
|
||||||
next := elem.Next()
|
next := elem.Next()
|
||||||
key := event.CorrelationKeyFull()
|
key := event.CorrelationKey()
|
||||||
buffer.events.Remove(elem)
|
buffer.events.Remove(elem)
|
||||||
pending[key] = removeElementFromSlice(pending[key], elem)
|
pending[key] = removeElementFromSlice(pending[key], elem)
|
||||||
if len(pending[key]) == 0 {
|
if len(pending[key]) == 0 {
|
||||||
|
|||||||
@ -30,8 +30,3 @@ type NormalizedEvent struct {
|
|||||||
func (e *NormalizedEvent) CorrelationKey() string {
|
func (e *NormalizedEvent) CorrelationKey() string {
|
||||||
return e.SrcIP + ":" + strconv.Itoa(e.SrcPort)
|
return e.SrcIP + ":" + strconv.Itoa(e.SrcPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CorrelationKeyFull returns a proper correlation key (alias for clarity).
|
|
||||||
func (e *NormalizedEvent) CorrelationKeyFull() string {
|
|
||||||
return e.CorrelationKey()
|
|
||||||
}
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package ports
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/logcorrelator/logcorrelator/internal/domain"
|
"github.com/logcorrelator/logcorrelator/internal/domain"
|
||||||
)
|
)
|
||||||
@ -35,11 +34,6 @@ type CorrelatedLogSink interface {
|
|||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeProvider abstracts time for testability.
|
|
||||||
type TimeProvider interface {
|
|
||||||
Now() time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// CorrelationProcessor defines the interface for the correlation service.
|
// CorrelationProcessor defines the interface for the correlation service.
|
||||||
// This allows for easier testing and alternative implementations.
|
// This allows for easier testing and alternative implementations.
|
||||||
type CorrelationProcessor interface {
|
type CorrelationProcessor interface {
|
||||||
|
|||||||
Reference in New Issue
Block a user