Skip to content

Commit

Permalink
fix(inputs.dns_query): Omit certain errors from logs
Browse files Browse the repository at this point in the history
fixes: #14941
  • Loading branch information
powersj committed Mar 19, 2024
1 parent d934158 commit 534df73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion plugins/inputs/dns_query/dns_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net"
"slices"
"strconv"
"sync"
"time"
Expand All @@ -20,6 +21,10 @@ import (
//go:embed sample.conf
var sampleConfig string

var ignoredErrors = []string{
"NXDOMAIN",
}

type ResultType uint64

const (
Expand Down Expand Up @@ -87,7 +92,7 @@ func (d *DNSQuery) Gather(acc telegraf.Accumulator) error {
defer wg.Done()

fields, tags, err := d.query(domain, server)
if err != nil {
if err != nil && !slices.Contains(ignoredErrors, tags["rcode"]) {
var opErr *net.OpError
if !errors.As(err, &opErr) || !opErr.Timeout() {
acc.AddError(err)
Expand Down
17 changes: 17 additions & 0 deletions plugins/inputs/dns_query/dns_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ func TestGathering(t *testing.T) {
require.NotEqual(t, float64(0), queryTime)
}

func TestGatherInvalid(t *testing.T) {
if testing.Short() {
t.Skip("Skipping network-dependent test in short mode.")
}

dnsConfig := DNSQuery{
Servers: servers,
Domains: []string{"qwerty123.example.com"},
Timeout: config.Duration(1 * time.Second),
}

var acc testutil.Accumulator
require.NoError(t, dnsConfig.Init())
require.NoError(t, dnsConfig.Gather(&acc))
require.Empty(t, acc.Errors)
}

func TestGatheringMxRecord(t *testing.T) {
if testing.Short() {
t.Skip("Skipping network-dependent test in short mode.")
Expand Down

0 comments on commit 534df73

Please sign in to comment.