@@ -533,38 +533,40 @@ impl ProxyState {
533533 ip_addr : std:: net:: IpAddr ,
534534 actor_id : & Option < Uuid > ,
535535 ) -> GlobalResult < bool > {
536- let Some ( actor_id) = * actor_id else {
537- // No rate limiting when actor_id is None
538- return Ok ( true ) ;
539- } ;
540-
541- // Get actor-specific middleware config
542- let middleware_config = self . get_middleware_config ( & actor_id) . await ?;
543-
544- let cache_key = ( actor_id, ip_addr) ;
545-
546- // Get existing limiter or create a new one
547- let limiter_arc = if let Some ( existing_limiter) = self . rate_limiters . get ( & cache_key) . await {
548- existing_limiter
549- } else {
550- let new_limiter = Arc :: new ( Mutex :: new ( RateLimiter :: new (
551- middleware_config. rate_limit . requests ,
552- middleware_config. rate_limit . period ,
553- ) ) ) ;
554- self . rate_limiters
555- . insert ( cache_key, new_limiter. clone ( ) )
556- . await ;
557- metrics:: RATE_LIMITER_COUNT . set ( self . rate_limiters . entry_count ( ) as i64 ) ;
558- new_limiter
559- } ;
560-
561- // Try to acquire from the limiter
562- let result = {
563- let mut limiter = limiter_arc. lock ( ) . await ;
564- limiter. try_acquire ( )
565- } ;
566-
567- Ok ( result)
536+ // let Some(actor_id) = *actor_id else {
537+ // // No rate limiting when actor_id is None
538+ // return Ok(true);
539+ // };
540+ //
541+ // // Get actor-specific middleware config
542+ // let middleware_config = self.get_middleware_config(&actor_id).await?;
543+ //
544+ // let cache_key = (actor_id, ip_addr);
545+ //
546+ // // Get existing limiter or create a new one
547+ // let limiter_arc = if let Some(existing_limiter) = self.rate_limiters.get(&cache_key).await {
548+ // existing_limiter
549+ // } else {
550+ // let new_limiter = Arc::new(Mutex::new(RateLimiter::new(
551+ // middleware_config.rate_limit.requests,
552+ // middleware_config.rate_limit.period,
553+ // )));
554+ // self.rate_limiters
555+ // .insert(cache_key, new_limiter.clone())
556+ // .await;
557+ // metrics::RATE_LIMITER_COUNT.set(self.rate_limiters.entry_count() as i64);
558+ // new_limiter
559+ // };
560+ //
561+ // // Try to acquire from the limiter
562+ // let result = {
563+ // let mut limiter = limiter_arc.lock().await;
564+ // limiter.try_acquire()
565+ // };
566+ //
567+ // Ok(result)
568+
569+ Ok ( true )
568570 }
569571
570572 #[ tracing:: instrument( skip_all) ]
@@ -573,53 +575,55 @@ impl ProxyState {
573575 ip_addr : std:: net:: IpAddr ,
574576 actor_id : & Option < Uuid > ,
575577 ) -> GlobalResult < bool > {
576- let Some ( actor_id) = * actor_id else {
577- // No in-flight limiting when actor_id is None
578- return Ok ( true ) ;
579- } ;
580-
581- // Get actor-specific middleware config
582- let middleware_config = self . get_middleware_config ( & actor_id) . await ?;
583-
584- let cache_key = ( actor_id, ip_addr) ;
585-
586- // Get existing counter or create a new one
587- let counter_arc =
588- if let Some ( existing_counter) = self . in_flight_counters . get ( & cache_key) . await {
589- existing_counter
590- } else {
591- let new_counter = Arc :: new ( Mutex :: new ( InFlightCounter :: new (
592- middleware_config. max_in_flight . amount ,
593- ) ) ) ;
594- self . in_flight_counters
595- . insert ( cache_key, new_counter. clone ( ) )
596- . await ;
597- metrics:: IN_FLIGHT_COUNTER_COUNT . set ( self . in_flight_counters . entry_count ( ) as i64 ) ;
598- new_counter
599- } ;
600-
601- // Try to acquire from the counter
602- let result = {
603- let mut counter = counter_arc. lock ( ) . await ;
604- counter. try_acquire ( )
605- } ;
606-
607- Ok ( result)
578+ // let Some(actor_id) = *actor_id else {
579+ // // No in-flight limiting when actor_id is None
580+ // return Ok(true);
581+ // };
582+ //
583+ // // Get actor-specific middleware config
584+ // let middleware_config = self.get_middleware_config(&actor_id).await?;
585+ //
586+ // let cache_key = (actor_id, ip_addr);
587+ //
588+ // // Get existing counter or create a new one
589+ // let counter_arc =
590+ // if let Some(existing_counter) = self.in_flight_counters.get(&cache_key).await {
591+ // existing_counter
592+ // } else {
593+ // let new_counter = Arc::new(Mutex::new(InFlightCounter::new(
594+ // middleware_config.max_in_flight.amount,
595+ // )));
596+ // self.in_flight_counters
597+ // .insert(cache_key, new_counter.clone())
598+ // .await;
599+ // metrics::IN_FLIGHT_COUNTER_COUNT.set(self.in_flight_counters.entry_count() as i64);
600+ // new_counter
601+ // };
602+ //
603+ // // Try to acquire from the counter
604+ // let result = {
605+ // let mut counter = counter_arc.lock().await;
606+ // counter.try_acquire()
607+ // };
608+ //
609+ // Ok(result)
610+
611+ Ok ( true )
608612 }
609613
610614 #[ tracing:: instrument( skip_all) ]
611615 async fn release_in_flight ( & self , ip_addr : std:: net:: IpAddr , actor_id : & Option < Uuid > ) {
612- // Skip if actor_id is None (no in-flight tracking)
613- let actor_id = match actor_id {
614- Some ( id) => * id,
615- None => return , // No in-flight tracking when actor_id is None
616- } ;
617-
618- let cache_key = ( actor_id, ip_addr) ;
619- if let Some ( counter_arc) = self . in_flight_counters . get ( & cache_key) . await {
620- let mut counter = counter_arc. lock ( ) . await ;
621- counter. release ( ) ;
622- }
616+ // // Skip if actor_id is None (no in-flight tracking)
617+ // let actor_id = match actor_id {
618+ // Some(id) => *id,
619+ // None => return, // No in-flight tracking when actor_id is None
620+ // };
621+ //
622+ // let cache_key = (actor_id, ip_addr);
623+ // if let Some(counter_arc) = self.in_flight_counters.get(&cache_key).await {
624+ // let mut counter = counter_arc.lock().await;
625+ // counter.release();
626+ // }
623627 }
624628}
625629
@@ -728,19 +732,20 @@ impl ProxyService {
728732 let client_ip = self . remote_addr . ip ( ) ;
729733
730734 // Apply rate limiting
731- let res = if !self . state . check_rate_limit ( client_ip, & actor_id) . await ? {
732- Response :: builder ( )
733- . status ( StatusCode :: TOO_MANY_REQUESTS )
734- . body ( ResponseBody :: Full ( Full :: < Bytes > :: new ( Bytes :: new ( ) ) ) )
735- . map_err ( Into :: into)
736- }
737- // Check in-flight limit
738- else if !self . state . acquire_in_flight ( client_ip, & actor_id) . await ? {
739- Response :: builder ( )
740- . status ( StatusCode :: TOO_MANY_REQUESTS )
741- . body ( ResponseBody :: Full ( Full :: < Bytes > :: new ( Bytes :: new ( ) ) ) )
742- . map_err ( Into :: into)
743- } else {
735+ // let res = if !self.state.check_rate_limit(client_ip, &actor_id).await? {
736+ // Response::builder()
737+ // .status(StatusCode::TOO_MANY_REQUESTS)
738+ // .body(ResponseBody::Full(Full::<Bytes>::new(Bytes::new())))
739+ // .map_err(Into::into)
740+ // }
741+ // // Check in-flight limit
742+ // else if !self.state.acquire_in_flight(client_ip, &actor_id).await? {
743+ // Response::builder()
744+ // .status(StatusCode::TOO_MANY_REQUESTS)
745+ // .body(ResponseBody::Full(Full::<Bytes>::new(Bytes::new())))
746+ // .map_err(Into::into)
747+ // } else {
748+ let res = {
744749 // Increment metrics
745750 metrics:: PROXY_REQUEST_PENDING . inc ( ) ;
746751 metrics:: PROXY_REQUEST_TOTAL . inc ( ) ;
0 commit comments