Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 34835c6

Browse files
committed
create new env var for gql rl value
1 parent b9c83a2 commit 34835c6

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

codecov/settings_base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,20 @@
9292

9393
WSGI_APPLICATION = "codecov.wsgi.application"
9494

95-
# Database
96-
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
95+
96+
# GraphQL
9797

9898
GRAPHQL_QUERY_COST_THRESHOLD = get_config(
9999
"setup", "graphql", "query_cost_threshold", default=10000
100100
)
101101

102+
GRAPHQL_RATE_LIMIT_VALUE = get_config(
103+
"setup", "graphql", "rate_limit_value", default=300
104+
)
105+
106+
# Database
107+
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
108+
102109
DATABASE_ROUTERS = ["codecov.db.DatabaseRouter"]
103110

104111
# Password validation

codecov/settings_staging.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
# 25MB in bytes
6666
DATA_UPLOAD_MAX_MEMORY_SIZE = 26214400
6767

68+
GRAPHQL_RATE_LIMIT_VALUE = get_config(
69+
"setup", "graphql", "rate_limit_value", default=1000
70+
)
71+
6872
# Same site is set to none on Staging as we want to be able to call the API
6973
# From Netlify preview deploy
7074
COOKIE_SAME_SITE = "None"

graphql_api/tests/test_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ async def test_query_metrics_extension_set_type_and_name_timeout(
203203

204204
@patch("sentry_sdk.metrics.incr")
205205
@patch("graphql_api.views.AsyncGraphqlView._check_ratelimit")
206+
@override_settings(DEBUG=False, GRAPHQL_RATE_LIMIT_VALUE=1000)
206207
async def test_when_rate_limit_reached(
207208
self, mocked_check_ratelimit, mocked_sentry_incr
208209
):
@@ -213,7 +214,7 @@ async def test_when_rate_limit_reached(
213214
assert response["status"] == 429
214215
assert (
215216
response["detail"]
216-
== "It looks like you've hit the rate limit of 300 req/min. Try again later."
217+
== "It looks like you've hit the rate limit of 1000 req/min. Try again later."
217218
)
218219

219220
expected_calls = [

graphql_api/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ async def post(self, request, *args, **kwargs):
233233
return JsonResponse(
234234
data={
235235
"status": 429,
236-
"detail": "It looks like you've hit the rate limit of 300 req/min. Try again later.",
236+
"detail": f"It looks like you've hit the rate limit of {settings.GRAPHQL_RATE_LIMIT_VALUE} req/min. Try again later.",
237237
},
238238
status=429,
239239
)
@@ -320,7 +320,7 @@ def _check_ratelimit(self, request):
320320
user_ip = self.get_client_ip(request)
321321
key = f"rl-ip:{user_ip}"
322322

323-
limit = 300
323+
limit = settings.GRAPHQL_RATE_LIMIT_VALUE
324324
window = 60 # in seconds
325325

326326
current_count = redis.get(key)

0 commit comments

Comments
 (0)