Files
coredns/plugin/metrics/recorder.go
Ville Vesilehto be934b2b06 perf(metrics): implement plugin chain tracking (#7791)
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>
2025-12-29 14:33:12 -08:00

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
}