mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
middleware/httpproxy: add debug queries (#446)
* middleware/httproxy: implement debug queries Not too useful at the moment, but o-o.debug queries are supported and return the Comment from dns.google.com. Note that this is not always set. * improve documentation * Testing cleanups
This commit is contained in:
@@ -37,7 +37,7 @@ etcd [ZONES...] {
|
||||
* **ENDPOINT** the etcd endpoints. Defaults to "http://localhost:2397".
|
||||
* `upstream` upstream resolvers to be used resolve external names found in etcd (think CNAMEs)
|
||||
pointing to external names. If you want CoreDNS to act as a proxy for clients, you'll need to add
|
||||
the proxy middleware. **ADDRESS* can be an IP address, and IP:port or a string pointing to a file
|
||||
the proxy middleware. **ADDRESS** can be an IP address, and IP:port or a string pointing to a file
|
||||
that is structured as /etc/resolv.conf.
|
||||
* `tls` followed the cert, key and the CA's cert filenames.
|
||||
* `debug` allows for debug queries. Prefix the name with `o-o.debug.` to retrieve extra information in the
|
||||
@@ -127,7 +127,7 @@ Or with *debug* queries enabled:
|
||||
When debug queries are enabled CoreDNS will return errors and etcd records encountered during the resolution
|
||||
process in the response. The general form looks like this:
|
||||
|
||||
skydns.test.skydns.dom.a. 300 CH TXT "127.0.0.1:0(10,0,,false)[0,]"
|
||||
skydns.test.skydns.dom.a. 0 CH TXT "127.0.0.1:0(10,0,,false)[0,]"
|
||||
|
||||
This shows the complete key as the owername, the rdata of the TXT record has:
|
||||
`host:port(priority,weight,txt content,mail)[targetstrip,group]`.
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package etcd
|
||||
|
||||
import "strings"
|
||||
|
||||
const debugName = "o-o.debug."
|
||||
|
||||
// isDebug checks if name is a debugging name, i.e. starts with o-o.debug.
|
||||
// it return the empty string if it is not a debug message, otherwise it will return the
|
||||
// name with o-o.debug. stripped off. Must be called with name lowercased.
|
||||
func isDebug(name string) string {
|
||||
if len(name) == len(debugName) {
|
||||
return ""
|
||||
}
|
||||
name = strings.ToLower(name)
|
||||
debug := strings.HasPrefix(name, debugName)
|
||||
if !debug {
|
||||
return ""
|
||||
}
|
||||
return name[len(debugName):]
|
||||
}
|
||||
@@ -4,7 +4,6 @@ package etcd
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/coredns/middleware/etcd/msg"
|
||||
@@ -14,21 +13,6 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func TestIsDebug(t *testing.T) {
|
||||
if ok := isDebug("o-o.debug.miek.nl."); ok != "miek.nl." {
|
||||
t.Errorf("expected o-o.debug.miek.nl. to be debug")
|
||||
}
|
||||
if ok := isDebug(strings.ToLower("o-o.Debug.miek.nl.")); ok != "miek.nl." {
|
||||
t.Errorf("expected o-o.Debug.miek.nl. to be debug")
|
||||
}
|
||||
if ok := isDebug("i-o.debug.miek.nl."); ok != "" {
|
||||
t.Errorf("expected i-o.Debug.miek.nl. to be non-debug")
|
||||
}
|
||||
if ok := isDebug(strings.ToLower("i-o.Debug.")); ok != "" {
|
||||
t.Errorf("expected o-o.Debug. to be non-debug")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebugLookup(t *testing.T) {
|
||||
etc := newEtcdMiddleware()
|
||||
etc.Debugging = true
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/coredns/middleware/etcd/msg"
|
||||
"github.com/miekg/coredns/middleware/pkg/debug"
|
||||
"github.com/miekg/coredns/middleware/pkg/dnsutil"
|
||||
"github.com/miekg/coredns/request"
|
||||
|
||||
@@ -21,10 +22,10 @@ func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
||||
}
|
||||
name := state.Name()
|
||||
if e.Debugging {
|
||||
if debug := isDebug(name); debug != "" {
|
||||
if bug := debug.IsDebug(name); bug != "" {
|
||||
opt.Debug = r.Question[0].Name
|
||||
state.Clear()
|
||||
state.Req.Question[0].Name = debug
|
||||
state.Req.Question[0].Name = bug
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user