* middleware/metrics: add more metrics middleware/cache: Add metrics for number of elements in the cache. Also export the total size. Update README to detail the new metrics. middleware/metrics Move metrics into subpackage called "vars". This breaks the import cycle and is cleaner. This allows vars.Report to be used in the the dnsserver to log refused queries. middleware/metrics: tests Add tests to the metrics framework. The metrics/test subpackage allows scraping of the local server. Do a few test scrape of the metrics that are defined in the metrics middleware. This also allows metrics integration tests to check if the caching and dnssec middleware export their metrics correctly. * update README * typos * fix tests
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package dnssec
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/miekg/coredns/middleware"
|
|
"github.com/miekg/coredns/request"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
// ResponseWriter sign the response on the fly.
|
|
type ResponseWriter struct {
|
|
dns.ResponseWriter
|
|
d Dnssec
|
|
}
|
|
|
|
// WriteMsg implements the dns.ResponseWriter interface.
|
|
func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
|
// By definition we should sign anything that comes back, we should still figure out for
|
|
// which zone it should be.
|
|
state := request.Request{W: d.ResponseWriter, Req: res}
|
|
|
|
qname := state.Name()
|
|
zone := middleware.Zones(d.d.zones).Matches(qname)
|
|
if zone == "" {
|
|
return d.ResponseWriter.WriteMsg(res)
|
|
}
|
|
|
|
if state.Do() {
|
|
res = d.d.Sign(state, zone, time.Now().UTC())
|
|
|
|
cacheSize.WithLabelValues("signature").Set(float64(d.d.cache.Len()))
|
|
}
|
|
state.SizeAndDo(res)
|
|
|
|
return d.ResponseWriter.WriteMsg(res)
|
|
}
|
|
|
|
// Write implements the dns.ResponseWriter interface.
|
|
func (d *ResponseWriter) Write(buf []byte) (int, error) {
|
|
log.Printf("[WARNING] Dnssec called with Write: not signing reply")
|
|
n, err := d.ResponseWriter.Write(buf)
|
|
return n, err
|
|
}
|
|
|
|
// Hijack implements the dns.ResponseWriter interface.
|
|
func (d *ResponseWriter) Hijack() { d.ResponseWriter.Hijack() }
|