feat(inputs.dns_query): Allow ignoring errors of specific types (#14992)
This commit is contained in:
parent
f8905b270a
commit
f9b1251058
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -20,6 +21,10 @@ import (
|
|||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
var ignoredErrors = []string{
|
||||
"NXDOMAIN",
|
||||
}
|
||||
|
||||
type ResultType uint64
|
||||
|
||||
const (
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.")
|
||||
|
|
|
|||
Loading…
Reference in New Issue