towerops/test/towerops
Graham McIntire 8ff0c44e7b
Add Redis health checks and improved error handling for Exq
Fixes crashes in Exq.Node.Server when Redis connections fail by adding
health checks before startup and wrapping Exq in a custom supervisor
with better resilience.

Problem:
- Valkey pod restarting frequently (24 times in 28h) due to K8s Flannel CNI issues
- When Redis disconnects, Exq.Node.Server crashes trying to process_signals/2
- Gets nil from Redis instead of expected list, crashes on Enum.each/2
- Rapid crash/restart cycles reduce application stability

Changes:

1. RedisHealthCheck module (lib/towerops/redis_health_check.ex)
   - Waits for Redis availability with exponential backoff before starting Exq
   - Prevents Exq from starting when Redis is unavailable
   - Handles connection errors gracefully without crashing caller processes
   - Supports configurable retry attempts, timeouts, and backoff intervals

2. ExqSupervisor module (lib/towerops/exq_supervisor.ex)
   - Custom supervisor that wraps Exq with health checks
   - Uses one_for_one strategy with limited restarts (3 per 60s)
   - Prevents rapid crash loops when Redis is unstable
   - Increased Exq retry/backoff settings for better Redis recovery
   - Allows application to continue functioning without background jobs if Redis unavailable

3. Updated Application.ex
   - Replaced direct Exq start with ExqSupervisor
   - Removed inline exq_config/0 function (moved to supervisor)

4. Tests
   - Comprehensive tests for RedisHealthCheck (health checks, retries, timeouts)
   - Tests for ExqSupervisor (configuration, restart strategy)
   - All 1006 tests passing

Benefits:
- Prevents Exq crashes from propagating when Redis fails
- Application continues running even when Redis is temporarily unavailable
- Better logging of Redis connection issues
- More graceful degradation during infrastructure problems

Infrastructure Issue (to be addressed separately):
- K8s Flannel CNI plugin failing: /run/flannel/subnet.env not found
- Causing Valkey pod network issues and restarts
- Needs investigation of Flannel daemonset and node configuration

🤖 Generated with Claude Code
2026-01-19 15:38:19 -06:00
..
accounts Add UserNotifier tests 2026-01-13 08:25:20 -06:00
agents more renames 2026-01-17 15:13:56 -06:00
alerts rename equipment to device 2026-01-17 14:48:46 -06:00
api_tokens add parallel build 2026-01-19 14:17:05 -06:00
ecto_types Add comprehensive test coverage for core context modules 2026-01-19 14:38:34 -06:00
equipment test cleanup 2026-01-19 13:29:38 -06:00
monitoring Add comprehensive test coverage for Towerops.Monitoring.Ping module 2026-01-19 15:02:05 -06:00
organizations rename equipment to device 2026-01-17 14:48:46 -06:00
profiles Add comprehensive test coverage for core context modules 2026-01-19 14:38:34 -06:00
proto add parallel build 2026-01-19 14:17:05 -06:00
sites Add comprehensive tests for Sites.Site schema 2026-01-13 09:05:02 -06:00
snmp Fix Credo issues and improve code quality 2026-01-19 15:09:19 -06:00
accounts_test.exs 1. User Authentication 2025-12-21 13:31:59 -06:00
agents_test.exs Add agent rename functionality 2026-01-17 15:48:47 -06:00
alerts_test.exs Fix Credo issues and improve code quality 2026-01-19 15:09:19 -06:00
api_tokens_test.exs add parallel build 2026-01-19 14:17:05 -06:00
devices_test.exs test cleanup 2026-01-19 13:29:38 -06:00
exq_supervisor_test.exs Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
log_filter_test.exs Fix Credo issues and improve code quality 2026-01-19 15:09:19 -06:00
monitoring_test.exs feat: add latency graph for ICMP ping monitoring 2026-01-17 16:02:35 -06:00
organizations_test.exs Add comprehensive test coverage for core context modules 2026-01-19 14:38:34 -06:00
profiles_test.exs Add comprehensive test coverage for core context modules 2026-01-19 14:38:34 -06:00
redis_health_check_test.exs Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
sites_test.exs Add comprehensive test coverage for core context modules 2026-01-19 14:38:34 -06:00
snmp_test.exs test cleanup 2026-01-19 13:29:38 -06:00