mirror of
https://github.com/coredns/coredns.git
synced 2025-12-31 06:00:28 -05:00
Remove expensive runtime.Caller calls from metrics Recorder.WriteMsg by tracking the responding plugin through the plugin chain instead. - Add PluginTracker interface and pluginWriter wrapper in plugin.go - Modify NextOrFailure to wrap ResponseWriter with plugin name - Update metrics Recorder to implement PluginTracker - Remove authoritativePlugin method using filepath inspection Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
35 lines
958 B
Go
35 lines
958 B
Go
package metrics
|
|
|
|
import (
|
|
"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
|
|
// Plugin holds the name of the plugin that wrote the response.
|
|
// This is set automatically by the plugin chain via the PluginTracker interface.
|
|
Plugin 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 {
|
|
return r.Recorder.WriteMsg(res)
|
|
}
|
|
|
|
// SetPlugin implements the plugin.PluginTracker interface.
|
|
func (r *Recorder) SetPlugin(name string) {
|
|
r.Plugin = name
|
|
}
|
|
|
|
// GetPlugin implements the plugin.PluginTracker interface.
|
|
func (r *Recorder) GetPlugin() string {
|
|
return r.Plugin
|
|
}
|