mirror of
https://github.com/coredns/coredns.git
synced 2025-11-13 15:32:24 -05:00
@@ -33,7 +33,7 @@ func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
|||||||
// see https://github.com/coredns/coredns/blob/master/core/dnsserver/server.go#L318
|
// see https://github.com/coredns/coredns/blob/master/core/dnsserver/server.go#L318
|
||||||
rc = status
|
rc = status
|
||||||
}
|
}
|
||||||
plugin := m.authoritativePlugin(rw.Caller1, rw.Caller2, rw.Caller3)
|
plugin := m.authoritativePlugin(rw.Caller)
|
||||||
vars.Report(WithServer(ctx), state, zone, rcode.ToString(rc), plugin, rw.Len, rw.Start)
|
vars.Report(WithServer(ctx), state, zone, rcode.ToString(rc), plugin, rw.Len, rw.Start)
|
||||||
|
|
||||||
return status, err
|
return status, err
|
||||||
@@ -43,22 +43,16 @@ func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
|||||||
func (m *Metrics) Name() string { return "prometheus" }
|
func (m *Metrics) Name() string { return "prometheus" }
|
||||||
|
|
||||||
// authoritativePlugin returns which of made the write, if none is found the empty string is returned.
|
// authoritativePlugin returns which of made the write, if none is found the empty string is returned.
|
||||||
func (m *Metrics) authoritativePlugin(a, b, c string) string {
|
func (m *Metrics) authoritativePlugin(caller [3]string) string {
|
||||||
// a b and c contain the full path of the caller, the plugin name 2nd last elements
|
// a b and c contain the full path of the caller, the plugin name 2nd last elements
|
||||||
// .../coredns/plugin/whoami/whoami.go --> whoami
|
// .../coredns/plugin/whoami/whoami.go --> whoami
|
||||||
// this is likely FS specific, so use filepath.
|
// this is likely FS specific, so use filepath.
|
||||||
plug := filepath.Base(filepath.Dir(a))
|
for _, c := range caller {
|
||||||
if _, ok := m.plugins[plug]; ok {
|
plug := filepath.Base(filepath.Dir(c))
|
||||||
return plug
|
if _, ok := m.plugins[plug]; ok {
|
||||||
}
|
return plug
|
||||||
plug = filepath.Base(filepath.Dir(b))
|
}
|
||||||
if _, ok := m.plugins[plug]; ok {
|
|
||||||
return plug
|
|
||||||
}
|
|
||||||
plug = filepath.Base(filepath.Dir(c))
|
|
||||||
if _, ok := m.plugins[plug]; ok {
|
|
||||||
return plug
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ import (
|
|||||||
// Recorder is a dnstest.Recorder specific to the metrics plugin.
|
// Recorder is a dnstest.Recorder specific to the metrics plugin.
|
||||||
type Recorder struct {
|
type Recorder struct {
|
||||||
*dnstest.Recorder
|
*dnstest.Recorder
|
||||||
// CallerN holds the string return value of the call to runtime.Caller(N)
|
// CallerN holds the string return value of the call to runtime.Caller(N+1)
|
||||||
Caller1 string
|
Caller [3]string
|
||||||
Caller2 string
|
|
||||||
Caller3 string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRecorder makes and returns a new Recorder.
|
// NewRecorder makes and returns a new Recorder.
|
||||||
@@ -22,9 +20,9 @@ func NewRecorder(w dns.ResponseWriter) *Recorder { return &Recorder{Recorder: dn
|
|||||||
// WriteMsg records the status code and calls the
|
// WriteMsg records the status code and calls the
|
||||||
// underlying ResponseWriter's WriteMsg method.
|
// underlying ResponseWriter's WriteMsg method.
|
||||||
func (r *Recorder) WriteMsg(res *dns.Msg) error {
|
func (r *Recorder) WriteMsg(res *dns.Msg) error {
|
||||||
_, r.Caller1, _, _ = runtime.Caller(1)
|
_, r.Caller[0], _, _ = runtime.Caller(1)
|
||||||
_, r.Caller2, _, _ = runtime.Caller(2)
|
_, r.Caller[1], _, _ = runtime.Caller(2)
|
||||||
_, r.Caller3, _, _ = runtime.Caller(3)
|
_, r.Caller[2], _, _ = runtime.Caller(3)
|
||||||
r.Len += res.Len()
|
r.Len += res.Len()
|
||||||
r.Msg = res
|
r.Msg = res
|
||||||
return r.ResponseWriter.WriteMsg(res)
|
return r.ResponseWriter.WriteMsg(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user