aboutsummaryrefslogtreecommitdiff
path: root/plugin/metrics/recorder.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/metrics/recorder.go')
-rw-r--r--plugin/metrics/recorder.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/plugin/metrics/recorder.go b/plugin/metrics/recorder.go
new file mode 100644
index 000000000..a37f420d5
--- /dev/null
+++ b/plugin/metrics/recorder.go
@@ -0,0 +1,30 @@
+package metrics
+
+import (
+ "runtime"
+
+ "github.com/coredns/coredns/plugin/pkg/dnstest"
+
+ "github.com/miekg/dns"
+)
+
+// Recorder is a dnstest.Recorder specific to the metrics plugin.
+type Recorder struct {
+ *dnstest.Recorder
+ // CallerN holds the string return value of the call to runtime.Caller(N+1)
+ Caller [3]string
+}
+
+// NewRecorder makes and returns a new Recorder.
+func NewRecorder(w dns.ResponseWriter) *Recorder { return &Recorder{Recorder: dnstest.NewRecorder(w)} }
+
+// WriteMsg records the status code and calls the
+// underlying ResponseWriter's WriteMsg method.
+func (r *Recorder) WriteMsg(res *dns.Msg) error {
+ _, r.Caller[0], _, _ = runtime.Caller(1)
+ _, r.Caller[1], _, _ = runtime.Caller(2)
+ _, r.Caller[2], _, _ = runtime.Caller(3)
+ r.Len += res.Len()
+ r.Msg = res
+ return r.ResponseWriter.WriteMsg(res)
+}