From 31c568d0633eb9d81d3a0ff2fe4868514c0a4627 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 29 Nov 2024 09:40:02 +0100 Subject: [PATCH] BREAKING CHANGE: slog: {r => dnsR}aw{Query,Response} (#13) Explicitly scope the rawQuery and rawResponse, which are not general fields but specific of the DNS. This should make it more intuitive to auto-generate a tabular format. While there, upgrade to `rbmk-project/common v0.4.0`. --- go.mod | 2 +- go.sum | 4 ++-- slog.go | 6 +++--- slog_test.go | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index e0f840c..28bc95b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.3 require ( github.com/miekg/dns v1.1.62 - github.com/rbmk-project/common v0.3.0 + github.com/rbmk-project/common v0.4.0 github.com/stretchr/testify v1.9.0 golang.org/x/net v0.31.0 ) diff --git a/go.sum b/go.sum index 94e26ea..e798091 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ= github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rbmk-project/common v0.3.0 h1:g9iX/lg5kvzmgxgr4xbkcCjA2jfazM1zAyLKzLD/3iU= -github.com/rbmk-project/common v0.3.0/go.mod h1:uzrFIJl8SEOpgS2pSeBFLUgqc4D1lIcGk/EYuxkFO0U= +github.com/rbmk-project/common v0.4.0 h1:gw7f/YdPxcUZ81cO9IMzEPDhsc6tOUte1m0OFi6euFg= +github.com/rbmk-project/common v0.4.0/go.mod h1:uzrFIJl8SEOpgS2pSeBFLUgqc4D1lIcGk/EYuxkFO0U= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= diff --git a/slog.go b/slog.go index 24a59de..6f9d27f 100644 --- a/slog.go +++ b/slog.go @@ -33,7 +33,7 @@ func (t *Transport) maybeLogQuery( t.Logger.InfoContext( ctx, "dnsQuery", - slog.Any("rawQuery", rawQuery), + slog.Any("dnsRawQuery", rawQuery), slog.String("serverAddr", addr.Address), slog.String("serverProtocol", string(addr.Protocol)), slog.Time("t", t0), @@ -59,8 +59,8 @@ func (t *Transport) maybeLogResponseAddrPort(ctx context.Context, ctx, "dnsResponse", slog.String("localAddr", laddr.String()), - slog.Any("rawQuery", rawQuery), - slog.Any("rawResponse", rawResp), + slog.Any("dnsRawQuery", rawQuery), + slog.Any("dnsRawResponse", rawResp), slog.String("remoteAddr", raddr.String()), slog.String("serverAddr", addr.Address), slog.String("serverProtocol", string(addr.Protocol)), diff --git a/slog_test.go b/slog_test.go index 20aa098..56981d0 100644 --- a/slog_test.go +++ b/slog_test.go @@ -82,7 +82,7 @@ func TestTransport_maybeLogQuery(t *testing.T) { })) }, expectTime: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), - expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsQuery\",\"rawQuery\":\"AAAAAA==\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t\":\"2020-01-01T00:00:00Z\"}\n", + expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsQuery\",\"dnsRawQuery\":\"AAAAAA==\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t\":\"2020-01-01T00:00:00Z\"}\n", }, { @@ -140,7 +140,7 @@ func TestTransport_maybeLogResponseAddrPort(t *testing.T) { }, laddr: netip.MustParseAddrPort("[2001:db8::1]:1234"), raddr: netip.MustParseAddrPort("[2001:db8::2]:443"), - expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[2001:db8::1]:1234\",\"rawQuery\":\"AAAAAA==\",\"rawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[2001:db8::2]:443\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", + expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[2001:db8::1]:1234\",\"dnsRawQuery\":\"AAAAAA==\",\"dnsRawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[2001:db8::2]:443\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", }, { @@ -158,7 +158,7 @@ func TestTransport_maybeLogResponseAddrPort(t *testing.T) { }, laddr: netip.AddrPort{}, // invalid raddr: netip.AddrPort{}, // invalid - expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[::]:0\",\"rawQuery\":\"AAAAAA==\",\"rawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[::]:0\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", + expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[::]:0\",\"dnsRawQuery\":\"AAAAAA==\",\"dnsRawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[::]:0\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", }, { @@ -233,7 +233,7 @@ func TestTransport_maybeLogResponseConn(t *testing.T) { } }, }, - expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[2001:db8::1]:1234\",\"rawQuery\":\"AAAAAA==\",\"rawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[2001:db8::2]:443\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", + expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[2001:db8::1]:1234\",\"dnsRawQuery\":\"AAAAAA==\",\"dnsRawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[2001:db8::2]:443\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", }, { @@ -257,7 +257,7 @@ func TestTransport_maybeLogResponseConn(t *testing.T) { return &net.UnixAddr{Name: "/tmp/remote.sock", Net: "unix"} }, }, - expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[::]:0\",\"rawQuery\":\"AAAAAA==\",\"rawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[::]:0\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", + expectLog: "{\"level\":\"INFO\",\"msg\":\"dnsResponse\",\"localAddr\":\"[::]:0\",\"dnsRawQuery\":\"AAAAAA==\",\"dnsRawResponse\":\"AQEBAQ==\",\"remoteAddr\":\"[::]:0\",\"serverAddr\":\"8.8.8.8:53\",\"serverProtocol\":\"udp\",\"t0\":\"2020-01-01T00:00:00Z\",\"t\":\"2020-01-01T00:00:11Z\"}\n", }, {