feat: parameterize ports/pod, fix valkey healthcheck, address all review comments#251
feat: parameterize ports/pod, fix valkey healthcheck, address all review comments#251sheepdestroyer wants to merge 22 commits into
Conversation
…yments Replaces all hardcoded port values and the pod name in pod.yaml, start-stack.sh, litellm/config.yaml and litellm/entrypoint.py with environment-variable-driven placeholders. A single pod.yaml now serves both the production agent-router-pod and the development dev-router-pod. Changes: - pod.yaml: rewrite with *_PLACEHOLDER vars for pod name, all 13 service ports, and DATA_ROOT; add clickhouse-port-config volume; litellm-config volume now points to DATA_ROOT/litellm-rendered (rendered copy) - start-stack.sh: load optional DEV_ENV_FILE overlay; resolve port/name defaults after env sourcing; add generate_clickhouse_config() and render_litellm_config() helpers; parameterize all agent-router-pod refs and hardcoded ports throughout cleanup, health-check, and minio helpers - litellm/config.yaml: replace port 6379 / 5000 with *_PLACEHOLDER vars (rendered at deploy time via render_litellm_config) - litellm/entrypoint.py: read POSTGRES_PORT / LITELLM_PORT from env instead of hardcoded 5432 / 4000; use setdefault to not clobber container-injected env vars - .env: append production port defaults (POD_NAME, ROUTER_PORT, ...) - .env.dev: new dev overlay (POD_NAME=dev-router-pod, +10 port offsets, dev.vendeuvre.lan URLs) - start-dev.sh: thin wrapper that sets DEV_ENV_FILE + DATA_ROOT then delegates to start-stack.sh - .gitignore: exclude dev-data/ (dev-stack runtime volumes)
…T, LANGFUSE_WEB_PORT, ROUTER_PORT)
…non-alpine valkey image Root cause: podman play kube converts tcpSocket liveness probes into 'nc -z -v localhost <port> || exit 1' healthchecks. Alpine's BusyBox nc does not support -z, so the healthcheck always fails. With HealthcheckOnFailureAction=restart, this causes an infinite SIGTERM restart loop (~every 30s). Changes: - valkey-cache: tcpSocket -> exec valkey-cli ping (liveness + readiness) - valkey-lf: tcpSocket -> exec valkey-cli -a <pass> ping (liveness) - Image: valkey:9.1.0-alpine -> valkey:9.1.0 (non-alpine has no nc, so no broken built-in healthcheck to conflict with) Verified in dev: 0 SIGTERMs, 0 ECONNREFUSED, both valkey instances healthy, Langfuse web/worker stable, chat completions 200 OK.
Sourcery review: valkey-cli ping without -p targets default 6379, causing false negatives when VALKEY_CACHE_PORT is customized (e.g. dev=6389). Now matches the port-aware pattern already used by valkey-lf probes.
- litellm/entrypoint.py: restore quote stripping before setdefault (prevents literal '"5432"' from breaking int() parsing) - start-stack.sh: use ROUTER_IMAGE var instead of hardcoded ghcr.io/sheepdestroyer/llm-routing:latest in build/pull paths - start-stack.sh: create volume dirs under DATA_ROOT instead of WORKDIR (fixes pod creation when DATA_ROOT != WORKDIR) - start-stack.sh: add placeholder validation to render_litellm_config and chmod 644 on rendered configs for non-root container access - scripts/backup.sh: use POD_NAME from .env instead of hardcoded agent-router-pod-postgres-db (fixes dev backup failures) - router/main.py: extract _valkey_port() helper to DRY the VALKEY_CACHE_PORT/VALKEY_PORT fallback (3 call sites) - router/main.py: replace hardcoded :3001 with LANGFUSE_WEB_PORT env var in dashboard Infrastructure Nodes display
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- scripts/backup.sh: wire POSTGRES_PORT through pg_isready -p flag (fixes backup failures when DB port is customized, e.g. dev=5442) - pod.yaml: remove redundant PORT env var (LITELLM_PORT already set) - start-stack.sh: remove undocumented --pull-latest alias - start-stack.sh: add placeholder validation to render_router_config (matches existing render_litellm_config guard) - start-stack.sh: extract deploy_fresh_pod() helper to DRY the repeated generate→render→deploy→setup→verify sequence (4 call sites) - router/main.py: use LLAMA_SERVER_URL for health check instead of hardcoded http://127.0.0.1:8080/health
Reviewer's GuideThis PR parameterizes all core service ports and pod naming for flexible prod/dev deployments, fixes Valkey health checks to avoid BusyBox nc incompatibility, and refactors deployment scripts/configs to be DRY and environment-driven while addressing earlier review feedback. Sequence diagram for deploy_fresh_pod environment-driven deploymentsequenceDiagram
participant User
participant start_stack_sh as start-stack.sh
participant clickhouse_cfg as generate_clickhouse_config
participant litellm_cfg as render_litellm_config
participant router_cfg as render_router_config
participant pod_yaml as render_pod_yaml
participant Podman as podman
participant Minio as setup_minio_buckets
participant Health as verify_stack_health
User->>start_stack_sh: run ./start-stack.sh
start_stack_sh->>clickhouse_cfg: generate_clickhouse_config
start_stack_sh->>litellm_cfg: render_litellm_config
start_stack_sh->>router_cfg: render_router_config
start_stack_sh->>pod_yaml: render_pod_yaml
pod_yaml-->>start_stack_sh: pod.yaml with POD_NAME and ports
start_stack_sh->>Podman: play kube -
Podman-->>start_stack_sh: create POD_NAME pod
start_stack_sh->>Minio: setup_minio_buckets
start_stack_sh->>Health: verify_stack_health
Health-->>User: stack healthy (router, LiteLLM, Valkey, Langfuse)
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
Next review available in: 38 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- You now derive ports and URLs from env in several places (start-stack.sh, router/main.py, litellm/entrypoint.py); consider centralizing this parsing/validation in one helper per component to avoid duplicated default logic and reduce the chance of divergence.
- The YAML rendering pipeline mixes Python placeholder replacement (pod.yaml) with sed-based templating (render_litellm_config/render_router_config); unifying these on the existing Python templater would make the configuration generation more consistent and easier to maintain.
- Router/main.py constructs the LiteLLM and Langfuse base URLs multiple times inline (e.g., in get_dashboard_data and proxy_memory) instead of reusing LITELLM_URL/LANGFUSE_HOST; reusing those globals would simplify the code and keep behavior consistent if the defaults change.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You now derive ports and URLs from env in several places (start-stack.sh, router/main.py, litellm/entrypoint.py); consider centralizing this parsing/validation in one helper per component to avoid duplicated default logic and reduce the chance of divergence.
- The YAML rendering pipeline mixes Python placeholder replacement (pod.yaml) with sed-based templating (render_litellm_config/render_router_config); unifying these on the existing Python templater would make the configuration generation more consistent and easier to maintain.
- Router/main.py constructs the LiteLLM and Langfuse base URLs multiple times inline (e.g., in get_dashboard_data and proxy_memory) instead of reusing LITELLM_URL/LANGFUSE_HOST; reusing those globals would simplify the code and keep behavior consistent if the defaults change.
## Individual Comments
### Comment 1
<location path="scripts/backup.sh" line_range="16-21" />
<code_context>
RETENTION_DAYS=14
LOG_FILE="/tmp/llm-backup-${TIMESTAMP}.log"
+# Source .env for POD_NAME and POSTGRES_PORT (with prod defaults)
+if [ -f "${WORKDIR}/.env" ]; then
+ set -a; source "${WORKDIR}/.env"; set +a
+fi
+POD_NAME="${POD_NAME:-agent-router-pod}"
+POSTGRES_PORT="${POSTGRES_PORT:-5432}"
+
mkdir -p "$BACKUP_DIR"
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Backup script only sources `.env`, so dev deployments with a different POD_NAME/ports won’t get correct backup behavior.
With `start-dev.sh` and `DEV_ENV_FILE` in `start-stack.sh`, dev setups can use different `POD_NAME`/`POSTGRES_PORT` (e.g., `dev-router-pod`). Since `backup.sh` always sources `${WORKDIR}/.env` and defaults to `agent-router-pod`, running it in dev will still target the prod pod/port. If dev backups are desired, this script should either respect `DEV_ENV_FILE` or allow the env file path to be configured.
```suggestion
# Determine env file to source for POD_NAME and POSTGRES_PORT.
# Priority: BACKUP_ENV_FILE (explicit), DEV_ENV_FILE (dev stack), then ${WORKDIR}/.env (prod default).
ENV_FILE=""
if [ -n "${BACKUP_ENV_FILE:-}" ]; then
ENV_FILE="${BACKUP_ENV_FILE}"
elif [ -n "${DEV_ENV_FILE:-}" ]; then
ENV_FILE="${DEV_ENV_FILE}"
else
ENV_FILE="${WORKDIR}/.env"
fi
if [ -f "${ENV_FILE}" ]; then
set -a; source "${ENV_FILE}"; set +a
fi
# Sensible defaults if env file did not define them
POD_NAME="${POD_NAME:-agent-router-pod}"
POSTGRES_PORT="${POSTGRES_PORT:-5432}"
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a development environment overlay (.env.dev and start-dev.sh) to run a development stack on distinct ports alongside production. It parameterizes ports, pod names, and image paths across configuration files and scripts, dynamically rendering them at startup. Feedback on the changes includes: ensuring the backup script preserves dev environment overrides by sourcing the dev environment file; checking and building local router images instead of attempting to pull them from remote registries on first deploy; stripping whitespace from parsed environment keys in litellm/entrypoint.py for robustness; and using POSIX-compliant grep -E instead of GNU-specific extensions for better portability.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| key, _, val = line.partition("=") | ||
| val = val.strip().strip('"').strip("'") | ||
| os.environ[key] = val | ||
| os.environ.setdefault(key, val) |
There was a problem hiding this comment.
The key parsed from the .env file is not stripped of whitespace. If there are spaces around the = character in the .env file (e.g., PORT = 4000), the key will contain trailing spaces (e.g., "PORT "), causing os.environ.get("PORT") to return None. Stripping the key ensures robust environment variable loading.
| key, _, val = line.partition("=") | |
| val = val.strip().strip('"').strip("'") | |
| os.environ[key] = val | |
| os.environ.setdefault(key, val) | |
| key, _, val = line.partition("=") | |
| key = key.strip() | |
| val = val.strip().strip('"').strip("'") | |
| os.environ.setdefault(key, val) |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- router/tests/test_get_redis.py: _valkey_port() now safely catches
ValueError and returns 6379, so the old test that expected int('invalid')
to crash inside get_redis() no longer applies. Split into two tests:
test_valkey_port_invalid_fallback (new) and a rewritten
test_get_redis_initialization_failure that uses aioredis.Redis
side_effect instead.
- start-stack.sh: fix broken if/elif/else chain in first-deploy path
(direct-applied commit had 'if' instead of 'elif', causing the
localhost check and pull branch to run inside FULL_REBUILD mode,
plus an extra dangling 'fi')
Summary
Parameterizes all ports and pod name for parallel prod/dev deployments, fixes the Valkey restart loop caused by BusyBox
nc -zincompatibility, and addresses all review comments from PRs #248, #249, and #250.Changes
Port & pod parameterization
.env/.env.devwith +10 offset for devPOD_NAMEenv var replaces hardcodedagent-router-podthroughoutROUTER_IMAGEenv var replaces hardcodedghcr.io/sheepdestroyer/llm-routing:latestDATA_ROOTdefaults toWORKDIR/data, volume dirs created under itdeploy_fresh_pod()helper DRYs the repeated generate→render→deploy→verify sequenceValkey healthcheck fix
tcpSocketprobes toexec valkey-cli ping(with-pport)valkey:9.1.0-alpinetovalkey:9.1.0(non-alpine has no brokennc -z)podman play kubeconverts tcpSocket tonc -z -v localhost <port>, BusyBoxnclacks-z, healthcheck always fails,HealthcheckOnFailureAction=restartcauses infinite loopReview fixes (all rounds)
litellm/entrypoint.py: restore quote stripping beforesetdefault, safe int parsing forPOSTGRES_PORTrouter/main.py: extract_valkey_port()helper (returns int, safe parsing), replace hardcoded:3001withLANGFUSE_WEB_PORT, useLLAMA_SERVER_URLfor health checkstart-stack.sh: placeholder validation in bothrender_litellm_configandrender_router_config,chmod 644on rendered configs, remove undocumented--pull-latestaliasscripts/backup.sh: usePOD_NAMEandPOSTGRES_PORTfrom.envpod.yaml: remove redundantPORTenv var (duplicate ofLITELLM_PORT)Verified in dev
Summary by Sourcery
Parameterize pod name, ports, and data directories for flexible prod/dev deployments, add dev startup wrapper, and update health checks and dependencies to stabilize Valkey, LiteLLM, Postgres, ClickHouse, Langfuse, and MinIO.
New Features:
Bug Fixes:
Enhancements:
Deployment:
Documentation:
Chores: