diff --git a/prober/dns.go b/prober/dns.go index 6bf2e465..4e1033b4 100644 --- a/prober/dns.go +++ b/prober/dns.go @@ -253,11 +253,13 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry } } + queryName := internationalizeDNSDomain(logger, module.DNS.QueryName) + msg := new(dns.Msg) msg.Id = dns.Id() msg.RecursionDesired = module.DNS.Recursion msg.Question = make([]dns.Question, 1) - msg.Question[0] = dns.Question{dns.Fqdn(module.DNS.QueryName), qt, qc} + msg.Question[0] = dns.Question{dns.Fqdn(queryName), qt, qc} level.Info(logger).Log("msg", "Making DNS query", "target", targetIP, "dial_protocol", dialProtocol, "query", module.DNS.QueryName, "type", qt, "class", qc) timeoutDeadline, _ := ctx.Deadline() diff --git a/prober/http.go b/prober/http.go index 232214c3..900fedab 100644 --- a/prober/http.go +++ b/prober/http.go @@ -319,7 +319,7 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr return false } - targetHost := targetURL.Hostname() + targetHost := internationalizeDNSDomain(logger, targetURL.Hostname()) targetPort := targetURL.Port() var ip *net.IPAddr diff --git a/prober/utils.go b/prober/utils.go index cde1f3ed..05bcf068 100644 --- a/prober/utils.go +++ b/prober/utils.go @@ -22,6 +22,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" + "golang.org/x/net/idna" "github.com/prometheus/client_golang/prometheus" ) @@ -60,6 +61,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b fallbackProtocol = "ip6" } + target = internationalizeDNSDomain(logger, target) level.Info(logger).Log("msg", "Resolving target address", "target", target, "ip_protocol", IPProtocol) resolveStart := time.Now() @@ -142,3 +144,18 @@ func ipHash(ip net.IP) float64 { } return float64(h.Sum32()) } + +func internationalizeDNSDomain(logger log.Logger, domain string) string { + if net.ParseIP(domain) != nil { + // IP addresses don't need to be internationalized. + return domain + } + idnaDomain, err := idna.Lookup.ToASCII(domain) + if err != nil { + return domain + } + if idnaDomain != domain { + level.Info(logger).Log("msg", "Domain internationalized", "unicode", domain, "ascii", idnaDomain) + } + return idnaDomain +} diff --git a/prober/utils_test.go b/prober/utils_test.go index 1b1c41dc..6918668f 100644 --- a/prober/utils_test.go +++ b/prober/utils_test.go @@ -252,3 +252,23 @@ func checkMetrics(expected map[string]map[string]map[string]struct{}, mfs []*dto } } } + +func TestChooseProtocolIDNA(t *testing.T) { + if testing.Short() { + t.Skip("skipping network dependent test") + } + var ( + ctx = context.Background() + registry = prometheus.NewPedanticRegistry() + w = log.NewSyncWriter(os.Stderr) + logger = log.NewLogfmtLogger(w) + ) + + ip, _, err := chooseProtocol(ctx, "ip4", true, "www.académie-française.fr", registry, logger) + if err != nil { + t.Error(err) + } + if ip == nil || ip.IP.To4() == nil { + t.Error("it should answer") + } +}