Pull request: AGDNS-3007-fix-ups-logger

Merge in DNS/adguard-home from AGDNS-3007-fix-ups-logger to master

Squashed commit of the following:

commit 7b198ab6f075ec0be9ab638925d65dcf16c3aa67
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 9 09:54:15 2025 +0400

    dnsforward: fix merge

commit dd0a680bd1b995bbe570861723f85244855de2ce
Merge: 081526039 63c64b10e
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 9 09:43:22 2025 +0400

    Merge remote-tracking branch 'origin/master' into AGDNS-3007-fix-ups-logger

commit 081526039f
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Mon Jul 7 17:53:37 2025 +0400

    all: imp code

commit 88b5398c8b
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 3 09:59:28 2025 +0400

    all: imp code

commit c9440af9a5
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Thu Jul 3 09:51:44 2025 +0400

    all: imp code

commit 4aff2860ed
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 2 13:41:00 2025 +0400

    all: upstream dnsproxy prefix

commit 4cbc65608e
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 2 13:37:45 2025 +0400

    aghslog: add dnsproxy prefix

commit fdc1ed02c3
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 2 13:33:10 2025 +0400

    client: imp upstream log

commit 19438ba7e8
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 2 13:30:10 2025 +0400

    all: aghslog consts

commit ee5e3875c7
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Wed Jul 2 13:26:42 2025 +0400

    dnsforward: imp tests

commit 8b8c608032
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue Jul 1 14:04:59 2025 +0400

    client: fix upd conf logger

commit 98227476a2
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue Jul 1 13:26:09 2025 +0400

    next: dnssvc: use aghslog constants

commit b331ba921c
Author: Dimitry Kolyshev <dkolyshev@adguard.com>
Date:   Tue Jul 1 13:23:33 2025 +0400

    all: fix upd conf logger
This commit is contained in:
Dimitry Kolyshev 2025-07-09 12:07:37 +03:00
parent 63c64b10e9
commit fca0faf6d4
14 changed files with 152 additions and 43 deletions

View File

@ -0,0 +1,52 @@
// Package aghslog contains logging constants and helpers.
package aghslog
import (
"log/slog"
"github.com/AdguardTeam/golibs/logutil/slogutil"
)
// PrefixDNSProxy is the prefix for DNS proxy logs.
const PrefixDNSProxy = "dnsproxy"
const (
// KeyClientName is the log attribute for the client name.
KeyClientName = "client_name"
// KeyUpstreamType is the log attribute for the upstream types. See the
// UpstreamType* constants below.
KeyUpstreamType = "upstream_type"
)
const (
// UpstreamTypeBootstrap is the log attribute value for bootstrap upstreams.
UpstreamTypeBootstrap = "bootstrap"
// UpstreamTypeCustom is the log attribute value for custom upstreams.
UpstreamTypeCustom = "custom"
// UpstreamTypeFallback is the log attribute value for fallback upstreams.
UpstreamTypeFallback = "fallback"
// UpstreamTypeMain is the log attribute value for main upstreams.
UpstreamTypeMain = "main"
// UpstreamTypeLocal is the log attribute value for upstreams used for
// resolving PTR records for local addresses.
UpstreamTypeLocal = "local"
// UpstreamTypeService is the log attribute value for upstreams used for
// safe browsing and parental services.
UpstreamTypeService = "service"
// UpstreamTypeTest is the log attribute value for upstreams used for
// testing and validation.
UpstreamTypeTest = "test"
)
// NewForUpstream returns a new logger with a prefix for logs related to a
// specific upstream type.
func NewForUpstream(baseLogger *slog.Logger, typ string) (l *slog.Logger) {
return baseLogger.With(slogutil.KeyPrefix, PrefixDNSProxy, KeyUpstreamType, typ)
}

View File

@ -10,6 +10,7 @@ import (
"slices"
"strings"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
@ -142,7 +143,9 @@ func (c *Persistent) validate(ctx context.Context, l *slog.Logger, allTags []str
return errors.Error("uid required")
}
conf, err := proxy.ParseUpstreamsConfig(c.Upstreams, &upstream.Options{})
conf, err := proxy.ParseUpstreamsConfig(c.Upstreams, &upstream.Options{
Logger: l.With(aghslog.KeyUpstreamType, aghslog.UpstreamTypeTest),
})
if err != nil {
return fmt.Errorf("invalid upstream servers: %w", err)
}

View File

@ -88,6 +88,10 @@ type HostsContainer interface {
// StorageConfig is the client storage configuration structure.
type StorageConfig struct {
// BaseLogger is used to create loggers for other entities. It should not
// have a prefix and must not be nil.
BaseLogger *slog.Logger
// Logger is used for logging the operation of the client storage. It must
// not be nil.
Logger *slog.Logger
@ -174,7 +178,7 @@ func NewStorage(ctx context.Context, conf *StorageConfig) (s *Storage, err error
mu: &sync.Mutex{},
index: newIndex(),
runtimeIndex: newRuntimeIndex(),
upstreamManager: newUpstreamManager(conf.Logger, conf.Clock),
upstreamManager: newUpstreamManager(conf.BaseLogger, conf.Clock),
dhcp: conf.DHCP,
etcHosts: conf.EtcHosts,
arpDB: conf.ARPDB,
@ -739,7 +743,7 @@ func (s *Storage) CustomUpstreamConfig(
return nil
}
return s.upstreamManager.customUpstreamConfig(c.UID)
return s.upstreamManager.customUpstreamConfig(c.UID, c.Name)
}
// UpdateCommonUpstreamConfig implements the [dnsforward.ClientsContainer]

View File

@ -25,14 +25,18 @@ import (
"github.com/stretchr/testify/require"
)
// testLogger is a logger used in tests.
var testLogger = slogutil.NewDiscardLogger()
// newTestStorage is a helper function that returns initialized storage.
func newTestStorage(tb testing.TB, clock timeutil.Clock) (s *client.Storage) {
tb.Helper()
ctx := testutil.ContextWithTimeout(tb, testTimeout)
s, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
Clock: clock,
BaseLogger: testLogger,
Logger: testLogger,
Clock: clock,
})
require.NoError(tb, err)
@ -134,7 +138,8 @@ func TestStorage_Add_hostsfile(t *testing.T) {
ctx := testutil.ContextWithTimeout(t, testTimeout)
storage, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
BaseLogger: testLogger,
Logger: testLogger,
DHCP: client.EmptyDHCP{},
EtcHosts: h,
ARPClientsUpdatePeriod: testTimeout / 10,
@ -224,7 +229,8 @@ func TestStorage_Add_arp(t *testing.T) {
ctx := testutil.ContextWithTimeout(t, testTimeout)
storage, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
BaseLogger: testLogger,
Logger: testLogger,
DHCP: client.EmptyDHCP{},
ARPDB: a,
ARPClientsUpdatePeriod: testTimeout / 10,
@ -301,8 +307,9 @@ func TestStorage_Add_whois(t *testing.T) {
ctx := testutil.ContextWithTimeout(t, testTimeout)
storage, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
DHCP: client.EmptyDHCP{},
BaseLogger: testLogger,
Logger: testLogger,
DHCP: client.EmptyDHCP{},
})
require.NoError(t, err)
@ -417,7 +424,8 @@ func TestClientsDHCP(t *testing.T) {
ctx := testutil.ContextWithTimeout(t, testTimeout)
storage, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
BaseLogger: testLogger,
Logger: testLogger,
ARPDB: arpDB,
DHCP: dhcp,
EtcHosts: etcHosts,
@ -566,8 +574,9 @@ func TestClientsAddExisting(t *testing.T) {
t.Run("simple", func(t *testing.T) {
storage, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
DHCP: client.EmptyDHCP{},
BaseLogger: testLogger,
Logger: testLogger,
DHCP: client.EmptyDHCP{},
})
require.NoError(t, err)
@ -613,8 +622,9 @@ func TestClientsAddExisting(t *testing.T) {
require.NoError(t, err)
storage, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
DHCP: dhcpServer,
BaseLogger: testLogger,
Logger: testLogger,
DHCP: dhcpServer,
})
require.NoError(t, err)
@ -653,8 +663,9 @@ func newStorage(tb testing.TB, m []*client.Persistent) (s *client.Storage) {
ctx := testutil.ContextWithTimeout(tb, testTimeout)
s, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
DHCP: client.EmptyDHCP{},
BaseLogger: testLogger,
Logger: testLogger,
DHCP: client.EmptyDHCP{},
})
require.NoError(tb, err)
@ -1210,9 +1221,10 @@ func TestStorage_CustomUpstreamConfig(t *testing.T) {
ctx := testutil.ContextWithTimeout(t, testTimeout)
s, err := client.NewStorage(ctx, &client.StorageConfig{
Logger: slogutil.NewDiscardLogger(),
Clock: clock,
DHCP: dhcp,
BaseLogger: testLogger,
Logger: testLogger,
Clock: clock,
DHCP: dhcp,
})
require.NoError(t, err)

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
@ -56,10 +57,12 @@ type customUpstreamConfig struct {
// upstreamManager stores and updates custom client upstream configurations.
type upstreamManager struct {
// baseLogger is used to create loggers for client upstream configurations.
// It should not have a prefix and must not be nil.
baseLogger *slog.Logger
// logger is used for logging the operation of the upstream manager. It
// must not be nil.
//
// TODO(s.chzhen): Consider using a logger with its own prefix.
logger *slog.Logger
// uidToCustomConf maps persistent client UID to the custom client upstream
@ -78,9 +81,10 @@ type upstreamManager struct {
}
// newUpstreamManager returns the new properly initialized upstream manager.
func newUpstreamManager(logger *slog.Logger, clock timeutil.Clock) (m *upstreamManager) {
func newUpstreamManager(baseLogger *slog.Logger, clock timeutil.Clock) (m *upstreamManager) {
return &upstreamManager{
logger: logger,
baseLogger: baseLogger,
logger: baseLogger.With(slogutil.KeyPrefix, "upstream_manager"),
uidToCustomConf: make(map[UID]*customUpstreamConfig),
clock: clock,
}
@ -115,7 +119,10 @@ func (m *upstreamManager) updateCustomUpstreamConfig(c *Persistent) {
}
// customUpstreamConfig returns the custom client upstream configuration.
func (m *upstreamManager) customUpstreamConfig(uid UID) (proxyConf *proxy.CustomUpstreamConfig) {
func (m *upstreamManager) customUpstreamConfig(
uid UID,
clientName string,
) (proxyConf *proxy.CustomUpstreamConfig) {
cliConf, ok := m.uidToCustomConf[uid]
if !ok {
// TODO(s.chzhen): Consider panic.
@ -136,7 +143,11 @@ func (m *upstreamManager) customUpstreamConfig(uid UID) (proxyConf *proxy.Custom
}
}
proxyConf = newCustomUpstreamConfig(cliConf, m.commonConf)
cliLogger := aghslog.NewForUpstream(m.baseLogger, aghslog.UpstreamTypeCustom).With(
aghslog.KeyClientName,
clientName,
)
proxyConf = newCustomUpstreamConfig(cliConf, m.commonConf, cliLogger)
cliConf.proxyConf = proxyConf
cliConf.commonConfUpdate = m.confUpdate
cliConf.isChanged = false
@ -193,10 +204,12 @@ func (m *upstreamManager) close() (err error) {
}
// newCustomUpstreamConfig returns the new properly initialized custom proxy
// upstream configuration for the client.
// upstream configuration for the client. cliConf, conf, and cliLogger must not
// be nil.
func newCustomUpstreamConfig(
cliConf *customUpstreamConfig,
conf *CommonUpstreamConfig,
cliLogger *slog.Logger,
) (proxyConf *proxy.CustomUpstreamConfig) {
upstreams := stringutil.FilterOut(cliConf.upstreams, aghnet.IsCommentOrEmpty)
if len(upstreams) == 0 {
@ -206,8 +219,9 @@ func newCustomUpstreamConfig(
upsConf, err := proxy.ParseUpstreamsConfig(
upstreams,
&upstream.Options{
Logger: cliLogger,
Bootstrap: conf.Bootstrap,
Timeout: time.Duration(conf.UpstreamTimeout),
Timeout: conf.UpstreamTimeout,
HTTPVersions: aghnet.UpstreamHTTPVersions(conf.UseHTTP3Upstreams),
PreferIPv6: conf.BootstrapPreferIPv6,
},

View File

@ -13,6 +13,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/AdGuardHome/internal/aghtls"
"github.com/AdguardTeam/AdGuardHome/internal/client"
"github.com/AdguardTeam/dnsproxy/proxy"
@ -311,7 +312,7 @@ func (s *Server) newProxyConfig() (conf *proxy.Config, err error) {
trustedPrefixes := netutil.UnembedPrefixes(srvConf.TrustedProxies)
conf = &proxy.Config{
Logger: s.baseLogger.With(slogutil.KeyPrefix, "dnsproxy"),
Logger: s.baseLogger.With(slogutil.KeyPrefix, aghslog.PrefixDNSProxy),
HTTP3: srvConf.ServeHTTP3,
Ratelimit: int(srvConf.Ratelimit),
RatelimitSubnetLenIPv4: srvConf.RatelimitSubnetLenIPv4,

View File

@ -18,6 +18,7 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/AdGuardHome/internal/client"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
@ -546,6 +547,7 @@ func (s *Server) prepareUpstreamSettings(boot upstream.Resolver) (err error) {
}
uc, err := newUpstreamConfig(upstreams, defaultDNS, &upstream.Options{
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeMain),
Bootstrap: boot,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: aghnet.UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams),
@ -612,6 +614,7 @@ func (s *Server) prepareLocalResolvers() (uc *proxy.UpstreamConfig, err error) {
}
opts := &upstream.Options{
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeLocal),
Bootstrap: s.bootstrap,
Timeout: defaultLocalTimeout,
// TODO(e.burkov): Should we verify server's certificates?
@ -644,6 +647,7 @@ func (s *Server) prepareInternalDNS() (err error) {
}
bootOpts := &upstream.Options{
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeBootstrap),
Timeout: DefaultTimeout,
HTTPVersions: aghnet.UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams),
}
@ -682,6 +686,7 @@ func (s *Server) setupFallbackDNS() (uc *proxy.UpstreamConfig, err error) {
}
uc, err = proxy.ParseUpstreamsConfig(fallbacks, &upstream.Options{
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeFallback),
// TODO(s.chzhen): Investigate if other options are needed.
Timeout: s.conf.UpstreamTimeout,
PreferIPv6: s.conf.BootstrapPreferIPv6,
@ -750,7 +755,7 @@ func validateBlockingMode(
func (s *Server) prepareInternalProxy() (err error) {
srvConf := s.conf
conf := &proxy.Config{
Logger: s.baseLogger.With(slogutil.KeyPrefix, "dnsproxy"),
Logger: s.baseLogger.With(slogutil.KeyPrefix, aghslog.PrefixDNSProxy),
CacheEnabled: true,
CacheSizeBytes: 4096,
PrivateRDNSUpstreamConfig: srvConf.PrivateRDNSUpstreamConfig,

View File

@ -39,6 +39,9 @@ import (
"github.com/stretchr/testify/require"
)
// testLogger is a logger used in tests.
var testLogger = slogutil.NewDiscardLogger()
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
@ -63,9 +66,6 @@ const (
// TODO(a.garipov): Use more.
var testClientAddrPort = netip.MustParseAddrPort("1.2.3.4:12345")
// testLogger is the common logger for tests.
var testLogger = slogutil.NewDiscardLogger()
// type check
var _ ClientsContainer = (*clientsContainer)(nil)
@ -532,7 +532,10 @@ func TestDoQServer(t *testing.T) {
// Create a DNS-over-QUIC upstream.
addr := s.dnsProxy.Addr(proxy.ProtoQUIC)
opts := &upstream.Options{InsecureSkipVerify: true}
opts := &upstream.Options{
Logger: testLogger,
InsecureSkipVerify: true,
}
u, err := upstream.AddressToUpstream(fmt.Sprintf("%s://%s", proxy.ProtoQUIC, addr), opts)
require.NoError(t, err)

View File

@ -12,11 +12,13 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/validate"
@ -366,7 +368,9 @@ func (req *jsonDNSConfig) checkPrivateRDNS(
addrs := cmp.Or(req.LocalPTRUpstreams, &[]string{})
uc, err := newPrivateConfig(*addrs, ownAddrs, sysResolvers, privateNets, &upstream.Options{})
uc, err := newPrivateConfig(*addrs, ownAddrs, sysResolvers, privateNets, &upstream.Options{
Logger: slogutil.NewDiscardLogger(),
})
err = errors.WithDeferred(err, uc.Close())
if err != nil {
return fmt.Errorf("private upstream servers: %w", err)
@ -382,7 +386,9 @@ func (req *jsonDNSConfig) validateUpstreamDNSServers(
privateNets netutil.SubnetSet,
) (err error) {
var uc *proxy.UpstreamConfig
opts := &upstream.Options{}
opts := &upstream.Options{
Logger: slogutil.NewDiscardLogger(),
}
if req.Upstreams != nil {
uc, err = proxy.ParseUpstreamsConfig(*req.Upstreams, opts)
@ -651,6 +657,7 @@ func (s *Server) handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
req.BootstrapDNS = stringutil.FilterOut(req.BootstrapDNS, aghnet.IsCommentOrEmpty)
opts := &upstream.Options{
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeTest),
Timeout: s.conf.UpstreamTimeout,
PreferIPv6: s.conf.BootstrapPreferIPv6,
}

View File

@ -144,6 +144,7 @@ func TestUpstreamConfigValidator(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cv := newUpstreamConfigValidator(tc.general, tc.fallback, tc.private, &upstream.Options{
Logger: testLogger,
Timeout: upsTimeout,
Bootstrap: net.DefaultResolver,
})
@ -195,6 +196,7 @@ func TestUpstreamConfigValidator_Check_once(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cv := newUpstreamConfigValidator(tc.ups, nil, nil, &upstream.Options{
Logger: testLogger,
Timeout: testTimeout,
})

View File

@ -112,6 +112,7 @@ func (clients *clientsContainer) Init(
}
clients.storage, err = client.NewStorage(ctx, &client.StorageConfig{
BaseLogger: baseLogger,
Logger: baseLogger.With(slogutil.KeyPrefix, "client_storage"),
Clock: timeutil.SystemClock{},
InitialClients: confClients,

View File

@ -21,6 +21,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/AdGuardHome/internal/arpdb"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
@ -385,6 +386,7 @@ func setupDNSFilteringConf(
cacheTime := time.Duration(conf.CacheTime) * time.Minute
upsOpts := &upstream.Options{
Logger: aghslog.NewForUpstream(baseLogger, aghslog.UpstreamTypeService),
Timeout: dnsTimeout,
Bootstrap: upstream.StaticResolver{
// 94.140.14.15.

View File

@ -230,8 +230,9 @@ func TestTLSManager_Reload(t *testing.T) {
require.NoError(t, err)
globalContext.clients.storage, err = client.NewStorage(ctx, &client.StorageConfig{
Logger: testLogger,
Clock: timeutil.SystemClock{},
BaseLogger: testLogger,
Logger: testLogger,
Clock: timeutil.SystemClock{},
})
require.NoError(t, err)
@ -492,8 +493,9 @@ func TestTLSManager_HandleTLSConfigure(t *testing.T) {
require.NoError(t, err)
globalContext.clients.storage, err = client.NewStorage(ctx, &client.StorageConfig{
Logger: testLogger,
Clock: timeutil.SystemClock{},
BaseLogger: testLogger,
Logger: testLogger,
Clock: timeutil.SystemClock{},
})
require.NoError(t, err)

View File

@ -14,10 +14,12 @@ import (
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/aghslog"
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/logutil/slogutil"
)
// Service is the AdGuard Home DNS service. A nil *Service is a valid
@ -78,7 +80,7 @@ func New(c *Config) (svc *Service, err error) {
}
upstreams, resolvers, err := addressesToUpstreams(
svc.logger,
svc.logger.With(slogutil.KeyPrefix, aghslog.PrefixDNSProxy),
c.UpstreamServers,
c.BootstrapServers,
c.UpstreamTimeout,
@ -122,8 +124,7 @@ func addressesToUpstreams(
preferIPv6 bool,
) (upstreams []upstream.Upstream, boots []*upstream.UpstreamResolver, err error) {
boots, err = aghnet.ParseBootstraps(bootstraps, &upstream.Options{
// TODO(d.kolyshev): Use consts.
Logger: logger.With("upstream_type", "bootstrap"),
Logger: logger.With(aghslog.KeyUpstreamType, aghslog.UpstreamTypeBootstrap),
Timeout: timeout,
PreferIPv6: preferIPv6,
})
@ -141,7 +142,7 @@ func addressesToUpstreams(
upstreams = make([]upstream.Upstream, len(upsStrs))
for i, upsStr := range upsStrs {
upstreams[i], err = upstream.AddressToUpstream(upsStr, &upstream.Options{
Logger: logger.With("upstream_type", "main"),
Logger: logger.With(aghslog.KeyUpstreamType, aghslog.UpstreamTypeMain),
Bootstrap: bootstrap,
Timeout: timeout,
PreferIPv6: preferIPv6,