mirror of
https://github.com/coredns/coredns.git
synced 2025-12-07 02:45:11 -05:00
fix(metrics): preserve request size from plugins (#7313)
The rewrite plugin modifies DNS messages, affecting the request size observed in the coredns_dns_request_size_bytes metric. This change captures the original request size before any plugins can modify it. It adds a functional options pattern to Report() to pass this information while maintaining API compatibility. Tests have been added to verify the fix prevents rewrite from affecting the request size metrics. Docs included. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
@@ -16,6 +16,9 @@ import (
|
||||
func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := request.Request{W: w, Req: r}
|
||||
|
||||
// Capture the original request size before any plugins modify it
|
||||
originalSize := r.Len()
|
||||
|
||||
qname := state.QName()
|
||||
zone := plugin.Zones(m.ZoneNames()).Matches(qname)
|
||||
if zone == "" {
|
||||
@@ -34,7 +37,9 @@ func (m *Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
rc = status
|
||||
}
|
||||
plugin := m.authoritativePlugin(rw.Caller)
|
||||
vars.Report(WithServer(ctx), state, zone, WithView(ctx), rcode.ToString(rc), plugin, rw.Len, rw.Start)
|
||||
// Pass the original request size to vars.Report
|
||||
vars.Report(WithServer(ctx), state, zone, WithView(ctx), rcode.ToString(rc), plugin,
|
||||
rw.Len, rw.Start, vars.WithOriginalReqSize(originalSize))
|
||||
|
||||
return status, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user