Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Fix miekgdns resolver LookupSRV function to work with CNAME records too #5716

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Changed

- [#5716](https://github.com/thanos-io/thanos/pull/5716) DNS: Fix miekgdns resolver LookupSRV to work with CNAME records.

### Removed

- [#5824](https://github.com/thanos-io/thanos/pull/5824) Mixin: Remove noisy `ThanosReceiveTrafficBelowThreshold` alert.
Expand Down
15 changes: 15 additions & 0 deletions pkg/discovery/dns/miekgdns/resolver.go
Expand Up @@ -20,6 +20,14 @@ type Resolver struct {
}

func (r *Resolver) LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error) {
return r.lookupSRV(service, proto, name, 1, 8)
}

func (r *Resolver) lookupSRV(service, proto, name string, currIteration, maxIterations int) (cname string, addrs []*net.SRV, err error) {
Atharva-Shinde marked this conversation as resolved.
Show resolved Hide resolved
// We want to protect from infinite loops when resolving DNS records recursively.
if currIteration > maxIterations {
return "", nil, errors.Errorf("maximum number of recursive iterations reached (%d)", maxIterations)
}
var target string
if service == "" && proto == "" {
target = name
Expand All @@ -41,6 +49,13 @@ func (r *Resolver) LookupSRV(ctx context.Context, service, proto, name string) (
Priority: addr.Priority,
Port: addr.Port,
})
case *dns.CNAME:
// Recursively resolve it.
_, resp, err := r.lookupSRV("", "", addr.Target, currIteration+1, maxIterations)
if err != nil {
return "", nil, errors.Wrapf(err, "recursively resolve %s", addr.Target)
}
addrs = append(addrs, resp...)
default:
return "", nil, errors.Errorf("invalid SRV response record %s", record)
}
Expand Down