all: sync with master

This commit is contained in:
Ainar Garipov
2025-02-18 19:50:19 +03:00
parent aef00413d5
commit effc822b85
50 changed files with 740 additions and 351 deletions

View File

@@ -20,6 +20,7 @@ import (
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/timeutil"
"go.etcd.io/bbolt"
bbolterrors "go.etcd.io/bbolt/errors"
)
// checkInterval returns true if days is valid to be used as statistics
@@ -469,7 +470,7 @@ func (s *StatsCtx) flushDB(id, limit uint32, ptr *unit) (cont bool, sleepFor tim
// TODO(e.burkov): Improve the algorithm of deleting the oldest bucket
// to avoid the error.
lvl := slog.LevelDebug
if !errors.Is(delErr, bbolt.ErrBucketNotFound) {
if !errors.Is(delErr, bbolterrors.ErrBucketNotFound) {
isCommitable = false
lvl = slog.LevelError
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/testutil"
@@ -78,15 +79,19 @@ func TestStats(t *testing.T) {
Client: cliIPStr,
Result: stats.RFiltered,
ProcessingTime: time.Microsecond * 123456,
Upstream: respUpstream,
UpstreamTime: time.Microsecond * 222222,
UpstreamStats: []*proxy.UpstreamStatistics{{
Address: respUpstream,
QueryDuration: time.Microsecond * 222222,
}},
}, {
Domain: reqDomain,
Client: cliIPStr,
Result: stats.RNotFiltered,
ProcessingTime: time.Microsecond * 123456,
Upstream: respUpstream,
UpstreamTime: time.Microsecond * 222222,
UpstreamStats: []*proxy.UpstreamStatistics{{
Address: respUpstream,
QueryDuration: time.Microsecond * 222222,
}},
}}
wantData := &stats.StatsResp{

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"go.etcd.io/bbolt"
@@ -62,8 +63,9 @@ type Entry struct {
// Domain is the domain name requested.
Domain string
// Upstream is the upstream DNS server.
Upstream string
// UpstreamStats contains the DNS query statistics for both the upstream and
// fallback DNS servers.
UpstreamStats []*proxy.UpstreamStatistics
// Result is the result of processing the request.
Result Result
@@ -71,9 +73,6 @@ type Entry struct {
// ProcessingTime is the duration of the request processing from the start
// of the request including timeouts.
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.
@@ -329,10 +328,14 @@ func (u *unit) add(e *Entry) {
u.timeSum += pt
u.nTotal++
if e.Upstream != "" {
u.upstreamsResponses[e.Upstream]++
ut := uint64(e.UpstreamTime.Microseconds())
u.upstreamsTimeSum[e.Upstream] += ut
for _, s := range e.UpstreamStats {
if s.IsCached || s.Error != nil {
continue
}
addr := s.Address
u.upstreamsResponses[addr]++
u.upstreamsTimeSum[addr] += uint64(s.QueryDuration.Microseconds())
}
}