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:
Ville Vesilehto
2025-12-30 00:33:12 +02:00
committed by GitHub
parent b21c752d7f
commit be934b2b06
5 changed files with 263 additions and 25 deletions

View File

@@ -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{