fix(e2e): make spend-counter redis connection env-driven for non-cluster deployments (#35732)

This commit is contained in:
yuneng-jiang 2026-08-04 09:47:01 -07:00 committed by GitHub
parent 6b3d4f2380
commit 5ac1edcd59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View file

@ -25,7 +25,7 @@ The suites run against a live proxy, so bring one up first by running the litell
GEMINI_API_KEY="..."
```
2. Bring up a Postgres and a Redis for the proxy to use. The repo-root `docker-compose.yml` already defines a Postgres on `5432`; a `docker run -p 6379:6379 redis:7` covers Redis. Point `DATABASE_URL` / `REDIS_HOST` / `REDIS_PORT` at whatever you run
2. Bring up a Postgres and a Redis for the proxy to use. The repo-root `docker-compose.yml` already defines a Postgres on `5432`; a `docker run -p 6379:6379 redis:7` covers Redis. Point `DATABASE_URL` / `REDIS_HOST` / `REDIS_PORT` at whatever you run. Tests that read Redis directly default to the deployed shape (TLS + cluster mode) whenever `REDIS_HOST` is set, so for a local standalone Redis also set `REDIS_CLUSTER=false` and `REDIS_SSL=false` (plus `REDIS_PASSWORD` when your Redis requires auth)
3. Start the litellm proxy locally against your config and confirm it is live:

View file

@ -46,22 +46,43 @@ COLD_WAIT_SECONDS = 80
_JSON_FLOAT: TypeAdapter[float] = TypeAdapter(float)
def _redis_flag(name: str, default: str) -> bool:
return os.environ.get(name, default).strip().lower() in ("1", "true", "yes")
def _redis() -> "redis.Redis[str] | RedisCluster[str]":
"""The proxy's Redis. The deployed runner sets REDIS_HOST to the serverless
ElastiCache, which is always TLS + cluster-mode; without it, fall back to a
local standalone redis for docker-compose runs."""
"""The proxy's Redis. With REDIS_HOST set, TLS and cluster mode default to
on (the stage runner's serverless ElastiCache) and are overridable with
REDIS_SSL / REDIS_CLUSTER, plus REDIS_PASSWORD when auth is enabled, so the
same test runs against a standalone redis like the ephemeral per-SHA
stack's bundled one. Without REDIS_HOST, fall back to a local standalone
redis for docker-compose runs."""
import redis
host = os.getenv("REDIS_HOST")
if not host:
return redis.Redis(host="localhost", port=6380, decode_responses=True, socket_connect_timeout=2)
port = int(os.getenv("REDIS_PORT", "6379"))
use_ssl = _redis_flag("REDIS_SSL", "true")
password = os.getenv("REDIS_PASSWORD") or None
if not _redis_flag("REDIS_CLUSTER", "true"):
return redis.Redis(
host=host,
port=port,
ssl=use_ssl,
password=password,
decode_responses=True,
socket_connect_timeout=2,
)
from redis.cluster import RedisCluster
return RedisCluster(
host=host,
port=int(os.getenv("REDIS_PORT", "6379")),
ssl=True,
port=port,
ssl=use_ssl,
password=password,
decode_responses=True,
socket_connect_timeout=2,
)