Skip to content

Commit d022338

Browse files
authored
update RateLimiter execution function name (#37287)
1 parent 072dd82 commit d022338

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

sdks/python/apache_beam/examples/rate_limiter_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def init_limiter():
5353
self.rate_limiter = self._shared.acquire(init_limiter)
5454

5555
def process(self, element):
56-
self.rate_limiter.throttle()
56+
self.rate_limiter.allow()
5757

5858
# Process the element mock API call
5959
logging.info("Processing element: %s", element)

sdks/python/apache_beam/io/components/rate_limiter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, namespace: str = ""):
6161
self.rpc_latency = Metrics.distribution(namespace, 'RatelimitRpcLatencyMs')
6262

6363
@abc.abstractmethod
64-
def throttle(self, **kwargs) -> bool:
64+
def allow(self, **kwargs) -> bool:
6565
"""Applies rate limiting to the request.
6666
6767
This method checks if the request is permitted by the rate limiting policy.
@@ -148,7 +148,7 @@ def init_connection(self):
148148
channel = grpc.insecure_channel(self.service_address)
149149
self._stub = EnvoyRateLimiter.RateLimitServiceStub(channel)
150150

151-
def throttle(self, hits_added: int = 1) -> bool:
151+
def allow(self, hits_added: int = 1) -> bool:
152152
"""Calls the Envoy RLS to apply rate limits.
153153
154154
Sends a rate limit request to the configured Envoy Rate Limit Service.

sdks/python/apache_beam/io/components/rate_limiter_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def setUp(self):
4242
namespace='test_namespace')
4343

4444
@mock.patch('grpc.insecure_channel')
45-
def test_throttle_allowed(self, mock_channel):
45+
def test_allow_success(self, mock_channel):
4646
# Mock successful OK response
4747
mock_stub = mock.Mock()
4848
mock_response = RateLimitResponse(overall_code=RateLimitResponseCode.OK)
@@ -51,13 +51,13 @@ def test_throttle_allowed(self, mock_channel):
5151
# Inject mock stub
5252
self.limiter._stub = mock_stub
5353

54-
throttled = self.limiter.throttle()
54+
allowed = self.limiter.allow()
5555

56-
self.assertTrue(throttled)
56+
self.assertTrue(allowed)
5757
mock_stub.ShouldRateLimit.assert_called_once()
5858

5959
@mock.patch('grpc.insecure_channel')
60-
def test_throttle_over_limit_retries_exceeded(self, mock_channel):
60+
def test_allow_over_limit_retries_exceeded(self, mock_channel):
6161
# Mock OVER_LIMIT response
6262
mock_stub = mock.Mock()
6363
mock_response = RateLimitResponse(
@@ -69,9 +69,9 @@ def test_throttle_over_limit_retries_exceeded(self, mock_channel):
6969

7070
# We mock time.sleep to run fast
7171
with mock.patch('time.sleep'):
72-
throttled = self.limiter.throttle()
72+
allowed = self.limiter.allow()
7373

74-
self.assertFalse(throttled)
74+
self.assertFalse(allowed)
7575
# Should be called 1 (initial) + 2 (retries) + 1 (last check > retries
7676
# logic depends on loop)
7777
# Logic: attempt starts at 0.
@@ -83,7 +83,7 @@ def test_throttle_over_limit_retries_exceeded(self, mock_channel):
8383
self.assertEqual(mock_stub.ShouldRateLimit.call_count, 3)
8484

8585
@mock.patch('grpc.insecure_channel')
86-
def test_throttle_rpc_error_retry(self, mock_channel):
86+
def test_allow_rpc_error_retry(self, mock_channel):
8787
# Mock RpcError then Success
8888
mock_stub = mock.Mock()
8989
mock_response = RateLimitResponse(overall_code=RateLimitResponseCode.OK)
@@ -95,13 +95,13 @@ def test_throttle_rpc_error_retry(self, mock_channel):
9595
self.limiter._stub = mock_stub
9696

9797
with mock.patch('time.sleep'):
98-
throttled = self.limiter.throttle()
98+
allowed = self.limiter.allow()
9999

100-
self.assertTrue(throttled)
100+
self.assertTrue(allowed)
101101
self.assertEqual(mock_stub.ShouldRateLimit.call_count, 3)
102102

103103
@mock.patch('grpc.insecure_channel')
104-
def test_throttle_rpc_error_fail(self, mock_channel):
104+
def test_allow_rpc_error_fail(self, mock_channel):
105105
# Mock Persistent RpcError
106106
mock_stub = mock.Mock()
107107
error = grpc.RpcError()
@@ -111,7 +111,7 @@ def test_throttle_rpc_error_fail(self, mock_channel):
111111

112112
with mock.patch('time.sleep'):
113113
with self.assertRaises(grpc.RpcError):
114-
self.limiter.throttle()
114+
self.limiter.allow()
115115

116116
# The inner loop tries 5 times for connection errors
117117
self.assertEqual(mock_stub.ShouldRateLimit.call_count, 5)
@@ -134,7 +134,7 @@ def test_extract_duration_from_response(self, mock_random, mock_channel):
134134
self.limiter.retries = 0 # Single attempt
135135

136136
with mock.patch('time.sleep') as mock_sleep:
137-
self.limiter.throttle()
137+
self.limiter.allow()
138138
# Should sleep for 5 seconds (jitter is 0.0)
139139
mock_sleep.assert_called_with(5.0)
140140

sdks/python/apache_beam/ml/inference/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def init_limiter():
450450

451451
self._shared_rate_limiter = self._shared_handle.acquire(init_limiter)
452452

453-
if not self._shared_rate_limiter.throttle(hits_added=len(batch)):
453+
if not self._shared_rate_limiter.allow(hits_added=len(batch)):
454454
raise RateLimitExceeded(
455455
"Rate Limit Exceeded, "
456456
"Could not process this batch.")

sdks/python/apache_beam/ml/inference/base_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ class FakeRateLimiter(base.RateLimiter):
20762076
def __init__(self):
20772077
super().__init__(namespace='test_namespace')
20782078

2079-
def throttle(self, hits_added=1):
2079+
def allow(self, hits_added=1):
20802080
self.requests_counter.inc()
20812081
return True
20822082

@@ -2114,7 +2114,7 @@ class FakeRateLimiter(base.RateLimiter):
21142114
def __init__(self):
21152115
super().__init__(namespace='test_namespace')
21162116

2117-
def throttle(self, hits_added=1):
2117+
def allow(self, hits_added=1):
21182118
return False
21192119

21202120
class ConcreteRemoteModelHandler(base.RemoteModelHandler):

0 commit comments

Comments
 (0)