plugin/dnstap: some cleanup (#1172)

Some cleanup in proxy and dnstap:
* just use time pkg directly and side step the indirection for Epoch
* Use Set in SetQueryEpoch to be more Go like. (Looked like a reader)
* Don't maintain two sets of time, we already track start, so use that.
* Use time.Time and convert when needed
* dedent the toDnstap function and put in a separate file
This commit is contained in:
Miek Gieben
2017-10-25 19:46:41 +01:00
committed by GitHub
parent 25367a4329
commit c2d93f7182
6 changed files with 64 additions and 61 deletions

View File

@@ -4,6 +4,7 @@ package taprw
import (
"fmt"
"time"
"github.com/coredns/coredns/plugin/dnstap/msg"
@@ -41,9 +42,9 @@ func (w ResponseWriter) DnstapError() error {
return w.err
}
// QueryEpoch sets the query epoch as reported by dnstap.
func (w *ResponseWriter) QueryEpoch() {
w.queryEpoch = msg.Epoch()
// SetQueryEpoch sets the query epoch as reported by dnstap.
func (w *ResponseWriter) SetQueryEpoch() {
w.queryEpoch = uint64(time.Now().Unix())
}
// WriteMsg writes back the response to the client and THEN works on logging the request
@@ -51,7 +52,7 @@ func (w *ResponseWriter) QueryEpoch() {
// Dnstap errors are to be checked by DnstapError.
func (w *ResponseWriter) WriteMsg(resp *dns.Msg) (writeErr error) {
writeErr = w.ResponseWriter.WriteMsg(resp)
writeEpoch := msg.Epoch()
writeEpoch := uint64(time.Now().Unix())
b := w.TapBuilder()
b.TimeSec = w.queryEpoch