Skip to content

Commit 0c746f3

Browse files
authored
fix: tag rate limit — single bucket per schema and throttle on OCP All endpoints (#5913)
1 parent 1f44357 commit 0c746f3

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

koku/api/common/test_throttling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def test_get_cache_key_success_returns_key(self, mock_flag):
8989
}
9090
key = throttle.get_cache_key(request, None)
9191
self.assertIsNotNone(key)
92-
self.assertIn("tag_query_throttle:acct123:", key)
93-
self.assertIn("group_by[tag:app]", key)
92+
self.assertEqual(key, "tag_query_throttle:acct123")
9493

9594

9695
class TagQueryThrottleGetDateRangeDaysTest(TestCase):

koku/api/common/throttling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def get_cache_key(self, request, view):
7474
# Limit the need to check unleash by calling it last
7575
return None
7676

77-
# Build cache key: schema + sorted tag keys
78-
tag_keys_str = ",".join(sorted(tag_keys))
79-
cache_key = f"tag_query_throttle:{schema_name}:{tag_keys_str}"
77+
# One bucket per schema: 1 heavy tag query per 12h total, regardless of which tag key.
78+
# (Previously we keyed by schema + tag_keys, allowing 1 per 12h per tag = multiple slots.)
79+
cache_key = f"tag_query_throttle:{schema_name}"
8080

8181
LOG.debug(f"Tag query throttle check: {cache_key}, date_range: {date_range_days} days")
8282
return cache_key

koku/api/report/all/openshift/view.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
"""View for OpenShift on All infrastructure Usage Reports."""
66
from api.common.permissions.openshift_all_access import OpenshiftAllAccessPermission
7+
from api.common.throttling import TagQueryThrottle
78
from api.models import Provider
89
from api.report.all.openshift.query_handler import OCPAllReportQueryHandler
910
from api.report.all.openshift.serializers import OCPAllQueryParamSerializer
@@ -14,6 +15,7 @@ class OCPAllView(ReportView):
1415
"""OCP on All Infrastructure Base View."""
1516

1617
permission_classes = [OpenshiftAllAccessPermission]
18+
throttle_classes = [TagQueryThrottle]
1719
provider = Provider.OCP_ALL
1820
serializer = OCPAllQueryParamSerializer
1921
query_handler = OCPAllReportQueryHandler

0 commit comments

Comments
 (0)