feat: collect system resolver results using context (#856)

* feat: Introduce context-based tracing to the system resolver

* testing: added tests for context-based tracing in netxlite resolvers

* Apply suggestions from code review

Reference issue: https://github.com/ooni/probe/issues/2207

Co-authored-by: decfox <decfox@github.com>
Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
DecFox 2022-08-11 13:50:28 +05:30 committed by GitHub
commit 576b52b1e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 347 additions and 2 deletions

View file

@ -130,11 +130,17 @@ var _ model.Resolver = &resolverSystem{}
func (r *resolverSystem) LookupHost(ctx context.Context, hostname string) ([]string, error) {
encoder := &DNSEncoderMiekg{}
query := encoder.Encode(hostname, dns.TypeANY, false)
trace := ContextTraceOrDefault(ctx)
start := trace.TimeNow()
resp, err := r.t.RoundTrip(ctx, query)
end := trace.TimeNow()
if err != nil {
return nil, err
trace.OnDNSRoundTripForLookupHost(start, r, query, resp, []string{}, err, end)
return []string{}, err
}
return resp.DecodeLookupHost()
addrs, err := resp.DecodeLookupHost()
trace.OnDNSRoundTripForLookupHost(start, r, query, resp, addrs, err, end)
return addrs, err
}
func (r *resolverSystem) Network() string {