Skip to content

Commit

Permalink
all: imp average processing time
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Oct 31, 2023
1 parent 62ec0d5 commit 040b6b9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome
go 1.20

require (
github.com/AdguardTeam/dnsproxy v0.56.3
github.com/AdguardTeam/dnsproxy v0.56.4-0.20231031121835-8d20902c442f
github.com/AdguardTeam/golibs v0.17.2
github.com/AdguardTeam/urlfilter v0.17.3
github.com/NYTimes/gziphandler v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/AdguardTeam/dnsproxy v0.56.3 h1:WP1FooLfZQPHEH2SuwMtJsOurDt32rubGx0OddcsKT0=
github.com/AdguardTeam/dnsproxy v0.56.3/go.mod h1:ZvkbM71HwpilgkCnTubDiR4Ba6x5Qvnhy2iasMWaTDM=
github.com/AdguardTeam/dnsproxy v0.56.4-0.20231031121835-8d20902c442f h1:0fgscvsWpMq5G8Ab653inTgo2TXB6RxM2PjYArfs7t4=
github.com/AdguardTeam/dnsproxy v0.56.4-0.20231031121835-8d20902c442f/go.mod h1:ZvkbM71HwpilgkCnTubDiR4Ba6x5Qvnhy2iasMWaTDM=
github.com/AdguardTeam/golibs v0.17.2 h1:vg6wHMjUKscnyPGRvxS5kAt7Uw4YxcJiITZliZ476W8=
github.com/AdguardTeam/golibs v0.17.2/go.mod h1:DKhCIXHcUYtBhU8ibTLKh1paUL96n5zhQBlx763sj+U=
github.com/AdguardTeam/urlfilter v0.17.3 h1:fg/ObbnO0Cv6aw0tW6N/ETDMhhNvmcUUOZ7HlmKC3rw=
Expand Down
5 changes: 2 additions & 3 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,8 @@ func (s *Server) Exchange(ip netip.Addr) (host string, ttl time.Duration, err er
}

dctx := &proxy.DNSContext{
Proto: "udp",
Req: req,
StartTime: time.Now(),
Proto: "udp",
Req: req,
}

var resolver *proxy.Proxy
Expand Down
8 changes: 3 additions & 5 deletions internal/dnsforward/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dnsforward

import (
"net/netip"
"time"

"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
Expand Down Expand Up @@ -270,10 +269,9 @@ func (s *Server) genBlockedHost(request *dns.Msg, newAddr string, d *proxy.DNSCo
replReq.RecursionDesired = true

newContext := &proxy.DNSContext{
Proto: d.Proto,
Addr: d.Addr,
StartTime: time.Now(),
Req: &replReq,
Proto: d.Proto,
Addr: d.Addr,
Req: &replReq,
}

prx := s.proxy()
Expand Down
2 changes: 1 addition & 1 deletion internal/dnsforward/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func (s *Server) processQueryLogsAndStats(dctx *dnsContext) (rc resultCode) {
log.Debug("dnsforward: started processing querylog and stats")
defer log.Debug("dnsforward: finished processing querylog and stats")

elapsed := time.Since(dctx.startTime)
pctx := dctx.proxyCtx
elapsed := pctx.QueryDuration

q := pctx.Req.Question[0]
host := aghnet.NormalizeDomain(q.Name)
Expand Down
9 changes: 5 additions & 4 deletions internal/stats/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ func (u *unit) add(e *Entry) {
}

u.clients[e.Client]++
t := uint64(e.Time.Microseconds())
u.timeSum += t
u.nTotal++

if e.Upstream != "" {
u.upstreamsResponses[e.Upstream]++
t := uint64(e.Time.Microseconds())
u.timeSum += t
u.upstreamsTimeSum[e.Upstream] += t
}
}
Expand Down Expand Up @@ -604,11 +604,12 @@ func prepareTopUpstreamsAvgTime(
) (topUpstreamsAvgTime []topAddrsFloat) {
keys := maps.Keys(upstreamsAvgTime)

// Sort in ascending order.
slices.SortFunc(keys, func(a, b string) (res int) {
switch x, y := upstreamsAvgTime[a], upstreamsAvgTime[b]; {
case x > y:
return -1
case x < y:
return -1
case x > y:
return +1
default:
return 0
Expand Down
6 changes: 3 additions & 3 deletions internal/stats/unit_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ func TestTopUpstreamsPairs(t *testing.T) {
{"1.1.1.1": 2},
},
wantAvgTime: []topAddrsFloat{
{"4.4.4.4": 1000},
{"3.3.3.3": 100},
{"2.2.2.2": 10},
{"1.1.1.1": 1},
{"2.2.2.2": 10},
{"3.3.3.3": 100},
{"4.4.4.4": 1000},
},
}}

Expand Down

0 comments on commit 040b6b9

Please sign in to comment.