From aaf2f3c91f77dcb6519c67fcaad9025180365bd2 Mon Sep 17 00:00:00 2001
From: Denis Machard <5562930+dmachard@users.noreply.github.com>
Date: Wed, 5 Jun 2024 21:06:56 +0200
Subject: [PATCH] fix regression on ingestor with dnstap files (#732)
* fix #729
* Update README.md
---
README.md | 4 +-
tests/testsdata/dnstap/dnstap.fstrm | Bin 0 -> 288 bytes
workers/file_ingestor.go | 2 +-
workers/file_ingestor_test.go | 62 +++++++++++++++++++---------
4 files changed, 45 insertions(+), 23 deletions(-)
create mode 100644 tests/testsdata/dnstap/dnstap.fstrm
diff --git a/README.md b/README.md
index 586d4882..71ad2fa0 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
-
+
-
+
diff --git a/tests/testsdata/dnstap/dnstap.fstrm b/tests/testsdata/dnstap/dnstap.fstrm
new file mode 100644
index 0000000000000000000000000000000000000000..4e848421fa368a387013d41fed013ccf625b6760
GIT binary patch
literal 288
zcmZQz00Si;$pplVKrB{JlwXpcRGMa$l2=@kSfJ+urhqc}TZ%LS2_Wx-0N7d(g9V700fKBjyZ`_I
literal 0
HcmV?d00001
diff --git a/workers/file_ingestor.go b/workers/file_ingestor.go
index 0db8b2dc..d524be6c 100644
--- a/workers/file_ingestor.go
+++ b/workers/file_ingestor.go
@@ -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
diff --git a/workers/file_ingestor_test.go b/workers/file_ingestor_test.go
index ed9972da..6ba7dcc1 100644
--- a/workers/file_ingestor_test.go
+++ b/workers/file_ingestor_test.go
@@ -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
+ }
+ }
+ })
}
}