Skip to content

Commit

Permalink
fix: log rcode as hex if not in RcodeToString map
Browse files Browse the repository at this point in the history
Signed-off-by: Clément Nussbaumer <clement.nussbaumer@postfinance.ch>
  • Loading branch information
clementnuss committed Mar 8, 2023
1 parent af24fd1 commit f531f2d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,14 @@ func (l *lookuper) start(interval time.Duration) {
m := new(dns.Msg)
m.SetQuestion(fmt.Sprintf("%s.", l.host), dns.TypeA)
msg, rtt, err := l.c.Exchange(m, l.dnsServer.address)
rcodeStr, ok := dns.RcodeToString[msg.Rcode]

if !ok { // rcode not known in table.
rcodeStr = fmt.Sprintf("%#x", msg.Rcode)
}

metrics.GetOrCreateCounter(fmt.Sprintf("%s{%s,rcode=%q}",
dnsLookupTotalName, l.labels, dns.RcodeToString[msg.Rcode])).Inc()
dnsLookupTotalName, l.labels, rcodeStr)).Inc()

if err != nil {
metrics.GetOrCreateCounter(fmt.Sprintf("%s{%s}", dnsErrorsTotalName, l.labels)).Inc()
Expand Down

0 comments on commit f531f2d

Please sign in to comment.