mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-03-26 03:59:05 +03:00
all: imp code
This commit is contained in:
parent
4795a2c8fb
commit
496cbba94e
5 changed files with 32 additions and 49 deletions
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.23.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
// TODO!!
|
// TODO!!
|
||||||
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250116174805-966cabfa8953
|
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250123124619-13a82417e9e2
|
||||||
github.com/AdguardTeam/golibs v0.31.0
|
github.com/AdguardTeam/golibs v0.31.0
|
||||||
github.com/AdguardTeam/urlfilter v0.20.0
|
github.com/AdguardTeam/urlfilter v0.20.0
|
||||||
github.com/NYTimes/gziphandler v1.1.1
|
github.com/NYTimes/gziphandler v1.1.1
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
||||||
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250116174805-966cabfa8953 h1:oWKRUtLrKqUO0g3Vh/uEvuxH4wpqh5mV2r7fwqmABF8=
|
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250123124619-13a82417e9e2 h1:YhG4TGJYPFZbio1Pwo3uxONNUqRJL2dfzVIqtbBl6MQ=
|
||||||
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250116174805-966cabfa8953/go.mod h1:Oqw+k7LyjDObfYzXYCkpgtirbzbUrmotr92jrb3N09I=
|
github.com/AdguardTeam/dnsproxy v0.74.2-0.20250123124619-13a82417e9e2/go.mod h1:Oqw+k7LyjDObfYzXYCkpgtirbzbUrmotr92jrb3N09I=
|
||||||
github.com/AdguardTeam/golibs v0.31.0 h1:Z0oPfLTLw6iZmpE58dePy2Bel0MaX+lnDwtFEE5EmIo=
|
github.com/AdguardTeam/golibs v0.31.0 h1:Z0oPfLTLw6iZmpE58dePy2Bel0MaX+lnDwtFEE5EmIo=
|
||||||
github.com/AdguardTeam/golibs v0.31.0/go.mod h1:wIkZ9o2UnppeW6/YD7yJB71dYbMhiuC1Fh/I2ElW7GQ=
|
github.com/AdguardTeam/golibs v0.31.0/go.mod h1:wIkZ9o2UnppeW6/YD7yJB71dYbMhiuC1Fh/I2ElW7GQ=
|
||||||
github.com/AdguardTeam/urlfilter v0.20.0 h1:X32qiuVCVd8WDYCEsbdZKfXMzwdVqrdulamtUi4rmzs=
|
github.com/AdguardTeam/urlfilter v0.20.0 h1:X32qiuVCVd8WDYCEsbdZKfXMzwdVqrdulamtUi4rmzs=
|
||||||
|
|
|
@ -139,16 +139,20 @@ func (s *Server) logQuery(dctx *dnsContext, ip net.IP, processingTime time.Durat
|
||||||
func (s *Server) updateStats(dctx *dnsContext, clientIP string, processingTime time.Duration) {
|
func (s *Server) updateStats(dctx *dnsContext, clientIP string, processingTime time.Duration) {
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
|
|
||||||
|
var upstreamStats []*proxy.UpstreamStatistics
|
||||||
|
qs := pctx.QueryStatistics()
|
||||||
|
if qs != nil {
|
||||||
|
upstreamStats = append(upstreamStats, qs.Main()...)
|
||||||
|
upstreamStats = append(upstreamStats, qs.Fallback()...)
|
||||||
|
}
|
||||||
|
|
||||||
e := &stats.Entry{
|
e := &stats.Entry{
|
||||||
|
UpstreamStats: upstreamStats,
|
||||||
Domain: aghnet.NormalizeDomain(pctx.Req.Question[0].Name),
|
Domain: aghnet.NormalizeDomain(pctx.Req.Question[0].Name),
|
||||||
Result: stats.RNotFiltered,
|
Result: stats.RNotFiltered,
|
||||||
ProcessingTime: processingTime,
|
ProcessingTime: processingTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
if pctx.Upstream != nil {
|
|
||||||
e.Upstream, e.UpstreamTime = upstreamDur(pctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
if clientID := dctx.clientID; clientID != "" {
|
if clientID := dctx.clientID; clientID != "" {
|
||||||
e.Client = clientID
|
e.Client = clientID
|
||||||
} else {
|
} else {
|
||||||
|
@ -171,32 +175,3 @@ func (s *Server) updateStats(dctx *dnsContext, clientIP string, processingTime t
|
||||||
|
|
||||||
s.stats.Update(e)
|
s.stats.Update(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// upstreamDur returns the upstream DNS server address and the DNS lookup
|
|
||||||
// duration. If the upstream address is empty, it means the request was served
|
|
||||||
// from the cache.
|
|
||||||
func upstreamDur(pctx *proxy.DNSContext) (upstream string, dur time.Duration) {
|
|
||||||
if pctx.Upstream == nil {
|
|
||||||
return "", 0
|
|
||||||
}
|
|
||||||
|
|
||||||
qs := pctx.QueryStatistics()
|
|
||||||
if qs == nil {
|
|
||||||
return "", 0
|
|
||||||
}
|
|
||||||
|
|
||||||
addr := pctx.Upstream.Address()
|
|
||||||
for _, u := range qs.Main() {
|
|
||||||
if u.Address == addr {
|
|
||||||
return u.Address, u.QueryDuration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, u := range qs.Fallback() {
|
|
||||||
if u.Address == addr {
|
|
||||||
return u.Address, u.QueryDuration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", 0
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
"github.com/AdguardTeam/AdGuardHome/internal/stats"
|
||||||
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||||
"github.com/AdguardTeam/golibs/netutil"
|
"github.com/AdguardTeam/golibs/netutil"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
|
@ -78,15 +79,19 @@ func TestStats(t *testing.T) {
|
||||||
Client: cliIPStr,
|
Client: cliIPStr,
|
||||||
Result: stats.RFiltered,
|
Result: stats.RFiltered,
|
||||||
ProcessingTime: time.Microsecond * 123456,
|
ProcessingTime: time.Microsecond * 123456,
|
||||||
Upstream: respUpstream,
|
UpstreamStats: []*proxy.UpstreamStatistics{{
|
||||||
UpstreamTime: time.Microsecond * 222222,
|
Address: respUpstream,
|
||||||
|
QueryDuration: time.Microsecond * 222222,
|
||||||
|
}},
|
||||||
}, {
|
}, {
|
||||||
Domain: reqDomain,
|
Domain: reqDomain,
|
||||||
Client: cliIPStr,
|
Client: cliIPStr,
|
||||||
Result: stats.RNotFiltered,
|
Result: stats.RNotFiltered,
|
||||||
ProcessingTime: time.Microsecond * 123456,
|
ProcessingTime: time.Microsecond * 123456,
|
||||||
Upstream: respUpstream,
|
UpstreamStats: []*proxy.UpstreamStatistics{{
|
||||||
UpstreamTime: time.Microsecond * 222222,
|
Address: respUpstream,
|
||||||
|
QueryDuration: time.Microsecond * 222222,
|
||||||
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
wantData := &stats.StatsResp{
|
wantData := &stats.StatsResp{
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
"github.com/AdguardTeam/golibs/errors"
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
|
@ -62,8 +63,9 @@ type Entry struct {
|
||||||
// Domain is the domain name requested.
|
// Domain is the domain name requested.
|
||||||
Domain string
|
Domain string
|
||||||
|
|
||||||
// Upstream is the upstream DNS server.
|
// UpstreamStats contains the DNS query statistics for both the upstream and
|
||||||
Upstream string
|
// fallback DNS servers.
|
||||||
|
UpstreamStats []*proxy.UpstreamStatistics
|
||||||
|
|
||||||
// Result is the result of processing the request.
|
// Result is the result of processing the request.
|
||||||
Result Result
|
Result Result
|
||||||
|
@ -71,9 +73,6 @@ type Entry struct {
|
||||||
// ProcessingTime is the duration of the request processing from the start
|
// ProcessingTime is the duration of the request processing from the start
|
||||||
// of the request including timeouts.
|
// of the request including timeouts.
|
||||||
ProcessingTime time.Duration
|
ProcessingTime time.Duration
|
||||||
|
|
||||||
// UpstreamTime is the duration of the successful request to the upstream.
|
|
||||||
UpstreamTime time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate returns an error if entry is not valid.
|
// validate returns an error if entry is not valid.
|
||||||
|
@ -329,10 +328,14 @@ func (u *unit) add(e *Entry) {
|
||||||
u.timeSum += pt
|
u.timeSum += pt
|
||||||
u.nTotal++
|
u.nTotal++
|
||||||
|
|
||||||
if e.Upstream != "" {
|
for _, s := range e.UpstreamStats {
|
||||||
u.upstreamsResponses[e.Upstream]++
|
if s.IsCached || s.Error != nil {
|
||||||
ut := uint64(e.UpstreamTime.Microseconds())
|
continue
|
||||||
u.upstreamsTimeSum[e.Upstream] += ut
|
}
|
||||||
|
|
||||||
|
addr := s.Address
|
||||||
|
u.upstreamsResponses[addr]++
|
||||||
|
u.upstreamsTimeSum[addr] += uint64(s.QueryDuration.Microseconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue