Add metadata for response Type and Class to Log. (#7806)

This commit is contained in:
Kelly Kane
2026-01-26 08:03:03 -08:00
committed by GitHub
parent b722aadc44
commit b3d79f59e5
2 changed files with 24 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import (
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/plugin/pkg/dnstest"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/replacer"
@@ -35,13 +36,21 @@ func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
rrw := dnstest.NewRecorder(w)
rc, err := plugin.NextOrFailure(l.Name(), l.Next, ctx, rrw, r)
tpe, _ := response.Typify(rrw.Msg, time.Now().UTC())
metadata.SetValueFunc(ctx, "log/type", func() string {
return tpe.String()
})
class := response.Classify(tpe)
metadata.SetValueFunc(ctx, "log/class", func() string {
return class.String()
})
// If we don't set up a class in config, the default "all" will be added
// and we shouldn't have an empty rule.Class.
_, ok := rule.Class[response.All]
var ok1 bool
if !ok {
tpe, _ := response.Typify(rrw.Msg, time.Now().UTC())
class := response.Classify(tpe)
_, ok1 = rule.Class[class]
}
if ok || ok1 {