@@ -17,7 +17,7 @@ use std::net::{IpAddr, SocketAddr};
1717use std:: str:: FromStr ;
1818use std:: time:: Duration ;
1919
20- use anyhow:: { Context , bail} ;
20+ use anyhow:: { Context , bail, ensure } ;
2121use bytesize:: ByteSize ;
2222use http:: HeaderMap ;
2323use quickwit_common:: fs:: get_disk_size;
@@ -31,6 +31,7 @@ use tracing::{info, warn};
3131use super :: { GrpcConfig , HealthConfig , RestConfig } ;
3232use crate :: config_value:: ConfigValue ;
3333use crate :: qw_env_vars:: * ;
34+ use crate :: serde_utils:: HumanDuration ;
3435use crate :: service:: QuickwitService ;
3536use crate :: storage_config:: StorageConfigs ;
3637use crate :: templating:: render_config;
@@ -457,6 +458,10 @@ struct RestConfigBuilder {
457458 pub extra_headers : HeaderMap ,
458459 #[ serde( default , rename = "tls" ) ]
459460 pub tls_config : Option < TlsConfig > ,
461+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
462+ pub max_connection_age : Option < HumanDuration > ,
463+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
464+ pub max_connection_age_grace : Option < HumanDuration > ,
460465}
461466
462467impl RestConfigBuilder {
@@ -475,11 +480,17 @@ impl RestConfigBuilder {
475480 if let Some ( tls_config) = & self . tls_config {
476481 tls_config. validate ( ) ?;
477482 }
483+ ensure ! (
484+ !( self . max_connection_age_grace. is_some( ) && self . max_connection_age. is_none( ) ) ,
485+ "`rest.max_connection_age_grace` requires `rest.max_connection_age` to be set"
486+ ) ;
478487 let rest_config = RestConfig {
479488 listen_addr : SocketAddr :: new ( listen_ip, listen_port) ,
480489 cors_allow_origins : self . cors_allow_origins ,
481490 extra_headers : self . extra_headers ,
482491 tls_config : self . tls_config ,
492+ max_connection_age : self . max_connection_age ,
493+ max_connection_age_grace : self . max_connection_age_grace ,
483494 } ;
484495 Ok ( rest_config)
485496 }
@@ -550,6 +561,8 @@ pub fn node_config_for_tests_from_ports(
550561 cors_allow_origins : Vec :: new ( ) ,
551562 extra_headers : HeaderMap :: new ( ) ,
552563 tls_config : None ,
564+ max_connection_age : None ,
565+ max_connection_age_grace : None ,
553566 } ;
554567 NodeConfig {
555568 cluster_id : default_cluster_id ( ) . unwrap ( ) ,
@@ -624,17 +637,54 @@ mod tests {
624637 config. rest_config. extra_headers. get( "x-header-2" ) . unwrap( ) ,
625638 "header-value-2"
626639 ) ;
640+ let rest_tls_config = config. rest_config . tls_config . unwrap ( ) ;
641+ assert_eq ! (
642+ rest_tls_config,
643+ TlsConfig {
644+ cert_path: "/path/to/rest.crt" . to_string( ) ,
645+ key_path: "/path/to/rest.key" . to_string( ) ,
646+ ca_path: "/path/to/ca.crt" . to_string( ) ,
647+ expected_name: None ,
648+ verify_client_cert: true ,
649+ cert_poll_interval: HumanDuration :: try_from( "5m" . to_string( ) ) . unwrap( ) ,
650+ }
651+ ) ;
652+ assert_eq ! (
653+ config. rest_config. max_connection_age,
654+ Some ( HumanDuration :: try_from( "30m" . to_string( ) ) . unwrap( ) )
655+ ) ;
656+ assert_eq ! (
657+ config. rest_config. max_connection_age_grace,
658+ Some ( HumanDuration :: try_from( "30s" . to_string( ) ) . unwrap( ) )
659+ ) ;
627660 assert_eq ! ( config. grpc_config. max_message_size, ByteSize :: mb( 10 ) ) ;
628661
662+ let grpc_tls_config = config. grpc_config . tls_config . unwrap ( ) ;
629663 assert_eq ! (
630- config
631- . health_config
632- . as_ref( )
633- . expect( "health config should be set" )
634- . listen_addr,
635- SocketAddr :: new( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) , 4444 )
664+ grpc_tls_config,
665+ TlsConfig {
666+ cert_path: "/path/to/grpc.crt" . to_string( ) ,
667+ key_path: "/path/to/grpc.key" . to_string( ) ,
668+ ca_path: "/path/to/ca.crt" . to_string( ) ,
669+ expected_name: Some ( "quickwit.local" . to_string( ) ) ,
670+ verify_client_cert: true ,
671+ cert_poll_interval: HumanDuration :: try_from( "5m" . to_string( ) ) . unwrap( ) ,
672+ }
673+ ) ;
674+ assert_eq ! (
675+ config. grpc_config. max_connection_age,
676+ Some ( HumanDuration :: try_from( "1h" . to_string( ) ) . unwrap( ) )
677+ ) ;
678+ assert_eq ! (
679+ config. grpc_config. max_connection_age_grace,
680+ Some ( HumanDuration :: try_from( "10s" . to_string( ) ) . unwrap( ) )
636681 ) ;
637682
683+ let health_config = config. health_config . unwrap ( ) ;
684+ assert_eq ! (
685+ health_config. listen_addr,
686+ SocketAddr :: new( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) , 4444 )
687+ ) ;
638688 assert_eq ! (
639689 config. gossip_listen_addr,
640690 SocketAddr :: new( IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) , 2222 )
0 commit comments