Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kafka, redis, fluentd and tcpclient loggers: no flush occurred on specific conditions for on connection attempts #552

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center">
<img src="https://goreportcard.com/badge/github.com/dmachard/go-dns-collector" alt="Go Report"/>
<img src="https://img.shields.io/badge/go%20version-min%201.20-green" alt="Go version"/>
<img src="https://img.shields.io/badge/go%20tests-383-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20tests-384-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20lines-37290-green" alt="Go lines"/>
</p>

Expand Down
1 change: 0 additions & 1 deletion loggers/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ PROCESS_LOOP:
case <-flushTimer.C:
if !fc.writerReady {
bufferDm = nil
continue
}

if len(bufferDm) > 0 {
Expand Down
2 changes: 0 additions & 2 deletions loggers/kafkaproducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@ PROCESS_LOOP:
// flush the buffer
case <-flushTimer.C:
if !k.kafkaConnected {
k.LogInfo("buffer cleared!")
bufferDm = nil
continue
}

if len(bufferDm) > 0 {
Expand Down
2 changes: 0 additions & 2 deletions loggers/redispub.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ PROCESS_LOOP:
// flush the buffer
case <-flushTimer.C:
if !c.writerReady {
c.LogInfo("Buffer cleared!")
bufferDm = nil
continue
}

if len(bufferDm) > 0 {
Expand Down
2 changes: 0 additions & 2 deletions loggers/tcpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ PROCESS_LOOP:
// flush the buffer
case <-flushTimer.C:
if !c.writerReady {
c.LogInfo("buffer cleared!")
bufferDm = nil
continue
}

if len(bufferDm) > 0 {
Expand Down
58 changes: 58 additions & 0 deletions loggers/tcpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,61 @@ func Test_TcpClientRun(t *testing.T) {
})
}
}

func Test_TcpClient_ConnectionAttempt(t *testing.T) {
// init logger
cfg := pkgconfig.GetFakeConfig()
cfg.Loggers.TCPClient.FlushInterval = 1
cfg.Loggers.TCPClient.Mode = pkgconfig.ModeText
cfg.Loggers.TCPClient.RemoteAddress = "127.0.0.1"
cfg.Loggers.TCPClient.RemotePort = 9999
cfg.Loggers.TCPClient.ConnectTimeout = 1
cfg.Loggers.TCPClient.RetryInterval = 2

g := NewTCPClient(cfg, logger.New(true), "test")

// start the logger
go g.Run()

// just way to get connect attempt
time.Sleep(time.Second * 3)

// start receiver
fakeRcvr, err := net.Listen(netlib.SocketTCP, ":9999")
if err != nil {
t.Fatal(err)
}
defer fakeRcvr.Close()

// accept conn from logger
conn, err := fakeRcvr.Accept()
if err != nil {
return
}
defer conn.Close()

// wait connection on logger
time.Sleep(time.Second)

// send fake dns message to logger
dm := dnsutils.GetFakeDNSMessage()
g.GetInputChannel() <- dm

// read data on server side and decode-it
reader := bufio.NewReader(conn)
line, err := reader.ReadString('\n')
if err != nil {
t.Error(err)
return
}

pattern := regexp.MustCompile("dns.collector")
if !pattern.MatchString(line) {
t.Errorf("tcp error want dns.collector, got: %s", line)
}

// stop all
fakeRcvr.Close()
g.Stop()

}
Loading