aboutsummaryrefslogtreecommitdiff
path: root/middleware/etcd/debug.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-05-22 21:16:26 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-05-22 21:16:26 +0100
commitc30671f4c03a41deccdcfa3f62a42be46bc0a401 (patch)
treef8936cd0174a4c6b8c1c7235d071fb8cb09bec93 /middleware/etcd/debug.go
parentd35394a8df3aa9d2b2bcf59101c093c03f4bd227 (diff)
downloadcoredns-c30671f4c03a41deccdcfa3f62a42be46bc0a401.tar.gz
coredns-c30671f4c03a41deccdcfa3f62a42be46bc0a401.tar.zst
coredns-c30671f4c03a41deccdcfa3f62a42be46bc0a401.zip
Allow debug queries to etcd middleware (#150)
With this you can retreive the raw data that the etcd middleware used to create the reply. The debug data is put in TXT records that are stuffed in the CH classs. This is only enabled if you specify `debug` in the etcd stanza. You can retrieve it by prefixing your query with 'o-o.debug.' For instance: ; <<>> DiG 9.10.3-P4-Ubuntu <<>> @localhost -p 1053 SRV o-o.debug.production.*.skydns.local ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47798 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 3 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;o-o.debug.production.*.skydns.local. IN SRV ;; ANSWER SECTION: production.*.skydns.local. 154 IN SRV 10 50 8080 service1.example.com. production.*.skydns.local. 154 IN SRV 10 50 8080 service2.example.com. ;; ADDITIONAL SECTION: skydns.local.skydns.east.production.rails.1. 154 CH TXT "service1.example.com:8080(10,0,,false)[0,]" skydns.local.skydns.west.production.rails.2. 154 CH TXT "service2.example.com:8080(10,0,,false)[0,]"
Diffstat (limited to 'middleware/etcd/debug.go')
-rw-r--r--middleware/etcd/debug.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/middleware/etcd/debug.go b/middleware/etcd/debug.go
new file mode 100644
index 000000000..b8ca3344f
--- /dev/null
+++ b/middleware/etcd/debug.go
@@ -0,0 +1,38 @@
+package etcd
+
+import (
+ "strings"
+
+ "github.com/miekg/coredns/middleware/etcd/msg"
+
+ "github.com/miekg/dns"
+)
+
+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.
+func isDebug(name string) string {
+ if len(name) == len(debugName) {
+ return ""
+ }
+ debug := strings.HasPrefix(name, debugName)
+ if !debug {
+ return ""
+ }
+ return name[len(debugName):]
+}
+
+// servicesToTxt puts debug in TXT RRs.
+func servicesToTxt(debug []msg.Service) []dns.RR {
+ if debug == nil {
+ return nil
+ }
+
+ rr := make([]dns.RR, len(debug))
+ for i, d := range debug {
+ rr[i] = d.RR()
+ }
+ return rr
+}