From f796fe3cdca2403218cd9aecf0680479d50181db Mon Sep 17 00:00:00 2001 From: verejoel Date: Thu, 27 Jun 2024 23:07:49 -1000 Subject: [PATCH] Remove trailing period from SRV records Recently ran into an issue with Istio in particular, where leaving the trailing dot on the SRV record returned by `dnssrvnoa` lookups led to an inability to connect to the endpoint. Removing the trailing dot fixes this behaviour. Now, technically, this is a valid URL, and it shouldn't be a problem. One could definitely argue that Istio should be responsible here for ensuring that the traffic is delivered. The problem seems rooted in how Istio attempts to do wildcard matching or URLs it receives - including the dot leads it to lookup an empty DNS field, which is invalid. The approach I take here is actually copied from how Prometheus does it. Therefore I hope we can sneak this through with the argument that 'this is how Prometheus does it', regardless of whether or not this is philosophically correct... Signed-off-by: verejoel --- CHANGELOG.md | 2 ++ pkg/discovery/dns/resolver.go | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9be4cdf26..e1188b6e27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Changed +- [#7494](https://github.com/thanos-io/thanos/pull/7494) Ruler: remove trailing period from SRV records returned by discovery `dnsnosrva` lookups + ### Removed ## [v0.36.0](https://github.com/thanos-io/thanos/tree/release-0.36) - in progress diff --git a/pkg/discovery/dns/resolver.go b/pkg/discovery/dns/resolver.go index d0078aea57..0025178607 100644 --- a/pkg/discovery/dns/resolver.go +++ b/pkg/discovery/dns/resolver.go @@ -108,7 +108,9 @@ func (s *dnsSD) Resolve(ctx context.Context, name string, qtype QType) ([]string } if qtype == SRVNoA { - res = append(res, appendScheme(scheme, net.JoinHostPort(rec.Target, resPort))) + // Remove the final dot from rooted DNS names (this is for compatibility with Prometheus) + target := strings.TrimRight(rec.Target, ".") + res = append(res, appendScheme(scheme, net.JoinHostPort(target, resPort))) continue } // Do A lookup for the domain in SRV answer.