@@ -22,7 +22,7 @@ use anyhow::{anyhow, Context};
22
22
use crossbeam:: channel:: { unbounded, Receiver , Sender } ;
23
23
use mz_ore:: collections:: CollectionExt ;
24
24
use mz_ore:: error:: ErrorExt ;
25
- use mz_ore:: netio:: resolve_external_address ;
25
+ use mz_ore:: netio:: resolve_address ;
26
26
use mz_ssh_util:: tunnel:: { SshTimeoutConfig , SshTunnelConfig , SshTunnelStatus } ;
27
27
use mz_ssh_util:: tunnel_manager:: { ManagedSshTunnelHandle , SshTunnelManager } ;
28
28
use rdkafka:: client:: { BrokerAddr , Client , NativeClient , OAuthToken } ;
@@ -297,7 +297,7 @@ enum BrokerRewriteHandle {
297
297
FailedDefaultSshTunnel ( String ) ,
298
298
/// We store an error if DNS resolution fails when resolving
299
299
/// a new broker host.
300
- FailedDNSResolution ( String ) ,
300
+ FailedDnsResolution ( String ) ,
301
301
}
302
302
303
303
/// Tunneling clients
@@ -425,7 +425,7 @@ impl<C> TunnelingClientContext<C> {
425
425
BrokerRewriteHandle :: FailedDefaultSshTunnel ( e) => {
426
426
SshTunnelStatus :: Errored ( e. clone ( ) )
427
427
}
428
- BrokerRewriteHandle :: Simple ( _) | BrokerRewriteHandle :: FailedDNSResolution ( _) => {
428
+ BrokerRewriteHandle :: Simple ( _) | BrokerRewriteHandle :: FailedDnsResolution ( _) => {
429
429
SshTunnelStatus :: Running
430
430
}
431
431
} )
@@ -447,7 +447,7 @@ impl<C> TunnelingClientContext<C> {
447
447
let broker_status = rewrites
448
448
. values ( )
449
449
. map ( |handle| match handle {
450
- BrokerRewriteHandle :: FailedDNSResolution ( e) => BrokerStatus :: Failed ( e. clone ( ) ) ,
450
+ BrokerRewriteHandle :: FailedDnsResolution ( e) => BrokerStatus :: Failed ( e. clone ( ) ) ,
451
451
_ => BrokerStatus :: Nominal ,
452
452
} )
453
453
. fold ( BrokerStatus :: Nominal , |acc, status| match ( acc, status) {
@@ -486,7 +486,7 @@ where
486
486
}
487
487
}
488
488
BrokerRewriteHandle :: FailedDefaultSshTunnel ( _)
489
- | BrokerRewriteHandle :: FailedDNSResolution ( _) => {
489
+ | BrokerRewriteHandle :: FailedDnsResolution ( _) => {
490
490
unreachable ! ( )
491
491
}
492
492
} ;
@@ -510,28 +510,18 @@ where
510
510
match rewrite {
511
511
None
512
512
| Some ( BrokerRewriteHandle :: FailedDefaultSshTunnel ( _) )
513
- | Some ( BrokerRewriteHandle :: FailedDNSResolution ( _) ) => {
513
+ | Some ( BrokerRewriteHandle :: FailedDnsResolution ( _) ) => {
514
514
match & self . default_tunnel {
515
515
TunnelConfig :: Ssh ( default_tunnel) => {
516
516
// Multiple users could all run `connect` at the same time; only one ssh
517
517
// tunnel will ever be connected, and only one will be inserted into the
518
518
// map.
519
519
let ssh_tunnel = self . runtime . block_on ( async {
520
- // Ensure the default tunnel host is resolved to an external address.
521
- let resolved_tunnel_addr = resolve_external_address (
522
- & default_tunnel. host ,
523
- self . enforce_external_addresses ,
524
- )
525
- . await ?;
526
- let tunnel_config = SshTunnelConfig {
527
- host : resolved_tunnel_addr. to_string ( ) ,
528
- port : default_tunnel. port ,
529
- user : default_tunnel. user . clone ( ) ,
530
- key_pair : default_tunnel. key_pair . clone ( ) ,
531
- } ;
532
520
self . ssh_tunnel_manager
533
521
. connect (
534
- tunnel_config,
522
+ // We know the default_tunnel has already been validated by the `resolve_address`
523
+ // method when it was provided to the client, so we don't need to check it again.
524
+ default_tunnel. clone ( ) ,
535
525
& addr. host ,
536
526
addr. port . parse ( ) . unwrap ( ) ,
537
527
self . ssh_timeout_config ,
@@ -546,7 +536,7 @@ where
546
536
if matches ! (
547
537
o. get( ) ,
548
538
BrokerRewriteHandle :: FailedDefaultSshTunnel ( _)
549
- | BrokerRewriteHandle :: FailedDNSResolution ( _)
539
+ | BrokerRewriteHandle :: FailedDnsResolution ( _)
550
540
) =>
551
541
{
552
542
o. insert ( BrokerRewriteHandle :: SshTunnel (
@@ -594,15 +584,14 @@ where
594
584
// If no rewrite is specified, we still should check that this potentially
595
585
// new broker address is a global address.
596
586
self . runtime . block_on ( async {
597
- match resolve_external_address (
598
- & addr. host ,
599
- self . enforce_external_addresses ,
600
- )
601
- . await
587
+ match resolve_address ( & addr. host , self . enforce_external_addresses ) . await
602
588
{
603
589
Ok ( resolved) => {
604
590
let rewrite = BrokerRewriteHandle :: Simple ( BrokerRewrite {
605
- host : resolved. to_string ( ) ,
591
+ // `resolve_address` will always return at least one address.
592
+ // TODO: Once we have a way to provide multiple hosts to rdkafka, we should
593
+ // return all resolved addresses here.
594
+ host : resolved. first ( ) . unwrap ( ) . to_string ( ) ,
606
595
port : addr. port . parse ( ) . ok ( ) ,
607
596
} ) ;
608
597
return_rewrite ( & rewrite)
@@ -616,7 +605,7 @@ where
616
605
// Write an error if no one else has already written one.
617
606
let mut rewrites = self . rewrites . lock ( ) . expect ( "poisoned" ) ;
618
607
rewrites. entry ( addr. clone ( ) ) . or_insert_with ( || {
619
- BrokerRewriteHandle :: FailedDNSResolution (
608
+ BrokerRewriteHandle :: FailedDnsResolution (
620
609
e. to_string_with_causes ( ) ,
621
610
)
622
611
} ) ;
0 commit comments