@@ -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 ,
@@ -241,8 +243,10 @@ pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(),
241243 if !cancellation_resolver_dir. is_dir ( ) {
242244 anyhow:: bail!( "{cancellation_resolver_dir:?} is not a directory" ) ;
243245 }
246+
244247 (
245- Resolver :: MultiTenant (
248+ BalancerResolver :: MultiTenant (
249+ create_default_resolver ( ) ,
246250 FronteggResolver {
247251 auth,
248252 addr_template,
@@ -261,11 +265,7 @@ pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(),
261265 )
262266 } )
263267 . expect ( "invalid port for pgwire_sni_resolver_template" ) ;
264- Some ( SniResolver {
265- resolver : StubResolver :: new ( ) ,
266- template,
267- port,
268- } )
268+ Some ( SniResolver { template, port } )
269269 }
270270 } ,
271271 ) ,
@@ -284,8 +284,35 @@ pub async fn run(args: ServiceArgs, tracing_handle: TracingHandle) -> Result<(),
284284 } ;
285285 drop ( addrs) ;
286286
287+ // Create a resolver for static addresses with the same caching configuration
288+ let mut resolver_opts = ResolverOpts :: default ( ) ;
289+ resolver_opts. cache_size = 10000 ;
290+ resolver_opts. positive_max_ttl = Some ( Duration :: from_secs ( 10 ) ) ;
291+ resolver_opts. positive_min_ttl = Some ( Duration :: from_secs ( 9 ) ) ;
292+ resolver_opts. negative_min_ttl = Some ( Duration :: from_secs ( 1 ) ) ;
293+
294+ // Read system DNS configuration or fall back to defaults
295+ let ( config, opts) = read_system_conf ( )
296+ . map ( |( config, mut opts) | {
297+ // Override specific options while keeping system DNS servers
298+ opts. cache_size = resolver_opts. cache_size ;
299+ opts. positive_max_ttl = resolver_opts. positive_max_ttl ;
300+ opts. positive_min_ttl = resolver_opts. positive_min_ttl ;
301+ opts. negative_min_ttl = resolver_opts. negative_min_ttl ;
302+ ( config, opts)
303+ } )
304+ . unwrap_or_else ( |err| {
305+ eprintln ! ( "Failed to read system DNS configuration for static resolver, using defaults: {}" , err) ;
306+ ( ResolverConfig :: default ( ) , resolver_opts)
307+ } ) ;
308+
287309 (
288- Resolver :: Static ( addr. clone ( ) ) ,
310+ BalancerResolver :: Static (
311+ Resolver :: builder_with_config ( config, TokioConnectionProvider :: default ( ) )
312+ . with_options ( opts)
313+ . build ( ) ,
314+ addr. clone ( ) ,
315+ ) ,
289316 CancellationResolver :: Static ( addr) ,
290317 )
291318 }
0 commit comments