Skip to content

Commit

Permalink
feat(localdns): log request information for failed local queries
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 31, 2024
1 parent 6233499 commit 1593121
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/middlewares/localdns/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (h *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
for i, localExchange := range h.localExchanges {
response, err := localExchange(h.ctx, r)
if err != nil {
h.logger.Debug(err.Error())
requestString := fmt.Sprintf("%s %s %s",
dns.ClassToString[r.Question[0].Qclass],
dns.TypeToString[r.Question[0].Qtype],
r.Question[0].Name)
h.logger.Debug("for " + requestString + ": " + err.Error())
continue
}

Expand Down
16 changes: 11 additions & 5 deletions pkg/middlewares/localdns/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ func Test_handler_ServeDNS(t *testing.T) {
"local_name_exchange_error": {
request: &dns.Msg{
Question: []dns.Question{{
Name: "domain.local.",
Qclass: dns.ClassINET,
Qtype: dns.TypeA,
Name: "domain.local.",
}},
},
makeHandler: func(ctrl *gomock.Controller) *handler {
logger := NewMockLogger(ctrl)
logger.EXPECT().Debug("test error")
logger.EXPECT().Debug("for IN A domain.local.: test error")

localExchanges := []server.Exchange{
makeTestExchange(nil, errTest),
Expand All @@ -207,7 +209,9 @@ func Test_handler_ServeDNS(t *testing.T) {
Rcode: dns.RcodeNameError,
},
Question: []dns.Question{{
Name: "domain.local.",
Qclass: dns.ClassINET,
Qtype: dns.TypeA,
Name: "domain.local.",
}},
},
},
Expand Down Expand Up @@ -284,7 +288,9 @@ func Test_handler_ServeDNS(t *testing.T) {
"local_name_success_after_failures": {
request: &dns.Msg{
Question: []dns.Question{{
Name: "domain.local.",
Qclass: dns.ClassINET,
Qtype: dns.TypeA,
Name: "domain.local.",
}},
},
makeHandler: func(ctrl *gomock.Controller) *handler {
Expand All @@ -307,7 +313,7 @@ func Test_handler_ServeDNS(t *testing.T) {
}

logger := NewMockLogger(ctrl)
logger.EXPECT().Debug("test error")
logger.EXPECT().Debug("for IN A domain.local.: test error")
logger.EXPECT().Debug("response received for " +
"domain.local. from 10.0.0.2:53 has " +
"rcode REFUSED")
Expand Down

0 comments on commit 1593121

Please sign in to comment.