@@ -18,11 +18,13 @@ use std::path::PathBuf;
1818use std:: time:: Duration ;
1919
2020use anyhow:: Context ;
21- use domain:: resolv:: StubResolver ;
21+ use hickory_resolver:: {
22+ Resolver , config:: * , name_server:: TokioConnectionProvider , system_conf:: read_system_conf,
23+ } ;
2224use jsonwebtoken:: DecodingKey ;
2325use mz_balancerd:: {
24- BUILD_INFO , BalancerConfig , BalancerService , CancellationResolver , FronteggResolver , Resolver ,
25- SniResolver ,
26+ BUILD_INFO , BalancerConfig , BalancerResolver , BalancerService , CancellationResolver ,
27+ FronteggResolver , SniResolver , create_default_resolver ,
2628} ;
2729use mz_frontegg_auth:: {
2830 Authenticator , AuthenticatorConfig , DEFAULT_REFRESH_DROP_FACTOR ,
@@ -240,8 +242,10 @@ pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(),
240242 if !cancellation_resolver_dir. is_dir ( ) {
241243 anyhow:: bail!( "{cancellation_resolver_dir:?} is not a directory" ) ;
242244 }
245+
243246 (
244- Resolver :: MultiTenant (
247+ BalancerResolver :: MultiTenant (
248+ create_default_resolver ( ) ,
245249 FronteggResolver {
246250 auth,
247251 addr_template,
@@ -260,11 +264,7 @@ pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(),
260264 )
261265 } )
262266 . expect ( "invalid port for pgwire_sni_resolver_template" ) ;
263- Some ( SniResolver {
264- resolver : StubResolver :: new ( ) ,
265- template,
266- port,
267- } )
267+ Some ( SniResolver { template, port } )
268268 }
269269 } ,
270270 ) ,
@@ -283,8 +283,35 @@ pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(),
283283 } ;
284284 drop ( addrs) ;
285285
286+ // Create a resolver for static addresses with the same caching configuration
287+ let mut resolver_opts = ResolverOpts :: default ( ) ;
288+ resolver_opts. cache_size = 10000 ;
289+ resolver_opts. positive_max_ttl = Some ( Duration :: from_secs ( 10 ) ) ;
290+ resolver_opts. positive_min_ttl = Some ( Duration :: from_secs ( 9 ) ) ;
291+ resolver_opts. negative_min_ttl = Some ( Duration :: from_secs ( 1 ) ) ;
292+
293+ // Read system DNS configuration or fall back to defaults
294+ let ( config, opts) = read_system_conf ( )
295+ . map ( |( config, mut opts) | {
296+ // Override specific options while keeping system DNS servers
297+ opts. cache_size = resolver_opts. cache_size ;
298+ opts. positive_max_ttl = resolver_opts. positive_max_ttl ;
299+ opts. positive_min_ttl = resolver_opts. positive_min_ttl ;
300+ opts. negative_min_ttl = resolver_opts. negative_min_ttl ;
301+ ( config, opts)
302+ } )
303+ . unwrap_or_else ( |err| {
304+ eprintln ! ( "Failed to read system DNS configuration for static resolver, using defaults: {}" , err) ;
305+ ( ResolverConfig :: default ( ) , resolver_opts)
306+ } ) ;
307+
286308 (
287- Resolver :: Static ( addr. clone ( ) ) ,
309+ BalancerResolver :: Static (
310+ Resolver :: builder_with_config ( config, TokioConnectionProvider :: default ( ) )
311+ . with_options ( opts)
312+ . build ( ) ,
313+ addr. clone ( ) ,
314+ ) ,
288315 CancellationResolver :: Static ( addr) ,
289316 )
290317 }
0 commit comments