Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require (
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand Down
4 changes: 4 additions & 0 deletions src/go/plugin/go.d/collector/dnsquery/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (c *Collector) Init(context.Context) error {
return fmt.Errorf("config validation: %v", err)
}

if err := c.initServers(); err != nil {
return fmt.Errorf("failed to initialize servers: %v", err)
}

rt, err := c.initRecordTypes()
if err != nil {
return fmt.Errorf("init record type: %v", err)
Expand Down
11 changes: 0 additions & 11 deletions src/go/plugin/go.d/collector/dnsquery/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ func TestCollector_Init(t *testing.T) {
Timeout: confopt.Duration(time.Second),
},
},
"fail when servers not set": {
wantFail: true,
config: Config{
Domains: []string{"example.com"},
Servers: nil,
Network: "udp",
RecordTypes: []string{"A"},
Port: 53,
Timeout: confopt.Duration(time.Second),
},
},
"fail when network is invalid": {
wantFail: true,
config: Config{
Expand Down
6 changes: 2 additions & 4 deletions src/go/plugin/go.d/collector/dnsquery/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"servers": {
"title": "Servers",
"description": "List of DNS servers to query.",
"description": "List of DNS servers to query. If empty, the collector will automatically use DNS servers from `/etc/resolv.conf`.",
"type": [
"array",
"null"
Expand All @@ -78,8 +78,7 @@
"default": [
"8.8.8.8"
],
"uniqueItems": true,
"minItems": 1
"uniqueItems": true
},
"domains": {
"title": "Domains",
Expand Down Expand Up @@ -107,7 +106,6 @@
},
"required": [
"domains",
"servers",
"network"
],
"patternProperties": {
Expand Down
22 changes: 18 additions & 4 deletions src/go/plugin/go.d/collector/dnsquery/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ func (c *Collector) verifyConfig() error {
return errors.New("no domains specified")
}

if len(c.Servers) == 0 {
return errors.New("no servers specified")
}

if !(c.Network == "" || c.Network == "udp" || c.Network == "tcp" || c.Network == "tcp-tls") {
return fmt.Errorf("wrong network transport : %s", c.Network)
}
Expand All @@ -36,6 +32,24 @@ func (c *Collector) verifyConfig() error {
return nil
}

func (c *Collector) initServers() error {
if len(c.Servers) != 0 {
return nil
}
servers, err := getResolvConfNameservers()
if err != nil {
return err
}
if len(servers) == 0 {
return errors.New("no resolv conf nameservers")
}

c.Debugf("resolv conf nameservers: %v", servers)
c.Servers = servers

return nil
}

func (c *Collector) initRecordTypes() (map[string]uint16, error) {
types := make(map[string]uint16)
for _, v := range c.RecordTypes {
Expand Down
20 changes: 16 additions & 4 deletions src/go/plugin/go.d/collector/dnsquery/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ modules:
default_value: ""
required: true
- name: servers
description: Servers to query.
description: Servers to query. If empty, the collector will automatically use DNS servers from `/etc/resolv.conf`.
default_value: ""
required: true
required: false
- name: port
description: DNS server port.
default_value: 53
Expand All @@ -86,8 +86,8 @@ modules:
title: Config
enabled: true
list:
- name: Basic
description: An example configuration.
- name: Specific DNS servers
description: An example configuration using Google's public DNS servers.
config: |
jobs:
- name: job1
Expand All @@ -101,6 +101,18 @@ modules:
servers:
- 8.8.8.8
- 8.8.4.4
- name: System DNS
description: An example configuration using DNS servers from `/etc/resolv.conf`.
config: |
jobs:
- name: job1
record_types:
- A
- AAAA
domains:
- google.com
- github.com
- reddit.com
troubleshooting:
problems:
list: []
Expand Down
16 changes: 16 additions & 0 deletions src/go/plugin/go.d/collector/dnsquery/resolvconf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dnsquery

import (
"os"

"github.com/docker/docker/libnetwork/resolvconf"
)

func getResolvConfNameservers() ([]string, error) {
path := resolvconf.Path()
bs, err := os.ReadFile(path)
if err != nil {
return nil, err
}
return resolvconf.GetNameservers(bs, resolvconf.IP), nil
}
Loading