@@ -37,18 +37,24 @@ pub struct ClusterState {
3737pub struct PatroniDiscovery {
3838 client : Client ,
3939 postgres_app_id : String ,
40+ gateway_subdomain : String ,
4041 cluster_state : Arc < RwLock < Option < ClusterState > > > ,
4142 refresh_interval : Duration ,
4243}
4344
4445impl PatroniDiscovery {
45- pub fn new ( postgres_app_id : String , refresh_interval_secs : u64 ) -> Self {
46+ pub fn new (
47+ postgres_app_id : String ,
48+ gateway_subdomain : String ,
49+ refresh_interval_secs : u64 ,
50+ ) -> Self {
4651 Self {
4752 client : Client :: builder ( )
4853 . timeout ( Duration :: from_secs ( 10 ) )
4954 . build ( )
5055 . expect ( "Failed to create HTTP client" ) ,
5156 postgres_app_id,
57+ gateway_subdomain,
5258 cluster_state : Arc :: new ( RwLock :: new ( None ) ) ,
5359 refresh_interval : Duration :: from_secs ( refresh_interval_secs) ,
5460 }
@@ -61,14 +67,14 @@ impl PatroniDiscovery {
6167 self . postgres_app_id
6268 ) ;
6369
64- let url = "http://dstack-service/cluster" ;
70+ let url = format ! (
71+ "https://{}-8008.{}/cluster" ,
72+ self . postgres_app_id, self . gateway_subdomain
73+ ) ;
74+
6575 let response = self
6676 . client
6777 . get ( url)
68- . header ( "x-dstack-target-app" , & self . postgres_app_id )
69- . header ( "x-dstack-target-port" , "8008" )
70- . header ( "x-dstack-target-use-tls" , "false" )
71- . header ( "Host" , "vpc-server" )
7278 . send ( )
7379 . await
7480 . map_err ( |e| anyhow ! ( "Failed to connect to Patroni API: {e}" ) ) ?;
@@ -282,7 +288,8 @@ mod tests {
282288
283289 #[ tokio:: test]
284290 async fn test_get_least_lag_replica ( ) {
285- let discovery = PatroniDiscovery :: new ( "test-app" . to_string ( ) , 30 ) ;
291+ let discovery =
292+ PatroniDiscovery :: new ( "test-app" . to_string ( ) , "dstack.internal" . to_string ( ) , 30 ) ;
286293
287294 let replica1 = create_test_member ( "replica1" , "replica" , Some ( 100 ) ) ;
288295 let replica2 = create_test_member ( "replica2" , "replica" , Some ( 10 ) ) ;
@@ -312,7 +319,8 @@ mod tests {
312319
313320 #[ tokio:: test]
314321 async fn test_get_replicas_by_lag ( ) {
315- let discovery = PatroniDiscovery :: new ( "test-app" . to_string ( ) , 30 ) ;
322+ let discovery =
323+ PatroniDiscovery :: new ( "test-app" . to_string ( ) , "dstack.internal" . to_string ( ) , 30 ) ;
316324
317325 let replica1 = create_test_member ( "replica1" , "replica" , Some ( 100 ) ) ;
318326 let replica2 = create_test_member ( "replica2" , "replica" , Some ( 10 ) ) ;
@@ -331,7 +339,8 @@ mod tests {
331339
332340 #[ tokio:: test]
333341 async fn test_round_robin_selection ( ) {
334- let discovery = PatroniDiscovery :: new ( "test-app" . to_string ( ) , 30 ) ;
342+ let discovery =
343+ PatroniDiscovery :: new ( "test-app" . to_string ( ) , "dstack.internal" . to_string ( ) , 30 ) ;
335344
336345 let replica1 = create_test_member ( "replica1" , "replica" , None ) ;
337346 let replica2 = create_test_member ( "replica2" , "replica" , None ) ;
0 commit comments