mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
discovery: Instead of looping over conf.Search, use NameList()
This commit is contained in:
parent
e7ce10d4e5
commit
865f28bb15
|
@ -179,13 +179,12 @@ func lookupAll(name string, qtype uint16) (*dns.Msg, error) {
|
||||||
|
|
||||||
for _, server := range conf.Servers {
|
for _, server := range conf.Servers {
|
||||||
servAddr := net.JoinHostPort(server, conf.Port)
|
servAddr := net.JoinHostPort(server, conf.Port)
|
||||||
for _, suffix := range conf.Search {
|
for _, lname := range conf.NameList(name) {
|
||||||
response, err = lookup(name, qtype, client, servAddr, suffix, false)
|
response, err = lookup(lname, qtype, client, servAddr, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.
|
log.
|
||||||
With("server", server).
|
With("server", server).
|
||||||
With("name", name).
|
With("name", name).
|
||||||
With("suffix", suffix).
|
|
||||||
With("reason", err).
|
With("reason", err).
|
||||||
Warn("DNS resolution failed.")
|
Warn("DNS resolution failed.")
|
||||||
continue
|
continue
|
||||||
|
@ -194,22 +193,12 @@ func lookupAll(name string, qtype uint16) (*dns.Msg, error) {
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response, err = lookup(name, qtype, client, servAddr, "", false)
|
|
||||||
if err == nil {
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
log.
|
|
||||||
With("server", server).
|
|
||||||
With("name", name).
|
|
||||||
With("reason", err).
|
|
||||||
Warn("DNS resolution failed.")
|
|
||||||
}
|
}
|
||||||
return response, fmt.Errorf("could not resolve %s: no server responded", name)
|
return response, fmt.Errorf("could not resolve %s: no server responded", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookup(name string, queryType uint16, client *dns.Client, servAddr string, suffix string, edns bool) (*dns.Msg, error) {
|
func lookup(lname string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) {
|
||||||
msg := &dns.Msg{}
|
msg := &dns.Msg{}
|
||||||
lname := strings.Join([]string{name, suffix}, ".")
|
|
||||||
msg.SetQuestion(dns.Fqdn(lname), queryType)
|
msg.SetQuestion(dns.Fqdn(lname), queryType)
|
||||||
|
|
||||||
if edns {
|
if edns {
|
||||||
|
@ -224,7 +213,7 @@ func lookup(name string, queryType uint16, client *dns.Client, servAddr string,
|
||||||
if edns { // Truncated even though EDNS is used
|
if edns { // Truncated even though EDNS is used
|
||||||
client.Net = "tcp"
|
client.Net = "tcp"
|
||||||
}
|
}
|
||||||
return lookup(name, queryType, client, servAddr, suffix, !edns)
|
return lookup(lname, queryType, client, servAddr, !edns)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue