correct EDNS responses (#96)
Tests updated as well and all the middleware. And Prometheus renamed to metrics (directive is still prometheus).
This commit is contained in:
parent
db3d689a8a
commit
ad221f4b2a
19 changed files with 192 additions and 143 deletions
42
middleware/metrics/handler.go
Normal file
42
middleware/metrics/handler.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := middleware.State{W: w, Req: r}
|
||||
qname := state.Name()
|
||||
qtype := state.Type()
|
||||
zone := middleware.Zones(m.ZoneNames).Matches(qname)
|
||||
if zone == "" {
|
||||
zone = "."
|
||||
}
|
||||
|
||||
// Record response to get status code and size of the reply.
|
||||
rw := middleware.NewResponseRecorder(w)
|
||||
status, err := m.Next.ServeDNS(ctx, rw, r)
|
||||
|
||||
Report(zone, qtype, rw.Rcode(), rw.Size(), rw.Start())
|
||||
|
||||
return status, err
|
||||
}
|
||||
|
||||
// Report is a plain reporting function that the server can use for REFUSED and other
|
||||
// queries that are turned down because they don't match any middleware.
|
||||
func Report(zone, qtype, rcode string, size int, start time.Time) {
|
||||
if requestCount == nil {
|
||||
// no metrics are enabled
|
||||
return
|
||||
}
|
||||
|
||||
requestCount.WithLabelValues(zone, qtype).Inc()
|
||||
requestDuration.WithLabelValues(zone, qtype).Observe(float64(time.Since(start) / time.Second))
|
||||
responseSize.WithLabelValues(zone, qtype).Observe(float64(size))
|
||||
responseRcode.WithLabelValues(zone, rcode, qtype).Inc()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue