mirror of
https://github.com/coredns/coredns.git
synced 2026-01-14 21:01:19 -05:00
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>
This commit is contained in:
@@ -23,6 +23,34 @@ func (r *inmemoryWriter) Write(buf []byte) (int, error) {
|
||||
return r.ResponseWriter.Write(buf)
|
||||
}
|
||||
|
||||
func TestRecorder_PluginTracker(t *testing.T) {
|
||||
tw := inmemoryWriter{ResponseWriter: test.ResponseWriter{}}
|
||||
rec := NewRecorder(&tw)
|
||||
|
||||
// Initially Plugin should be empty
|
||||
if rec.Plugin != "" {
|
||||
t.Errorf("Expected empty Plugin, got %q", rec.Plugin)
|
||||
}
|
||||
if rec.GetPlugin() != "" {
|
||||
t.Errorf("Expected GetPlugin() to return empty string, got %q", rec.GetPlugin())
|
||||
}
|
||||
|
||||
// SetPlugin should set the plugin name
|
||||
rec.SetPlugin("whoami")
|
||||
if rec.Plugin != "whoami" {
|
||||
t.Errorf("Expected Plugin to be 'whoami', got %q", rec.Plugin)
|
||||
}
|
||||
if rec.GetPlugin() != "whoami" {
|
||||
t.Errorf("Expected GetPlugin() to return 'whoami', got %q", rec.GetPlugin())
|
||||
}
|
||||
|
||||
// SetPlugin should overwrite previous value
|
||||
rec.SetPlugin("cache")
|
||||
if rec.Plugin != "cache" {
|
||||
t.Errorf("Expected Plugin to be 'cache', got %q", rec.Plugin)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecorder_WriteMsg(t *testing.T) {
|
||||
successResp := dns.Msg{}
|
||||
successResp.Answer = []dns.RR{
|
||||
|
||||
Reference in New Issue
Block a user