# 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