@@ -33,6 +33,7 @@ use crate::stats::Stats;
3333use  crate :: storage:: object_storage:: ingestor_metadata_path; 
3434use  crate :: storage:: { ObjectStorageError ,  STREAM_ROOT_DIRECTORY } ; 
3535use  crate :: storage:: { ObjectStoreFormat ,  PARSEABLE_ROOT_DIRECTORY } ; 
36+ use  crate :: HTTP_CLIENT ; 
3637use  actix_web:: http:: header:: { self ,  HeaderMap } ; 
3738use  actix_web:: { HttpRequest ,  Responder } ; 
3839use  bytes:: Bytes ; 
@@ -76,8 +77,6 @@ pub async fn sync_streams_with_ingestors(
7677 StreamError :: Anyhow ( err) 
7778 } ) ?; 
7879
79-  let  client = reqwest:: Client :: new ( ) ; 
80- 
8180 for  ingestor in  ingestor_infos { 
8281 if  !utils:: check_liveness ( & ingestor. domain_name ) . await  { 
8382 warn ! ( "Ingestor {} is not live" ,  ingestor. domain_name) ; 
@@ -89,7 +88,7 @@ pub async fn sync_streams_with_ingestors(
8988 base_path_without_preceding_slash( ) , 
9089 stream_name
9190 ) ; 
92-  let  res = client 
91+  let  res = HTTP_CLIENT 
9392 . put ( url) 
9493 . headers ( reqwest_headers. clone ( ) ) 
9594 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
@@ -126,7 +125,6 @@ pub async fn sync_users_with_roles_with_ingestors(
126125 RBACError :: Anyhow ( err) 
127126 } ) ?; 
128127
129-  let  client = reqwest:: Client :: new ( ) ; 
130128 let  role = to_vec ( & role. clone ( ) ) . map_err ( |err| { 
131129 error ! ( "Fatal: failed to serialize role: {:?}" ,  err) ; 
132130 RBACError :: SerdeError ( err) 
@@ -143,7 +141,7 @@ pub async fn sync_users_with_roles_with_ingestors(
143141 username
144142 ) ; 
145143
146-  let  res = client 
144+  let  res = HTTP_CLIENT 
147145 . put ( url) 
148146 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
149147 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
@@ -177,7 +175,6 @@ pub async fn sync_user_deletion_with_ingestors(username: &String) -> Result<(),
177175 RBACError :: Anyhow ( err) 
178176 } ) ?; 
179177
180-  let  client = reqwest:: Client :: new ( ) ; 
181178 for  ingestor in  ingestor_infos. iter ( )  { 
182179 if  !utils:: check_liveness ( & ingestor. domain_name ) . await  { 
183180 warn ! ( "Ingestor {} is not live" ,  ingestor. domain_name) ; 
@@ -190,7 +187,7 @@ pub async fn sync_user_deletion_with_ingestors(username: &String) -> Result<(),
190187 username
191188 ) ; 
192189
193-  let  res = client 
190+  let  res = HTTP_CLIENT 
194191 . delete ( url) 
195192 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
196193 . send ( ) 
@@ -231,7 +228,6 @@ pub async fn sync_user_creation_with_ingestors(
231228 user. roles . clone_from ( role) ; 
232229 } 
233230 let  username = user. username ( ) ; 
234-  let  client = reqwest:: Client :: new ( ) ; 
235231
236232 let  user = to_vec ( & user) . map_err ( |err| { 
237233 error ! ( "Fatal: failed to serialize user: {:?}" ,  err) ; 
@@ -250,7 +246,7 @@ pub async fn sync_user_creation_with_ingestors(
250246 username
251247 ) ; 
252248
253-  let  res = client 
249+  let  res = HTTP_CLIENT 
254250 . post ( url) 
255251 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
256252 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
@@ -283,7 +279,6 @@ pub async fn sync_password_reset_with_ingestors(username: &String) -> Result<(),
283279 error ! ( "Fatal: failed to get ingestor info: {:?}" ,  err) ; 
284280 RBACError :: Anyhow ( err) 
285281 } ) ?; 
286-  let  client = reqwest:: Client :: new ( ) ; 
287282
288283 for  ingestor in  ingestor_infos. iter ( )  { 
289284 if  !utils:: check_liveness ( & ingestor. domain_name ) . await  { 
@@ -297,7 +292,7 @@ pub async fn sync_password_reset_with_ingestors(username: &String) -> Result<(),
297292 username
298293 ) ; 
299294
300-  let  res = client 
295+  let  res = HTTP_CLIENT 
301296 . post ( url) 
302297 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
303298 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
@@ -338,7 +333,6 @@ pub async fn sync_role_update_with_ingestors(
338333 RoleError :: SerdeError ( err) 
339334 } ) ?; 
340335 let  roles = Bytes :: from ( roles) ; 
341-  let  client = reqwest:: Client :: new ( ) ; 
342336
343337 for  ingestor in  ingestor_infos. iter ( )  { 
344338 if  !utils:: check_liveness ( & ingestor. domain_name ) . await  { 
@@ -352,7 +346,7 @@ pub async fn sync_role_update_with_ingestors(
352346 name
353347 ) ; 
354348
355-  let  res = client 
349+  let  res = HTTP_CLIENT 
356350 . put ( url) 
357351 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
358352 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
@@ -401,7 +395,7 @@ pub async fn fetch_daily_stats_from_ingestors(
401395 StreamError :: Anyhow ( anyhow:: anyhow!( "Invalid URL in Ingestor Metadata: {}" ,  err) ) 
402396 } ) ?; 
403397
404-  let  res = reqwest :: Client :: new ( ) 
398+  let  res = HTTP_CLIENT 
405399 . get ( uri) 
406400 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
407401 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
@@ -512,8 +506,7 @@ pub async fn send_stream_delete_request(
512506 if  !utils:: check_liveness ( & ingestor. domain_name ) . await  { 
513507 return  Ok ( ( ) ) ; 
514508 } 
515-  let  client = reqwest:: Client :: new ( ) ; 
516-  let  resp = client
509+  let  resp = HTTP_CLIENT 
517510 . delete ( url) 
518511 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
519512 . header ( header:: AUTHORIZATION ,  ingestor. token ) 
@@ -551,8 +544,7 @@ pub async fn send_retention_cleanup_request(
551544 if  !utils:: check_liveness ( & ingestor. domain_name ) . await  { 
552545 return  Ok ( first_event_at) ; 
553546 } 
554-  let  client = reqwest:: Client :: new ( ) ; 
555-  let  resp = client
547+  let  resp = HTTP_CLIENT 
556548 . post ( url) 
557549 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
558550 . header ( header:: AUTHORIZATION ,  ingestor. token ) 
@@ -603,7 +595,7 @@ pub async fn get_cluster_info() -> Result<impl Responder, StreamError> {
603595 ) ) 
604596 . expect ( "should always be a valid url" ) ; 
605597
606-  let  resp = reqwest :: Client :: new ( ) 
598+  let  resp = HTTP_CLIENT 
607599 . get ( uri) 
608600 . header ( header:: AUTHORIZATION ,  ingestor. token . clone ( ) ) 
609601 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
@@ -752,7 +744,7 @@ async fn fetch_cluster_metrics() -> Result<Vec<Metrics>, PostError> {
752744 PostError :: Invalid ( anyhow:: anyhow!( "Invalid URL in Ingestor Metadata: {}" ,  err) ) 
753745 } ) ?; 
754746
755-  let  res = reqwest :: Client :: new ( ) 
747+  let  res = HTTP_CLIENT 
756748 . get ( uri) 
757749 . header ( header:: AUTHORIZATION ,  & ingestor. token ) 
758750 . header ( header:: CONTENT_TYPE ,  "application/json" ) 
0 commit comments