mirror of
https://github.com/coredns/coredns.git
synced 2025-11-07 12:36:20 -05:00
middleware/proxy: dnstap (#786)
* experimental dnstap support into proxy * proxy reports dnstap errors * refactoring * add a message builder for less dnstap code * msg lint * context * proxy by DNS: dnstap comments * TapBuilder * resolves conflict * dnstap into ServeDNS * testing * more tests * `go lint` * doc update
This commit is contained in:
@@ -7,11 +7,18 @@ import (
|
||||
"github.com/coredns/coredns/middleware/dnstap/msg"
|
||||
|
||||
tap "github.com/dnstap/golang-dnstap"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Context is a message trap.
|
||||
type Context struct {
|
||||
context.Context
|
||||
TrapTapper
|
||||
}
|
||||
|
||||
// TestingData returns the Data matching coredns/test.ResponseWriter.
|
||||
func TestingData() (d *msg.Data) {
|
||||
d = &msg.Data{
|
||||
Type: tap.Message_CLIENT_RESPONSE,
|
||||
SocketFam: tap.SocketFamily_INET,
|
||||
SocketProto: tap.SocketProtocol_UDP,
|
||||
Address: net.ParseIP("10.240.0.1"),
|
||||
@@ -50,15 +57,24 @@ func toComp(m *tap.Message) comp {
|
||||
}
|
||||
}
|
||||
|
||||
// MsgEqual compares two dnstap messages ignoring timestamps.
|
||||
func MsgEqual(a, b *tap.Message) bool {
|
||||
return reflect.DeepEqual(toComp(a), toComp(b))
|
||||
}
|
||||
|
||||
type TrapTaper struct {
|
||||
// TrapTapper traps messages.
|
||||
type TrapTapper struct {
|
||||
Trap []*tap.Message
|
||||
Full bool
|
||||
}
|
||||
|
||||
func (t *TrapTaper) TapMessage(m *tap.Message) error {
|
||||
// TapMessage adds the message to the trap.
|
||||
func (t *TrapTapper) TapMessage(m *tap.Message) error {
|
||||
t.Trap = append(t.Trap, m)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TapBuilder returns a test msg.Builder.
|
||||
func (t *TrapTapper) TapBuilder() msg.Builder {
|
||||
return msg.Builder{Full: t.Full}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user