Skip to content

Commit cb22ea8

Browse files
committed
fix(dns): polish dual-stack review follow-ups
Signed-off-by: Kevin Glasson <kevinglasson@gmail.com>
1 parent 7fe2cf0 commit cb22ea8

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

docs/service-discovery.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ This configuration will instruct Thanos to discover all endpoints within the `th
9696
--endpoint=dnssrvnoa+_thanosstores._tcp.mycompany.org
9797
```
9898
99-
* `dnsdualstack+` - the domain name after this prefix will be looked up as both A and AAAA queries simultaneously, returning all resolved addresses. This provides dual-stack resilience by resolving both IPv4 and IPv6 addresses, with automatic failover handled by gRPC's built-in health checking. *A port is required for this query type*. This is most useful with `--endpoint-group`, which allows gRPC to manage all resolved addresses as a single logical group with automatic failover. For example:
99+
* `dnsdualstack+` - the domain name after this prefix will be looked up as both A and AAAA queries, returning all resolved addresses. This provides dual-stack resilience by resolving both IPv4 and IPv6 addresses, with automatic failover handled by gRPC's built-in health checking. *A port is required for this query type*. This is most useful with `--endpoint-group`, which allows gRPC to manage all resolved addresses as a single logical group with automatic failover. For example:
100100
101101
```
102102
--endpoint-group=dnsdualstack+stores.thanos.mycompany.org:9090

pkg/discovery/dns/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (s *dnsSD) Resolve(ctx context.Context, name string, qtype QType) ([]string
157157
res = append(res, appendScheme(scheme, net.JoinHostPort(ip.String(), port)))
158158
}
159159
if len(ips) == 0 {
160-
level.Error(s.logger).Log("msg", "failed to lookup IP addresses (dual-stack)", "host", host)
160+
level.Error(s.logger).Log("msg", "found no IP addresses (dual-stack)", "host", host)
161161
}
162162
default:
163163
return nil, errors.Errorf("invalid lookup scheme %q", qtype)

pkg/discovery/dns/resolver_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ type mockHostnameResolver struct {
2121
resultSRVs map[string][]*net.SRV
2222
err error
2323

24-
// Per-network results for LookupIPAddrByNetwork. Key format: "network:host".
2524
resultByNetwork map[string][]net.IPAddr
2625
errByNetwork map[string]error
2726
isNotFound func(error) bool
2827
}
2928

29+
func lookupKey(network, host string) string {
30+
return network + ":" + host
31+
}
32+
3033
func (m mockHostnameResolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error) {
3134
if m.err != nil {
3235
return nil, m.err
@@ -35,7 +38,7 @@ func (m mockHostnameResolver) LookupIPAddr(ctx context.Context, host string) ([]
3538
}
3639

3740
func (m mockHostnameResolver) LookupIPAddrByNetwork(_ context.Context, network, host string) ([]net.IPAddr, error) {
38-
key := network + ":" + host
41+
key := lookupKey(network, host)
3942
if m.errByNetwork != nil {
4043
if err, ok := m.errByNetwork[key]; ok {
4144
return nil, err
@@ -242,8 +245,8 @@ func TestDnsSD_ResolveDualStack(t *testing.T) {
242245
addr: host + ":8080",
243246
resolver: &mockHostnameResolver{
244247
resultByNetwork: map[string][]net.IPAddr{
245-
"ip6:" + host: {{IP: ipv6}},
246-
"ip4:" + host: {{IP: ipv4}},
248+
lookupKey("ip6", host): {{IP: ipv6}},
249+
lookupKey("ip4", host): {{IP: ipv4}},
247250
},
248251
},
249252
expectedResult: []string{"[2001:db8::1]:8080", "192.168.1.1:8080"},
@@ -253,7 +256,7 @@ func TestDnsSD_ResolveDualStack(t *testing.T) {
253256
addr: host + ":8080",
254257
resolver: &mockHostnameResolver{
255258
resultByNetwork: map[string][]net.IPAddr{
256-
"ip6:" + host: {{IP: ipv6}},
259+
lookupKey("ip6", host): {{IP: ipv6}},
257260
},
258261
},
259262
expectedResult: []string{"[2001:db8::1]:8080"},
@@ -263,7 +266,7 @@ func TestDnsSD_ResolveDualStack(t *testing.T) {
263266
addr: host + ":8080",
264267
resolver: &mockHostnameResolver{
265268
resultByNetwork: map[string][]net.IPAddr{
266-
"ip4:" + host: {{IP: ipv4}},
269+
lookupKey("ip4", host): {{IP: ipv4}},
267270
},
268271
},
269272
expectedResult: []string{"192.168.1.1:8080"},
@@ -280,10 +283,10 @@ func TestDnsSD_ResolveDualStack(t *testing.T) {
280283
addr: host + ":8080",
281284
resolver: &mockHostnameResolver{
282285
resultByNetwork: map[string][]net.IPAddr{
283-
"ip4:" + host: {{IP: ipv4}},
286+
lookupKey("ip4", host): {{IP: ipv4}},
284287
},
285288
errByNetwork: map[string]error{
286-
"ip6:" + host: errors.New("network unreachable"),
289+
lookupKey("ip6", host): errors.New("network unreachable"),
287290
},
288291
},
289292
expectedResult: []string{"192.168.1.1:8080"},
@@ -293,10 +296,10 @@ func TestDnsSD_ResolveDualStack(t *testing.T) {
293296
addr: host + ":8080",
294297
resolver: &mockHostnameResolver{
295298
resultByNetwork: map[string][]net.IPAddr{
296-
"ip6:" + host: {{IP: ipv6}},
299+
lookupKey("ip6", host): {{IP: ipv6}},
297300
},
298301
errByNetwork: map[string]error{
299-
"ip4:" + host: errors.New("network unreachable"),
302+
lookupKey("ip4", host): errors.New("network unreachable"),
300303
},
301304
},
302305
expectedResult: []string{"[2001:db8::1]:8080"},
@@ -329,8 +332,8 @@ func TestDnsSD_ResolveDualStack_Errors(t *testing.T) {
329332
t.Run("both families fail propagates error", func(t *testing.T) {
330333
resolver := &mockHostnameResolver{
331334
errByNetwork: map[string]error{
332-
"ip6:" + host: errors.New("network unreachable"),
333-
"ip4:" + host: errors.New("network unreachable"),
335+
lookupKey("ip6", host): errors.New("network unreachable"),
336+
lookupKey("ip4", host): errors.New("network unreachable"),
334337
},
335338
}
336339
dnsSD := dnsSD{resolver, log.NewNopLogger()}
@@ -343,8 +346,8 @@ func TestDnsSD_ResolveDualStack_Errors(t *testing.T) {
343346
notFound := &net.DNSError{Err: "no such host", Name: host, IsNotFound: true}
344347
resolver := &mockHostnameResolver{
345348
errByNetwork: map[string]error{
346-
"ip6:" + host: notFound,
347-
"ip4:" + host: notFound,
349+
lookupKey("ip6", host): notFound,
350+
lookupKey("ip4", host): notFound,
348351
},
349352
isNotFound: func(err error) bool {
350353
dnsErr, ok := err.(*net.DNSError)
@@ -362,8 +365,8 @@ func TestDnsSD_ResolveDualStack_Errors(t *testing.T) {
362365
notFound := &net.DNSError{Err: "no such host", Name: host, IsNotFound: true}
363366
resolver := &mockHostnameResolver{
364367
errByNetwork: map[string]error{
365-
"ip6:" + host: notFound,
366-
"ip4:" + host: errors.New("server misbehaving"),
368+
lookupKey("ip6", host): notFound,
369+
lookupKey("ip4", host): errors.New("server misbehaving"),
367370
},
368371
isNotFound: func(err error) bool {
369372
dnsErr, ok := err.(*net.DNSError)

0 commit comments

Comments
 (0)