plugin/metrics: add 'server' label (#1682)

* plugin/metrics: add 'server' label

This uses the new WithServer(ctx) to get the current server from the
context.

First in a larger refactor to make all plugins do this.

* compile

* compile

* lala test

* compile and test

* typos

* Dont duplicate the code
This commit is contained in:
Miek Gieben
2018-04-18 09:42:20 +01:00
committed by GitHub
parent 573ad62b77
commit 08443a9f00
10 changed files with 68 additions and 56 deletions

View File

@@ -21,7 +21,7 @@ import (
type Logger struct {
Next plugin.Handler
Rules []Rule
ErrorFunc func(dns.ResponseWriter, *dns.Msg, int) // failover error handler
ErrorFunc func(context.Context, dns.ResponseWriter, *dns.Msg, int) // failover error handler
}
// ServeDNS implements the plugin.Handler interface.
@@ -39,13 +39,13 @@ func (l Logger) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
// There was an error up the chain, but no response has been written yet.
// The error must be handled here so the log entry will record the response size.
if l.ErrorFunc != nil {
l.ErrorFunc(rrw, r, rc)
l.ErrorFunc(ctx, rrw, r, rc)
} else {
answer := new(dns.Msg)
answer.SetRcode(r, rc)
state.SizeAndDo(answer)
vars.Report(state, vars.Dropped, rcode.ToString(rc), answer.Len(), time.Now())
vars.Report(ctx, state, vars.Dropped, rcode.ToString(rc), answer.Len(), time.Now())
w.WriteMsg(answer)
}