Skip to content

Commit

Permalink
fix: only add rcode label when no err was returned
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 080fbb4 commit 8a2c341
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,9 @@ 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, rcodeStr)).Inc()

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

l.l.Errorw("dns lookup failed",
Expand All @@ -232,6 +225,14 @@ func (l *lookuper) start(interval time.Duration) {
continue
}

rcodeStr, ok := dns.RcodeToString[msg.Rcode]

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

metrics.GetOrCreateCounter(fmt.Sprintf("%s{%s,rcode=%q}",
dnsLookupTotalName, l.labels, rcodeStr)).Inc()
metrics.GetOrCreateHistogram(fmt.Sprintf("%s{%s}",
dnsDurationName, l.labels)).Update(rtt.Seconds())

Expand Down

0 comments on commit 8a2c341

Please sign in to comment.