all: imp code

This commit is contained in:
Dimitry Kolyshev 2025-07-03 09:59:28 +04:00
parent c9440af9a5
commit 88b5398c8b
5 changed files with 21 additions and 28 deletions

View File

@ -1,6 +1,12 @@
// 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"
@ -38,3 +44,9 @@ const (
// testing.
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

@ -143,10 +143,9 @@ func (m *upstreamManager) customUpstreamConfig(
}
}
cliLogger := m.baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeCustom,
aghslog.KeyClientName, clientName,
cliLogger := aghslog.NewForUpstream(m.baseLogger, aghslog.UpstreamTypeCustom).With(
aghslog.KeyClientName,
clientName,
)
proxyConf = newCustomUpstreamConfig(cliConf, m.commonConf, cliLogger)
cliConf.proxyConf = proxyConf

View File

@ -547,10 +547,7 @@ func (s *Server) prepareUpstreamSettings(boot upstream.Resolver) (err error) {
}
uc, err := newUpstreamConfig(upstreams, defaultDNS, &upstream.Options{
Logger: s.baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeMain,
),
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeMain),
Bootstrap: boot,
Timeout: s.conf.UpstreamTimeout,
HTTPVersions: aghnet.UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams),
@ -617,10 +614,7 @@ func (s *Server) prepareLocalResolvers() (uc *proxy.UpstreamConfig, err error) {
}
opts := &upstream.Options{
Logger: s.baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeLocal,
),
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeLocal),
Bootstrap: s.bootstrap,
Timeout: defaultLocalTimeout,
// TODO(e.burkov): Should we verify server's certificates?
@ -653,10 +647,7 @@ func (s *Server) prepareInternalDNS() (err error) {
}
bootOpts := &upstream.Options{
Logger: s.baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeBootstrap,
),
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeBootstrap),
Timeout: DefaultTimeout,
HTTPVersions: aghnet.UpstreamHTTPVersions(s.conf.UseHTTP3Upstreams),
}
@ -695,10 +686,7 @@ func (s *Server) setupFallbackDNS() (uc *proxy.UpstreamConfig, err error) {
}
uc, err = proxy.ParseUpstreamsConfig(fallbacks, &upstream.Options{
Logger: s.baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeFallback,
),
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeFallback),
// TODO(s.chzhen): Investigate if other options are needed.
Timeout: s.conf.UpstreamTimeout,
PreferIPv6: s.conf.BootstrapPreferIPv6,

View File

@ -657,10 +657,7 @@ func (s *Server) handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
req.BootstrapDNS = stringutil.FilterOut(req.BootstrapDNS, aghnet.IsCommentOrEmpty)
opts := &upstream.Options{
Logger: s.baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeTest,
),
Logger: aghslog.NewForUpstream(s.baseLogger, aghslog.UpstreamTypeTest),
Timeout: s.conf.UpstreamTimeout,
PreferIPv6: s.conf.BootstrapPreferIPv6,
}

View File

@ -384,10 +384,7 @@ func setupDNSFilteringConf(
cacheTime := time.Duration(conf.CacheTime) * time.Minute
upsOpts := &upstream.Options{
Logger: baseLogger.With(
slogutil.KeyPrefix, aghslog.PrefixDNSProxy,
aghslog.KeyUpstreamType, aghslog.UpstreamTypeService,
),
Logger: aghslog.NewForUpstream(baseLogger, aghslog.UpstreamTypeService),
Timeout: dnsTimeout,
Bootstrap: upstream.StaticResolver{
// 94.140.14.15.