Skip to content

Commit

Permalink
fix regression on ingestor with dnstap files (#732)
Browse files Browse the repository at this point in the history
* fix #729
* Update README.md
  • Loading branch information
dmachard authored Jun 5, 2024
1 parent 1d93805 commit aaf2f3c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<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.21-green" alt="Go version"/>
<img src="https://img.shields.io/badge/go%20tests-426-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20tests-436-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20bench-20-green" alt="Go bench"/>
<img src="https://img.shields.io/badge/go%20lines-29697-green" alt="Go lines"/>
<img src="https://img.shields.io/badge/go%20lines-29834-green" alt="Go lines"/>
</p>

<p align="center">
Expand Down
Binary file added tests/testsdata/dnstap/dnstap.fstrm
Binary file not shown.
2 changes: 1 addition & 1 deletion workers/file_ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (w *FileIngestor) StartCollect() {
dnstapProcessor := NewDNSTapProcessor(0, "", w.GetConfig(), w.GetLogger(), w.GetName(), w.GetConfig().Collectors.FileIngestor.ChannelBufferSize)
dnstapProcessor.SetDefaultRoutes(w.GetDefaultRoutes())
dnstapProcessor.SetDefaultDropped(w.GetDroppedRoutes())
go dnsProcessor.StartCollect()
go dnstapProcessor.StartCollect()

w.dnstapProcessor = dnstapProcessor
w.dnsProcessor = dnsProcessor
Expand Down
62 changes: 42 additions & 20 deletions workers/file_ingestor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,47 @@ import (
"github.com/dmachard/go-logger"
)

func Test_FileIngestor_Pcap(t *testing.T) {
g := GetWorkerForTest(pkgconfig.DefaultBufferSize)
config := pkgconfig.GetDefaultConfig()

// watch tests data folder
config.Collectors.FileIngestor.WatchDir = "./../tests/testsdata/pcap/"

// init collector
c := NewFileIngestor([]Worker{g}, config, logger.New(false), "test")
go c.StartCollect()

// waiting message in channel
for {
// read dns message from channel
msg := <-g.GetInputChannel()

// check qname
if msg.DNSTap.Operation == dnsutils.DNSTapClientQuery {
break
}
func Test_FileIngestor(t *testing.T) {
tests := []struct {
name string
watchMode string
watchDir string
}{
{
name: "Pcap",
watchMode: "pcap",
watchDir: "./../tests/testsdata/pcap/",
},
{
name: "Dnstap",
watchMode: "dnstap",
watchDir: "./../tests/testsdata/dnstap/",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := GetWorkerForTest(pkgconfig.DefaultBufferSize)
config := pkgconfig.GetDefaultConfig()

// watch tests data folder
config.Collectors.FileIngestor.WatchMode = tt.watchMode
config.Collectors.FileIngestor.WatchDir = tt.watchDir

// init collector
c := NewFileIngestor([]Worker{g}, config, logger.New(false), "test")
go c.StartCollect()

// waiting message in channel
for {
// read dns message from channel
msg := <-g.GetInputChannel()

// check qname
if msg.DNSTap.Operation == dnsutils.DNSTapClientQuery {
break
}
}
})
}
}

0 comments on commit aaf2f3c

Please sign in to comment.