Skip to content

Commit

Permalink
proxy: slog
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Jun 18, 2024
1 parent da68b56 commit 22e1bb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
21 changes: 16 additions & 5 deletions proxy/proxycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"
"slices"

"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/logutil/slogutil"
)

// cacheForContext returns cache object for the given context.
Expand Down Expand Up @@ -45,7 +45,11 @@ func (p *Proxy) replyFromCache(d *DNSContext) (hit bool) {
d.Res = ci.m
d.CachedUpstreamAddr = ci.u

log.Debug("dnsproxy: cache: %s", hitMsg)
p.logger.With(slogutil.KeyPrefix, CacheLogPrefix).Debug(
"replying from cache",
"details",
hitMsg,
)

if dctxCache.optimistic && expired {
// Build a reduced clone of the current context to avoid data race.
Expand Down Expand Up @@ -103,7 +107,11 @@ func (p *Proxy) cacheResp(d *DNSContext) {
// TODO(a.meshkov): The whole response MUST be dropped if ECS in it
// doesn't correspond.
if !ecs.IP.Mask(ecs.Mask).Equal(d.ReqECS.IP.Mask(d.ReqECS.Mask)) || ones != reqOnes {
log.Debug("dnsproxy: cache: bad response: ecs %s does not match %s", ecs, d.ReqECS)
p.logger.With(slogutil.KeyPrefix, CacheLogPrefix).Debug(
"bad response; ecs does not match",
"ecs", ecs,
"req_ecs", d.ReqECS,
)

return
}
Expand All @@ -118,7 +126,10 @@ func (p *Proxy) cacheResp(d *DNSContext) {
ecs.IP = ecs.IP.Mask(ecs.Mask)
}

log.Debug("dnsproxy: cache: ecs option in response: %s", ecs)
p.logger.With(slogutil.KeyPrefix, CacheLogPrefix).Debug(
"ecs option in response",
"ecs", ecs,
)

dctxCache.setWithSubnet(d.Res, d.Upstream, ecs)
case d.ReqECS != nil:
Expand All @@ -135,6 +146,6 @@ func (p *Proxy) ClearCache() {
if p.cache != nil {
p.cache.clearItems()
p.cache.clearItemsWithSubnet()
log.Debug("dnsproxy: cache: cleared")
p.logger.With(slogutil.KeyPrefix, CacheLogPrefix).Debug("cleared")
}
}
3 changes: 1 addition & 2 deletions proxy/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"slices"
"time"

"github.com/AdguardTeam/golibs/log"
rate "github.com/beefsack/go-rate"
gocache "github.com/patrickmn/go-cache"
)
Expand Down Expand Up @@ -53,7 +52,7 @@ func (p *Proxy) isRatelimited(addr netip.Addr) (ok bool) {
value := p.limiterForIP(ipStr)
rl, ok := value.(*rate.RateLimiter)
if !ok {
log.Error("dnsproxy: %T found in ratelimit cache", value)
p.logger.Error("bad type found in ratelimit cache", "value", value)

return false
}
Expand Down
5 changes: 3 additions & 2 deletions proxy/recursiondetector_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package proxy
import (
"bytes"
"encoding/binary"
"log/slog"
"testing"
"time"

"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/netutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -177,7 +178,7 @@ func msgToSignatureSlow(msg *dns.Msg) (sig []byte) {
}
copy(signature.name[:], q.Name)
if err := binary.Write(b, binary.BigEndian, signature); err != nil {
log.Debug("writing message signature: %s", err)
slog.Default().Debug("writing message signature", slogutil.KeyError, err)
}

return b.Bytes()
Expand Down

0 comments on commit 22e1bb2

Please sign in to comment.