-
Notifications
You must be signed in to change notification settings - Fork 30
env variable for cache disable via WAVEFRONT_CACHE_ENABLED #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,23 +32,32 @@ def __init__( | |
| self.initial_backoff = initial_backoff | ||
| self.max_backoff = max_backoff | ||
|
|
||
| self.pool = self._create_connection_pool( | ||
| connection_timeout=connection_timeout, | ||
| socket_timeout=socket_timeout, | ||
| socket_keepalive=socket_keepalive, | ||
| pool_size=pool_size, | ||
| self.cache_enabled = ( | ||
| os.getenv('WAVEFRONT_CACHE_ENABLED', 'true').lower() == 'true' | ||
| ) | ||
|
|
||
| self.redis = self._create_redis_connection() | ||
| if self.cache_enabled: | ||
| self.pool = self._create_connection_pool( | ||
| connection_timeout=connection_timeout, | ||
| socket_timeout=socket_timeout, | ||
| socket_keepalive=socket_keepalive, | ||
| pool_size=pool_size, | ||
| ) | ||
|
|
||
| # Test the connection immediately - fail fast if Redis is unreachable | ||
| try: | ||
| self.redis.ping() | ||
| logger.info('Connected to Redis with redis ping') | ||
| except (ConnectionError, TimeoutError, RedisError) as e: | ||
| logger.error(f'Failed to connect to Redis during initialization: {e}') | ||
| logger.error('Server will not start without Redis connectivity') | ||
| raise RuntimeError(f'Redis connection test failed: {e}') from e | ||
| self.redis = self._create_redis_connection() | ||
|
|
||
| # Test the connection immediately - fail fast if Redis is unreachable | ||
| try: | ||
| self.redis.ping() | ||
| logger.info('Connected to Redis with redis ping') | ||
| except (ConnectionError, TimeoutError, RedisError) as e: | ||
| logger.error(f'Failed to connect to Redis during initialization: {e}') | ||
| logger.error('Server will not start without Redis connectivity') | ||
| raise RuntimeError(f'Redis connection test failed: {e}') from e | ||
| else: | ||
| self.pool = None | ||
| self.redis = None | ||
| logger.info('Cache is disabled via WAVEFRONT_CACHE_ENABLED env variable') | ||
|
|
||
| def _create_connection_pool( | ||
| self, | ||
|
|
@@ -80,6 +89,9 @@ def _create_redis_connection(self) -> Redis: | |
| return Redis(connection_pool=self.pool) | ||
|
|
||
| def _checking_redis_connection(self): | ||
| if not self.cache_enabled: | ||
| return False | ||
|
|
||
| try: | ||
| self.redis.ping() | ||
| return True | ||
|
|
@@ -100,6 +112,9 @@ def add( | |
| expiry: int = 3600, | ||
| nx: bool = False, | ||
| ) -> bool: | ||
| if not self.cache_enabled: | ||
| return False | ||
|
|
||
| try: | ||
| logger.info(f'Adding key: {key} to cache with expiry: {expiry} seconds') | ||
| return bool( | ||
|
|
@@ -115,6 +130,9 @@ def add( | |
| retry=retry_if_exception_type((RedisError, ConnectionError, TimeoutError)), | ||
| ) | ||
| def get_str(self, key: str, default: Any = None) -> Optional[str]: | ||
| if not self.cache_enabled: | ||
| return default | ||
|
|
||
| try: | ||
| value = self.redis.get(f'{self.namespace}/{key}') | ||
| return value if value is not None else default | ||
|
|
@@ -124,10 +142,16 @@ def get_str(self, key: str, default: Any = None) -> Optional[str]: | |
| raise | ||
|
|
||
| def get_int(self, key: str, default: int = 0) -> int: | ||
| if not self.cache_enabled: | ||
| return default | ||
|
|
||
| value = self.get_str(key, default) | ||
| return int(value) if value is not None else default | ||
|
|
||
| def remove(self, key: str) -> bool: | ||
| if not self.cache_enabled: | ||
| return False | ||
|
|
||
| try: | ||
| return bool(self.redis.delete(f'{self.namespace}/{key}')) | ||
| except (RedisError, ConnectionError, TimeoutError) as e: | ||
|
|
@@ -136,6 +160,9 @@ def remove(self, key: str) -> bool: | |
|
|
||
| def invalidate_query(self, pattern: str) -> int: | ||
| """Remove all keys matching the given pattern""" | ||
| if not self.cache_enabled: | ||
| return 0 | ||
|
|
||
| try: | ||
| # Get all keys matching the pattern | ||
| search_pattern = f'{self.namespace}/{pattern}' | ||
|
|
@@ -170,6 +197,9 @@ def publish(self, channel: str, message: str) -> int: | |
| Raises: | ||
| RedisError: If publishing fails | ||
| """ | ||
| if not self.cache_enabled: | ||
| return 0 | ||
|
|
||
|
Comment on lines
+200
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== CacheManager publish/subscribe call sites ==="
rg -n -C3 '\bcache_manager\.(publish|subscribe)\s*\(' wavefront
echo
echo "=== Redis API update channel usage ==="
rg -n -C3 'REDIS_API_SERVICE_UPDATES_CHANNEL|process_message\s*\(' wavefront
echo
echo "=== CommonCache / subscribe contract ==="
rg -n -C3 '\bclass CommonCache\b|\bdef subscribe\s*\(' wavefront
echo
echo "=== Publisher / processor sources ==="
fd 'api_change_publisher\.py$' wavefront -x sed -n '1,220p' {}
fd 'api_change_processor\.py$' wavefront -x sed -n '1,260p' {}Repository: rootflo/wavefront Length of output: 11393 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== Full publish and subscribe methods ==="
sed -n '195,250p' wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py
echo
echo "=== Check return type hints for subscribe method ==="
rg -n 'def subscribe' wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py -A 50 | head -60
echo
echo "=== Any other usages of cache_manager.publish/subscribe beyond API updates ==="
rg -n '\.publish\(|\.subscribe\(' wavefront --type py | grep -v 'test' | grep -v '.pyc'Repository: rootflo/wavefront Length of output: 5441 Update The
Either document the optional 🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rootflo-hardik Lets not disable publish and subscribe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| try: | ||
| full_channel = f'{self.namespace}/{channel}' | ||
| logger.info(f'Publishing message to channel: {full_channel}') | ||
|
|
@@ -203,6 +233,9 @@ def subscribe( | |
| if message['type'] == 'message': | ||
| print(f"Received: {message['data']}") | ||
| """ | ||
| if not self.cache_enabled: | ||
| return None | ||
|
|
||
| try: | ||
| pubsub = self.redis.pubsub() | ||
|
|
||
|
|
@@ -225,6 +258,9 @@ def subscribe( | |
| raise | ||
|
|
||
| def close(self): | ||
| if not self.cache_enabled: | ||
| return | ||
|
|
||
| try: | ||
| self.pool.disconnect() | ||
| logger.info('Redis connection pool closed successfully') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DId you test this? Is it working fine with cache disabled ?