Pular para o conteúdo principal

Fase 3: Health Checks Ativos

Objetivo: Monitoramento proativo de saúde ao invés de detecção reativa de falhas.

Estado Atual (Passivo)

// Detecta falha apenas quando conexão falha
match TcpStream::connect(backend).await {
Ok(stream) => use_backend(stream),
Err(_) => mark_unhealthy(backend), // Tarde demais!
}

Estado Alvo (Ativo + Passivo)

// Verificador de saúde em background
async fn health_checker(backends: Vec<Backend>) {
loop {
for backend in &backends {
let health = check_health(backend).await;
update_health_status(backend, health);
}
sleep(Duration::from_secs(5)).await;
}
}

async fn check_health(backend: &Backend) -> HealthStatus {
// Verificação TCP
let tcp_ok = tcp_connect(backend, timeout).await.is_ok();

// Verificação HTTP (se aplicável)
let http_ok = http_get(backend, "/health").await
.map(|r| r.status().is_success())
.unwrap_or(false);

// Medição de RTT
let rtt = measure_rtt(backend).await;

HealthStatus { tcp_ok, http_ok, rtt }
}

Tipos de Health Check

TipoProtocoloVerificaçãoFrequência
TCPL4Porta aberta5s
HTTPL7GET /health retorna 2xx10s
gRPCL7grpc.health.v1.Health10s
CustomQualquerScript definido pelo usuárioConfigurável

Benefícios

  • Detecção proativa: Saber antes dos usuários reclamarem
  • Degradação gradual: Soft limit antes de falha hard
  • Roteamento baseado em RTT: Rotear para backend mais rápido
  • Integração com alertas: Notificar em mudanças de saúde

Relacionado