175 lines
5.3 KiB
Markdown
175 lines
5.3 KiB
Markdown
# Analyse : Que fait Loki pendant "health: starting" ?
|
|
|
|
## 🔍 Situation Observée
|
|
|
|
### **État Actuel**
|
|
- **Statut Docker** : `Up X seconds (health: starting)`
|
|
- **Endpoint /ready** : Retourne HTTP 200 et "ready" ✅
|
|
- **Logs Loki** : Fonctionnement normal ✅
|
|
- **Healthcheck Docker** : Continue d'échouer ❌
|
|
|
|
### **Incohérence Détectée**
|
|
```bash
|
|
# Test manuel depuis l'extérieur - SUCCÈS
|
|
curl -s http://localhost:3100/ready # → "ready"
|
|
|
|
# Test manuel depuis l'intérieur - SUCCÈS
|
|
docker exec loki wget -q -O- http://localhost:3100/ready # → "ready"
|
|
|
|
# Healthcheck Docker - ÉCHEC
|
|
# Retourne : "Loki starting: Log aggregation service not yet ready"
|
|
```
|
|
|
|
## 🕐 Ce que Loki Attend Pendant "health: starting"
|
|
|
|
### **1. Start Period (120 secondes)**
|
|
Loki est dans la période de grâce où Docker n'évalue pas encore le healthcheck comme définitif :
|
|
- **Durée** : 120 secondes depuis le démarrage
|
|
- **Comportement** : Docker ignore les échecs de healthcheck
|
|
- **Statut** : "health: starting" → "healthy" ou "unhealthy"
|
|
|
|
### **2. Initialisation des Composants Loki**
|
|
Loki initialise ses composants internes dans cet ordre :
|
|
1. **Configuration** : Lecture du fichier de configuration
|
|
2. **Stockage** : Initialisation des volumes et index
|
|
3. **Ingester** : Composant de réception des logs
|
|
4. **Distributor** : Composant de distribution
|
|
5. **Query Frontend** : Interface de requête
|
|
6. **Table Manager** : Gestion des tables d'index
|
|
|
|
### **3. Processus de Démarrage Observé**
|
|
```bash
|
|
# Logs typiques pendant le démarrage
|
|
level=info msg="starting recalculate owned streams job"
|
|
level=info msg="completed recalculate owned streams job"
|
|
level=info msg="uploading tables" index-store=tsdb-2020-10-24
|
|
level=info msg="flushing stream" component=ingester
|
|
```
|
|
|
|
### **4. Délai d'Attente Ingester**
|
|
Loki a un **délai d'attente de l'ingester** après être "prêt" :
|
|
- **Message** : "Ingester not ready: waiting for 15s after being ready"
|
|
- **Durée** : 15 secondes supplémentaires
|
|
- **Raison** : Stabilisation des composants internes
|
|
|
|
## 🚨 Problème Identifié : Healthcheck Docker Défaillant
|
|
|
|
### **Cause Racine**
|
|
Le healthcheck Docker ne fonctionne pas correctement malgré :
|
|
- Loki fonctionnel
|
|
- Endpoint /ready accessible
|
|
- Configuration healthcheck corrigée
|
|
|
|
### **Hypothèses**
|
|
1. **Problème de timing** : Healthcheck s'exécute à un mauvais moment
|
|
2. **Problème d'environnement** : Différence d'environnement d'exécution
|
|
3. **Problème de cache Docker** : Cache healthcheck corrompu
|
|
4. **Problème de réseau interne** : Connectivité réseau Docker
|
|
|
|
## 🔧 Solutions Proposées
|
|
|
|
### **Solution 1: Healthcheck Simplifié (RECOMMANDÉE)**
|
|
```yaml
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "--spider", "http://localhost:3100/ready"]
|
|
interval: 30s
|
|
timeout: 15s
|
|
retries: 5
|
|
start_period: 120s
|
|
```
|
|
|
|
### **Solution 2: Healthcheck avec Logging Détaillé**
|
|
```yaml
|
|
healthcheck:
|
|
test: ["CMD", "sh", "-c", "echo 'Testing Loki readiness...' && wget -q --spider http://localhost:3100/ready && echo 'Loki ready' || (echo 'Loki not ready' && exit 1)"]
|
|
interval: 30s
|
|
timeout: 15s
|
|
retries: 5
|
|
start_period: 120s
|
|
```
|
|
|
|
### **Solution 3: Healthcheck Alternative (Metrics)**
|
|
```yaml
|
|
healthcheck:
|
|
test: ["CMD", "sh", "-c", "wget -q --spider http://localhost:3100/metrics || wget -q --spider http://localhost:3100/ready"]
|
|
interval: 30s
|
|
timeout: 15s
|
|
retries: 5
|
|
start_period: 120s
|
|
```
|
|
|
|
### **Solution 4: Pas de Healthcheck (Temporaire)**
|
|
```yaml
|
|
# Commentaire temporaire du healthcheck pour tester
|
|
# healthcheck:
|
|
# test: ["CMD", "wget", "-q", "--spider", "http://localhost:3100/ready"]
|
|
```
|
|
|
|
## 📊 Timeline Typique du Démarrage Loki
|
|
|
|
### **0-30 secondes : Initialisation**
|
|
- Démarrage des processus
|
|
- Lecture de la configuration
|
|
- Initialisation du stockage
|
|
|
|
### **30-60 secondes : Composants**
|
|
- Démarrage de l'ingester
|
|
- Démarrage du distributor
|
|
- Initialisation des tables
|
|
|
|
### **60-90 secondes : Stabilisation**
|
|
- Recalcul des streams
|
|
- Upload des tables d'index
|
|
- Flush des streams
|
|
|
|
### **90-120 secondes : Finalisation**
|
|
- Délai d'attente ingester (15s)
|
|
- Stabilisation finale
|
|
- Service prêt
|
|
|
|
## 🎯 Recommandations
|
|
|
|
### **Immédiate**
|
|
1. **Simplifier le healthcheck** pour éliminer les variables
|
|
2. **Augmenter les timeouts** si nécessaire
|
|
3. **Surveiller les logs** pendant le démarrage
|
|
|
|
### **À Moyen Terme**
|
|
1. **Optimiser la configuration Loki** pour un démarrage plus rapide
|
|
2. **Ajuster les ressources** (mémoire, CPU) si nécessaire
|
|
3. **Documenter les patterns** de démarrage observés
|
|
|
|
### **Monitoring**
|
|
1. **Surveiller la durée** de démarrage
|
|
2. **Alerter** si le démarrage prend plus de 2 minutes
|
|
3. **Documenter** les variations de performance
|
|
|
|
## 🔍 Diagnostic Continue
|
|
|
|
### **Commandes Utiles**
|
|
```bash
|
|
# Vérifier le statut
|
|
docker compose --env-file .env.master ps loki
|
|
|
|
# Vérifier les logs de démarrage
|
|
docker logs loki --tail 50
|
|
|
|
# Tester l'endpoint manuellement
|
|
curl -s http://localhost:3100/ready
|
|
|
|
# Vérifier les healthchecks
|
|
docker inspect loki --format='{{range .State.Health.Log}}{{.Start}} - {{.ExitCode}}: {{.Output}}{{end}}' | tail -5
|
|
```
|
|
|
|
### **Métriques à Surveiller**
|
|
- **Temps de démarrage** : < 2 minutes
|
|
- **Disponibilité endpoint** : /ready retourne "ready"
|
|
- **Logs d'erreur** : Absence d'erreurs critiques
|
|
- **Ressources** : Utilisation CPU/mémoire acceptable
|
|
|
|
---
|
|
|
|
**Document créé le 2025-09-21**
|
|
**Version** : 1.0
|
|
**Analyse** : Loki Health Starting Process
|