Skip to content

Commit

Permalink
MOD: Update statistics and add multi-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
oif committed Nov 6, 2017
1 parent a694adf commit 5cde369
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
13 changes: 7 additions & 6 deletions pkg/engine/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, m *dns.Msg) {
goto RESPONSE
}

log.WithFields(log.Fields{
"req_id": reqID,
"name": m.Question[0].Name,
"type": m.Question[0].Qtype,
}).Debug("Receive request")

context = plugin.NewContext(w, m, reqID)
context.MustRegisterPluginsOnce(s.plugins)

log.WithFields(log.Fields{
"req_id": reqID,
"name": m.Question[0].Name,
"type": m.Question[0].Qtype,
"client_ip": context.ClientIP(),
}).Debug("Receive request")

context.Warmup()
context.Patch()

Expand Down
2 changes: 1 addition & 1 deletion plugin/mupstream/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (p *Plugin) Patch(c *plugin.Context) {
up := p.bestUpstream()
resp, rtt, err := up.forward(c.Msg)
if err != nil {
c.Error(err)
// c.Error(err)
return
}
resp.CopyTo(c.Msg)
Expand Down
2 changes: 1 addition & 1 deletion plugin/mupstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newUpstream(addr string) *upstream {
Dialer: &net.Dialer{
KeepAlive: time.Minute,
},
Timeout: time.Second,
Timeout: 300 * time.Millisecond,
},
}
}
Expand Down
10 changes: 8 additions & 2 deletions plugin/statistics/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ func (p *Plugin) AfterResponse(c *plugin.Context, err error) {
}).Info("Response time usage statistics")
// write influxdb
go func(responseTime int64) {
if len(c.Msg.Question) < 1 {
return
}
err := p.pushResponsePoint(c.Msg.Question[0].Qtype, c.Msg.Question[0].Name, responseTime, !c.HasError())
if err != nil {

logrus.Error(err)
}
}(responseTime)
}
Expand Down Expand Up @@ -116,5 +119,8 @@ func (p *Plugin) writeResponse() {
p.points = make([]*client.Point, 0)
p.writeLock.Unlock()

influxdbClient.Write(bp) // ignore error
err = influxdbClient.Write(bp) // ignore error
if err != nil {
logrus.Error(err)
}
}

0 comments on commit 5cde369

Please sign in to comment.