From f1c5fa9753e522523a24bd7caea55fec212118ea Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 9 Jul 2020 00:27:54 +0200 Subject: [PATCH] Fix tests Signed-off-by: Julien Pivotto --- prober/dns.go | 8 ++------ prober/utils.go | 18 +++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/prober/dns.go b/prober/dns.go index cf6a36d8..121d8627 100644 --- a/prober/dns.go +++ b/prober/dns.go @@ -209,17 +209,13 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry } } - idnTarget, err := internationalizeDNSTarget(logger, module.DNS.QueryName) - if err != nil { - level.Error(logger).Log("msg", "IDN conversion failed", "err", err) - return false - } + queryName := internationalizeDNSDomain(logger, module.DNS.QueryName) msg := new(dns.Msg) msg.Id = dns.Id() msg.RecursionDesired = true msg.Question = make([]dns.Question, 1) - msg.Question[0] = dns.Question{dns.Fqdn(idnTarget), qt, qc} + msg.Question[0] = dns.Question{dns.Fqdn(queryName), qt, qc} level.Info(logger).Log("msg", "Making DNS query", "target", target, "dial_protocol", dialProtocol, "query", module.DNS.QueryName, "type", qt, "class", qc) timeoutDeadline, _ := ctx.Deadline() client.Timeout = time.Until(timeoutDeadline) diff --git a/prober/utils.go b/prober/utils.go index 31b5b441..b585f6b5 100644 --- a/prober/utils.go +++ b/prober/utils.go @@ -56,11 +56,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b fallbackProtocol = "ip6" } - target, err = internationalizeDNSTarget(logger, target) - if err != nil { - level.Error(logger).Log("msg", "IDN conversion failed", "err", err) - return nil, 0.0, err - } + target = internationalizeDNSDomain(logger, target) level.Info(logger).Log("msg", "Resolving target address", "ip_protocol", IPProtocol) resolveStart := time.Now() @@ -127,13 +123,13 @@ func ipHash(ip net.IP) float64 { return float64(h.Sum32()) } -func internationalizeDNSTarget(logger log.Logger, target string) (string, error) { - idnaTarget, err := idna.Lookup.ToASCII(target) +func internationalizeDNSDomain(logger log.Logger, domain string) string { + idnaDomain, err := idna.Lookup.ToASCII(domain) if err != nil { - return target, fmt.Errorf("error while internationalizing target: %w", err) + return domain } - if idnaTarget != target { - level.Info(logger).Log("msg", "Target address internationalized", "ascii", idnaTarget) + if idnaDomain != domain { + level.Info(logger).Log("msg", "Domain internationalized", "unicode", domain, "ascii", idnaDomain) } - return idnaTarget, nil + return idnaDomain }