mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 02:03:13 -05:00
plugin/dnstap: don't spam Travis + valid dnstap payload (#1121)
* don't spam Travis + valid dnstap payload
* log instead of fmt
* Revert "log instead of fmt"
This reverts commit 88f09c3939.
* log the right way
* log the final way
* minor enhancements
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package dnstapio
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
tap "github.com/dnstap/golang-dnstap"
|
||||
"github.com/golang/protobuf/proto"
|
||||
@@ -10,9 +9,9 @@ import (
|
||||
|
||||
// DnstapIO wraps the dnstap I/O routine.
|
||||
type DnstapIO struct {
|
||||
writer io.WriteCloser
|
||||
queue chan tap.Dnstap
|
||||
stop chan bool
|
||||
protocol Protocol
|
||||
queue chan tap.Dnstap
|
||||
stop chan bool
|
||||
}
|
||||
|
||||
// Protocol is either `out.TCP` or `out.Socket`.
|
||||
@@ -26,7 +25,7 @@ type Protocol interface {
|
||||
// New dnstap I/O routine from Protocol.
|
||||
func New(w Protocol) *DnstapIO {
|
||||
dio := DnstapIO{}
|
||||
dio.writer = w
|
||||
dio.protocol = w
|
||||
dio.queue = make(chan tap.Dnstap, 10)
|
||||
dio.stop = make(chan bool)
|
||||
go dio.serve()
|
||||
@@ -38,7 +37,7 @@ func (dio *DnstapIO) Dnstap(payload tap.Dnstap) {
|
||||
select {
|
||||
case dio.queue <- payload:
|
||||
default:
|
||||
fmt.Println("[WARN] Dnstap payload dropped.")
|
||||
log.Println("[WARN] Dnstap payload dropped.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +47,9 @@ func (dio *DnstapIO) serve() {
|
||||
case payload := <-dio.queue:
|
||||
frame, err := proto.Marshal(&payload)
|
||||
if err == nil {
|
||||
dio.writer.Write(frame)
|
||||
dio.protocol.Write(frame)
|
||||
} else {
|
||||
fmt.Println("[ERROR] Invalid dnstap payload dropped.")
|
||||
log.Printf("[ERROR] Invalid dnstap payload dropped: %s\n", err)
|
||||
}
|
||||
case <-dio.stop:
|
||||
close(dio.queue)
|
||||
@@ -65,5 +64,5 @@ func (dio DnstapIO) Close() error {
|
||||
dio.stop <- true
|
||||
<-dio.stop
|
||||
close(dio.stop)
|
||||
return dio.writer.Close()
|
||||
return dio.protocol.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user