Skip to content

Commit

Permalink
BREAKING CHANGE: slog: {r => dnsR}aw{Query,Response} (#13)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bassosimone authored Nov 29, 2024
1 parent 55a1286 commit 31c568d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)),
Expand Down
10 changes: 5 additions & 5 deletions slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

{
Expand Down Expand Up @@ -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",
},

{
Expand All @@ -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",
},

{
Expand Down Expand Up @@ -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",
},

{
Expand All @@ -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",
},

{
Expand Down

0 comments on commit 31c568d

Please sign in to comment.