Skip to content

Commit

Permalink
Merge branch 'AdguardTeam:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hoang-rio authored Feb 1, 2025
2 parents 119badc + d3dea0f commit c2c5133
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 46 deletions.
38 changes: 27 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@ The format is based on [*Keep a Changelog*](https://keepachangelog.com/en/1.0.0/
<!--
## [v0.108.0] – TBA

## [v0.107.56] - 2025-01-10 (APPROX.)
## [v0.107.57] - 2025-02-10 (APPROX.)

See also the [v0.107.56 GitHub milestone][ms-v0.107.56].
See also the [v0.107.57 GitHub milestone][ms-v0.107.57].

[ms-v0.107.56]: https://github.com/AdguardTeam/AdGuardHome/milestone/91?closed=1
[ms-v0.107.57]: https://github.com/AdguardTeam/AdGuardHome/milestone/92?closed=1

NOTE: Add new changes BELOW THIS COMMENT.
-->

### Changed

- The *Fastest IP adddress* upstream mode now collects statistics for the all upstream DNS servers.

### Fixed

- The formatting of large numbers in the upstream table and query log ([#7590]).

[#7590]: https://github.com/AdguardTeam/AdGuardHome/issues/7590

<!--
NOTE: Add new changes ABOVE THIS COMMENT.
-->

## [v0.107.56] - 2025-01-23

See also the [v0.107.56 GitHub milestone][ms-v0.107.56].

### Security

- Go version has been updated to prevent the possibility of exploiting the Go vulnerabilities fixed in [1.23.5][go-1.23.5].
Expand All @@ -36,14 +54,11 @@ NOTE: Add new changes BELOW THIS COMMENT.

- The formatting of large numbers on the dashboard ([#7329]).

[#7513]: https://github.com/AdguardTeam/AdGuardHome/issues/7513
[#7329]: https://github.com/AdguardTeam/AdGuardHome/issues/7329
[#7513]: https://github.com/AdguardTeam/AdGuardHome/issues/7513

[go-1.23.5]: https://groups.google.com/g/golang-announce/c/sSaUhLA-2SI

<!--
NOTE: Add new changes ABOVE THIS COMMENT.
-->
[ms-v0.107.56]: https://github.com/AdguardTeam/AdGuardHome/milestone/91?closed=1

## [v0.107.55] - 2024-12-11

Expand Down Expand Up @@ -2985,11 +3000,12 @@ See also the [v0.104.2 GitHub milestone][ms-v0.104.2].
[ms-v0.104.2]: https://github.com/AdguardTeam/AdGuardHome/milestone/28?closed=1

<!--
[Unreleased]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.56...HEAD
[v0.107.55]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.55...v0.107.56
[Unreleased]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.57...HEAD
[v0.107.57]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.56...v0.107.57
-->

[Unreleased]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.55...HEAD
[Unreleased]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.56...HEAD
[v0.107.56]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.55...v0.107.56
[v0.107.55]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.54...v0.107.55
[v0.107.54]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.53...v0.107.54
[v0.107.53]: https://github.com/AdguardTeam/AdGuardHome/compare/v0.107.52...v0.107.53
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/Dashboard/UpstreamAvgTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Card from '../ui/Card';

import DomainCell from './DomainCell';
import { DASHBOARD_TABLES_DEFAULT_PAGE_SIZE, TABLES_MIN_ROWS } from '../../helpers/constants';
import { formatNumber } from '../../helpers/helpers';

interface TimeCellProps {
value?: string | number;
Expand All @@ -20,7 +21,7 @@ const TimeCell = ({ value }: TimeCellProps) => {
return '–';
}

const valueInMilliseconds = round(Number(value) * 1000);
const valueInMilliseconds = formatNumber(round(Number(value) * 1000));

return (
<div className="logs__row o-hidden">
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const Dashboard = ({
}}
disabled={processingProtection}>
{protectionDisabledDuration
? `${t('enable_protection_timer')} ${getRemaningTimeText(protectionDisabledDuration)}`
? `${t('enable_protection_timer', { time: getRemaningTimeText(protectionDisabledDuration) })}`
: getProtectionBtnText(protectionEnabled)}
</button>

Expand Down
22 changes: 13 additions & 9 deletions client/src/helpers/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export const getParamsForClientsSearch = (data: any, param: any, additionalParam
});

return {
clients: Array.from(clients).map(id => ({ id })),
clients: Array.from(clients).map((id) => ({ id })),
};
};

Expand Down Expand Up @@ -718,9 +718,16 @@ export const countClientsStatistics = (ids: any, autoClients: any) => {
* @param {function} t translate
* @returns {string}
*/
export const formatElapsedMs = (elapsedMs: any, t: any) => {
const formattedElapsedMs = parseInt(elapsedMs, 10) || parseFloat(elapsedMs).toFixed(2);
return `${formattedElapsedMs} ${t('milliseconds_abbreviation')}`;
export const formatElapsedMs = (elapsedMs: string, t: (key: string) => string) => {
const parsedElapsedMs = parseInt(elapsedMs, 10);

if (Number.isNaN(parsedElapsedMs)) {
return elapsedMs;
}

const formattedMs = formatNumber(parsedElapsedMs);

return `${formattedMs} ${t('milliseconds_abbreviation')}`;
};

/**
Expand Down Expand Up @@ -803,12 +810,9 @@ type NestedObject = {
order: number;
};

export const getObjectKeysSorted = <
T extends Record<string, NestedObject>,
K extends keyof NestedObject
>(
export const getObjectKeysSorted = <T extends Record<string, NestedObject>, K extends keyof NestedObject>(
object: T,
sortKey: K
sortKey: K,
): string[] => {
return Object.entries(object)
.sort(([, a], [, b]) => (a[sortKey] as number) - (b[sortKey] as number))
Expand Down
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.23.5

require (
github.com/AdguardTeam/dnsproxy v0.73.5
github.com/AdguardTeam/dnsproxy v0.75.0
github.com/AdguardTeam/golibs v0.31.0
github.com/AdguardTeam/urlfilter v0.20.0
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.73.5 h1:3EiVaTfmuW6PcJGbqloR6ZdHACsrYkm9z0eH8ZQTZnQ=
github.com/AdguardTeam/dnsproxy v0.73.5/go.mod h1:Oqw+k7LyjDObfYzXYCkpgtirbzbUrmotr92jrb3N09I=
github.com/AdguardTeam/dnsproxy v0.75.0 h1:v8/Oq/xPYzNoALR7SEUZEIbKmjnPcXLVhJLFVbrozEc=
github.com/AdguardTeam/dnsproxy v0.75.0/go.mod h1:O2qoXwF4BUBFui7OMUiWSYwapEDcYxKWeur4+jfy9nM=
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/urlfilter v0.20.0 h1:X32qiuVCVd8WDYCEsbdZKfXMzwdVqrdulamtUi4rmzs=
Expand Down
24 changes: 16 additions & 8 deletions internal/dnsforward/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ func (s *Server) logQuery(dctx *dnsContext, ip net.IP, processingTime time.Durat

if pctx.Upstream != nil {
p.Upstream = pctx.Upstream.Address()
} else if cachedUps := pctx.CachedUpstreamAddr; cachedUps != "" {
p.Upstream = pctx.CachedUpstreamAddr
p.Cached = true
}

if qs := pctx.QueryStatistics(); qs != nil {
ms := qs.Main()
if len(ms) == 1 && ms[0].IsCached {
p.Upstream = ms[0].Address
p.Cached = true
}
}

s.queryLog.Add(p)
Expand All @@ -134,15 +139,18 @@ func (s *Server) logQuery(dctx *dnsContext, ip net.IP, processingTime time.Durat
func (s *Server) updateStats(dctx *dnsContext, clientIP string, processingTime time.Duration) {
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{
UpstreamStats: upstreamStats,
Domain: aghnet.NormalizeDomain(pctx.Req.Question[0].Name),
Result: stats.RNotFiltered,
ProcessingTime: processingTime,
UpstreamTime: pctx.QueryDuration,
}

if pctx.Upstream != nil {
e.Upstream = pctx.Upstream.Address()
}

if clientID := dctx.clientID; clientID != "" {
Expand Down
13 changes: 9 additions & 4 deletions internal/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
21 changes: 12 additions & 9 deletions internal/stats/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -62,18 +63,16 @@ 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

// 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.
Expand Down Expand Up @@ -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())
}
}

Expand Down

0 comments on commit c2c5133

Please sign in to comment.