Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions web/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ def remotes_json_path(self) -> str:
"""Path to remotes.json configuration."""
return os.path.join(self.base_dir, 'configs', 'remotes.json')

@property
def rate_limiter_storage_uri(self) -> str:
"""
Storage URI for the rate limiter.

Uses CBS_RATE_LIMITER_STORAGE_URI env var if set and non-empty,
otherwise falls back to redis backend. When using the redis backend,
db index 1 is used to avoid conflicts with any other components that
use db index 0.
"""
uri = os.getenv('CBS_RATE_LIMITER_STORAGE_URI', '').strip()
if uri:
return uri
return f"redis://{self.redis_host}:{self.redis_port}/1"

@property
def enable_inbuilt_builder(self) -> bool:
"""Whether to enable the inbuilt builder."""
Expand Down
6 changes: 1 addition & 5 deletions web/core/limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@

settings = get_settings()

# We use the same redis instance which is used to store build metadata
# and other cached data. To keep that data separate, we use db-1 of the
# redis instance instead of the default db-0.
REDIS_DB_NUMBER = 1
limiter = Limiter(
key_func=get_remote_address,
storage_uri=f"redis://{settings.redis_host}:{settings.redis_port}/{REDIS_DB_NUMBER}",
storage_uri=settings.rate_limiter_storage_uri,
strategy="fixed-window",
)

Expand Down
Loading