Fix redis ssl issues 2
This commit is contained in:
@@ -365,21 +365,14 @@ class AlertEventConsumer:
|
||||
|
||||
# Redis-based rate limiting implementation
|
||||
try:
|
||||
import ssl
|
||||
import redis.asyncio as redis
|
||||
from datetime import datetime, timedelta
|
||||
from app.core.config import Settings
|
||||
from shared.redis_utils import RedisConnectionManager
|
||||
|
||||
# Connect to Redis using proper configuration with TLS and auth
|
||||
# Connect to Redis using shared manager (handles SSL, pooling, health checks)
|
||||
settings = Settings()
|
||||
redis_url = settings.REDIS_URL
|
||||
|
||||
# Handle SSL/TLS for self-signed certificates
|
||||
connection_kwargs = {"decode_responses": True}
|
||||
if redis_url and redis_url.startswith("rediss://"):
|
||||
connection_kwargs["ssl_cert_reqs"] = ssl.CERT_NONE
|
||||
|
||||
redis_client = await redis.from_url(redis_url, **connection_kwargs)
|
||||
redis_manager = await RedisConnectionManager.create(settings.REDIS_URL, decode_responses=True)
|
||||
redis_client = redis_manager.get_client()
|
||||
|
||||
# Rate limit keys
|
||||
hour_key = f"alert_rate_limit:{tenant_id}:{alert_type}:hour:{datetime.utcnow().strftime('%Y%m%d%H')}"
|
||||
@@ -404,7 +397,7 @@ class AlertEventConsumer:
|
||||
count=hour_count,
|
||||
limit=max_per_hour
|
||||
)
|
||||
await redis_client.close()
|
||||
await redis_manager.close()
|
||||
return False
|
||||
|
||||
if day_count >= max_per_day:
|
||||
@@ -415,7 +408,7 @@ class AlertEventConsumer:
|
||||
count=day_count,
|
||||
limit=max_per_day
|
||||
)
|
||||
await redis_client.close()
|
||||
await redis_manager.close()
|
||||
return False
|
||||
|
||||
# Increment counters
|
||||
@@ -426,7 +419,7 @@ class AlertEventConsumer:
|
||||
pipe.expire(day_key, 86400) # 24 hour TTL
|
||||
await pipe.execute()
|
||||
|
||||
await redis_client.close()
|
||||
await redis_manager.close()
|
||||
|
||||
logger.debug(
|
||||
"Rate limit check passed",
|
||||
|
||||
Reference in New Issue
Block a user