diff --git a/README.md b/README.md index b5dea20a..9110543c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
- +
diff --git a/workers/dnstapserver.go b/workers/dnstapserver.go index 5337dbbd..e11fac93 100644 --- a/workers/dnstapserver.go +++ b/workers/dnstapserver.go @@ -344,9 +344,6 @@ func (w *DNSTapProcessor) StartCollect() { continue } - // count global messages - w.CountIngressTraffic() - // init dns message dm := dnsutils.DNSMessage{} dm.Init() diff --git a/workers/dnstapserver_test.go b/workers/dnstapserver_test.go index 74c6ad70..756a9b62 100644 --- a/workers/dnstapserver_test.go +++ b/workers/dnstapserver_test.go @@ -11,6 +11,7 @@ import ( "github.com/dmachard/go-dnscollector/dnsutils" "github.com/dmachard/go-dnscollector/pkgconfig" + "github.com/dmachard/go-dnscollector/telemetry" "github.com/dmachard/go-dnstap-protobuf" "github.com/dmachard/go-framestream" "github.com/dmachard/go-logger" @@ -240,7 +241,7 @@ func Test_DnstapProcessor_toDNSMessage(t *testing.T) { } } -func Test_DnstapProcessor_DecodeCounters(t *testing.T) { +func Test_DnstapProcessor_DecodeDNSCounters(t *testing.T) { logger := logger.New(true) var o bytes.Buffer logger.SetOutput(&o) @@ -622,3 +623,54 @@ func Test_DnstapProcessor_BufferLoggerIsFull(t *testing.T) { t.Errorf("invalid qname in second dns message: %s", dm2.DNS.Qname) } } + +// test for telemetry counter +func Test_DnstapProcessor_TelemetryCounters(t *testing.T) { + logger := logger.New(true) + var o bytes.Buffer + logger.SetOutput(&o) + + // run the consumer with a fake logger + fl := GetWorkerForTest(pkgconfig.DefaultBufferSize) + + cfg := pkgconfig.GetDefaultConfig() + cfg.Global.Telemetry.Enabled = true + cfg.Global.Worker.InternalMonitor = 1 + + config := pkgconfig.Config{} + metrics := telemetry.NewPrometheusCollector(&config) + + // init the dnstap consumer + consumer := NewDNSTapProcessor(0, "peertest", cfg, logger, "test", 512) + consumer.SetMetrics(metrics) + consumer.AddDefaultRoute(fl) + consumer.AddDroppedRoute(fl) + + // get dns packet + queryPkt, _ := dnsutils.GetFakeDNS() + + // prepare dnstap + dt := &dnstap.Dnstap{} + dt.Type = dnstap.Dnstap_Type.Enum(1) + + dt.Message = &dnstap.Message{} + dt.Message.Type = dnstap.Message_Type.Enum(5) // CLIENT_QUERY + dt.Message.ResponseMessage = queryPkt + data, _ := proto.Marshal(dt) + + // start the consumer + go consumer.StartCollect() + + // add packet to consumer and read output + consumer.GetDataChannel() <- data + + <-fl.GetInputChannel() + r := <-metrics.Record + + if r.TotalIngress != 1 { + t.Errorf("invalid total ingress oucnter: got %d expect 1", r.TotalIngress) + } + if r.TotalEgress != 1 { + t.Errorf("invalid total egress counter: got %d expect 1", r.TotalEgress) + } +} diff --git a/workers/worker.go b/workers/worker.go index f793065d..b56a5754 100644 --- a/workers/worker.go +++ b/workers/worker.go @@ -232,7 +232,7 @@ func (w *GenericWorker) Monitor() { // // send to telemetry? if w.config.Global.Telemetry.Enabled && w.metrics != nil { - if w.totalIngress > 0 || w.totalForwarded > 0 || w.totalDropped > 0 { + if w.totalIngress > 0 || w.totalEgress > 0 || w.totalForwarded > 0 || w.totalDropped > 0 { w.metrics.Record <- telemetry.WorkerStats{ Name: w.GetName(), TotalIngress: w.totalIngress,