MCPcopy
hub / github.com/grafana/dskit / NewResolverWithClient

Function NewResolverWithClient

dns/miekgdns/resolver.go:71–90  ·  view source on GitHub ↗

NewResolverWithClient creates a new Resolver that uses the provided resolv.conf configuration, reload period, and Client implementation to perform DNS queries. Configuration from resolv.conf will be periodically reloaded.

(resolvConf string, logger log.Logger, reloadPeriod time.Duration, client Client)

Source from the content-addressed store, hash-verified

69// reload period, and Client implementation to perform DNS queries. Configuration from resolv.conf
70// will be periodically reloaded.
71func NewResolverWithClient(resolvConf string, logger log.Logger, reloadPeriod time.Duration, client Client) *Resolver {
72 r := &Resolver{
73 client: client,
74 logger: logger,
75 confPath: resolvConf,
76 reloadPeriod: reloadPeriod,
77 stop: make(chan struct{}),
78 }
79
80 // Attempt an initial load of the configuration but fallback to defaults if it fails. The file
81 // missing should not be fatal according to `man 5 resolv.conf`.
82 if err := r.loadConfig(); err != nil {
83 level.Warn(r.logger).Log("msg", "unable to load resolv.conf, using default values", "path", r.confPath, "err", err)
84 r.conf = defaultClientConfig()
85 }
86
87 // Attempt to reload configuration periodically. If the reloads fail, old values are used.
88 go r.loop()
89 return r
90}
91
92// Stop stops periodic tasks run by the Resolver. The resolver should not be used after it is stopped.
93func (r *Resolver) Stop() {

Callers 4

TestResolver_LookupSRVFunction · 0.85
TestResolver_LookupIPFunction · 0.85
NewResolverFunction · 0.85

Calls 4

loadConfigMethod · 0.95
loopMethod · 0.95
defaultClientConfigFunction · 0.85
LogMethod · 0.45

Tested by 3

TestResolver_LookupSRVFunction · 0.68
TestResolver_LookupIPFunction · 0.68