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 6 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#5641](https://github.com/thanos-io/thanos/pull/5641) Store: Remove hardcoded labels in shard matcher.
- [#5641](https://github.com/thanos-io/thanos/pull/5641) Query: Inject unshardable le label in query analyzer.
- [#5685](https://github.com/thanos-io/thanos/pull/5685) Receive: Make active/head series limiting configuration per tenant by adding it to new limiting config.
- [#5716](https://github.com/thanos-io/thanos/pull/5716) DNS: Fix miekgdns resolver LookupSRV to work with CNAME records.

### Removed

Expand Down
15 changes: 15 additions & 0 deletions pkg/discovery/dns/miekgdns/resolver.go
Original file line number Diff line number Diff line change
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