Closed mohshami closed 7 months ago
I got the idea and it does make sense, but I'd suggest implement it differently.
Make a new struct, something like this:
type JSONMsg struct {
Query *dns.Msg `json:"query"`
Message *dns.Msg `json:"response"`
Elapsed time.Duration `json:"elapsed"`
}
Fill it with the necessary information and serialize to JSON.
It won't be backwards-compatible, but it will be pretty :)
Thank you so much.
Yeah my golang-fu isn't any good :)
While working the change you requested I thought of looking at the upstream code and I had an idea, the updated code now uses a struct like you mentioned but is also backwards compatible.
Thanks again :)
Please check out the linter warnings and once they're fixed it'll be good to merge.
Thank you so much, JSONMsg renamed to jsonMsg so it's unexported
First I would love to say thank you for this wonderful tool. I use it all the time.
One thing I use it for is to do health checks on our caching resolvers, and something I wanted to do was to monitor how long those queries took. But noticed ElapsedTime is only available in the human readable output.
Please forgive me as the last meaningful Go that I wrote was in 2018, and even then my Go skills were quite limited.
My first instinct was to modify the output string slice before printing as follows
But I didn't feel comfortable editing formatted JSON, because it could conflict with future changes. So I went with the sjson package as follows
After that I ended up dropping the sjson requirement, editing compact JSON directly and then formatting the JSON output.
Also, one thing I wanted to monitor was plain DNS-over-TCP, which my script used dig for since I didn't know it was supported by dnslookup. But when when I saw https://pkg.go.dev/github.com/AdguardTeam/dnsproxy/upstream#AddressToUpstream I realized it was possible and after testing it does indeed work. So I thought it would be a good idea to expose it in the README