225 lines
5.5 KiB
Markdown
225 lines
5.5 KiB
Markdown
# Résolution du Problème Loki Unhealthy
|
|
|
|
## 🎯 Problème Résolu
|
|
|
|
**Statut final** : Loki est maintenant `(healthy)` ✅
|
|
|
|
## 🔍 Cause Racine Identifiée
|
|
|
|
### **Problème Principal : Configuration d'Écoute Incorrecte**
|
|
```yaml
|
|
# ❌ Configuration par défaut (PROBLÉMATIQUE)
|
|
server:
|
|
http_listen_port: 3100
|
|
grpc_listen_port: 9096
|
|
|
|
common:
|
|
instance_addr: 127.0.0.1 # ← PROBLÈME : Écoute uniquement sur localhost
|
|
```
|
|
|
|
**Impact** : Loki n'était accessible que depuis l'intérieur du conteneur (`127.0.0.1`), mais pas depuis l'extérieur, causant l'échec du healthcheck Docker.
|
|
|
|
### **Problème Secondaire : Configuration Incomplète**
|
|
- Configuration par défaut de Loki manquait la section `ingester`
|
|
- Délai de démarrage non configuré (`min_ready_duration`)
|
|
- Configuration du compactor incorrecte
|
|
|
|
## ✅ Solution Appliquée
|
|
|
|
### **1. Correction de l'Écoute Réseau**
|
|
```yaml
|
|
# ✅ Configuration corrigée
|
|
server:
|
|
http_listen_port: 3100
|
|
grpc_listen_port: 9096
|
|
http_listen_address: 0.0.0.0 # ← SOLUTION : Écoute sur toutes les interfaces
|
|
grpc_listen_address: 0.0.0.0
|
|
|
|
common:
|
|
instance_addr: 0.0.0.0 # ← SOLUTION : Adresse sur toutes les interfaces
|
|
```
|
|
|
|
### **2. Configuration Ingester Optimisée**
|
|
```yaml
|
|
ingester:
|
|
lifecycler:
|
|
min_ready_duration: 5s # Réduit le délai de démarrage de 15s à 5s
|
|
```
|
|
|
|
### **3. Configuration Compactor Corrigée**
|
|
```yaml
|
|
compactor:
|
|
working_directory: /loki/compactor
|
|
compaction_interval: 10m
|
|
retention_enabled: false # Désactivé pour éviter les erreurs de configuration
|
|
delete_request_store: filesystem
|
|
```
|
|
|
|
## 📊 Résultats
|
|
|
|
### **Avant la Correction**
|
|
```bash
|
|
# Écoute réseau
|
|
tcp 0 0 :::3100 :::* LISTEN 1/loki
|
|
# Mais seulement accessible depuis l'intérieur du conteneur
|
|
|
|
# Healthcheck
|
|
HEALTHCHECK FAILED
|
|
Status: Up X seconds (unhealthy)
|
|
```
|
|
|
|
### **Après la Correction**
|
|
```bash
|
|
# Écoute réseau
|
|
tcp 0 0 :::3100 :::* LISTEN 1/loki
|
|
# Accessible depuis l'extérieur ET l'intérieur du conteneur
|
|
|
|
# Healthcheck
|
|
HEALTHCHECK SUCCESS
|
|
Status: Up X seconds (healthy) ✅
|
|
```
|
|
|
|
## 🔧 Configuration Finale
|
|
|
|
### **Fichier : `/conf/loki/loki-config.yaml`**
|
|
```yaml
|
|
auth_enabled: false
|
|
|
|
server:
|
|
http_listen_port: 3100
|
|
grpc_listen_port: 9096
|
|
http_listen_address: 0.0.0.0
|
|
grpc_listen_address: 0.0.0.0
|
|
|
|
common:
|
|
instance_addr: 0.0.0.0
|
|
path_prefix: /loki
|
|
storage:
|
|
filesystem:
|
|
chunks_directory: /loki/chunks
|
|
rules_directory: /loki/rules
|
|
replication_factor: 1
|
|
ring:
|
|
kvstore:
|
|
store: inmemory
|
|
|
|
schema_config:
|
|
configs:
|
|
- from: 2020-10-24
|
|
store: tsdb
|
|
object_store: filesystem
|
|
schema: v13
|
|
index:
|
|
prefix: index_
|
|
period: 24h
|
|
|
|
ruler:
|
|
alertmanager_url: http://localhost:9093
|
|
|
|
ingester:
|
|
lifecycler:
|
|
min_ready_duration: 5s
|
|
|
|
limits_config:
|
|
reject_old_samples: true
|
|
reject_old_samples_max_age: 168h
|
|
max_cache_freshness_per_query: 10m
|
|
split_queries_by_interval: 15m
|
|
max_query_parallelism: 32
|
|
max_streams_per_user: 0
|
|
max_line_size: 256000
|
|
ingestion_rate_mb: 16
|
|
ingestion_burst_size_mb: 32
|
|
per_stream_rate_limit: 3MB
|
|
per_stream_rate_limit_burst: 15MB
|
|
max_entries_limit_per_query: 5000
|
|
max_query_series: 500
|
|
max_query_length: 721h
|
|
cardinality_limit: 100000
|
|
max_streams_matchers_per_query: 1000
|
|
max_concurrent_tail_requests: 10
|
|
|
|
storage_config:
|
|
tsdb_shipper:
|
|
active_index_directory: /loki/tsdb-index
|
|
cache_location: /loki/tsdb-cache
|
|
filesystem:
|
|
directory: /loki/chunks
|
|
|
|
compactor:
|
|
working_directory: /loki/compactor
|
|
compaction_interval: 10m
|
|
retention_enabled: false
|
|
delete_request_store: filesystem
|
|
|
|
analytics:
|
|
reporting_enabled: false
|
|
```
|
|
|
|
### **Docker Compose : Volume Mapping**
|
|
```yaml
|
|
loki:
|
|
image: grafana/loki:latest
|
|
container_name: loki
|
|
ports:
|
|
- "0.0.0.0:3100:3100"
|
|
volumes:
|
|
- loki_data:/loki
|
|
- ./conf/loki/loki-config.yaml:/etc/loki/loki-config.yaml:ro
|
|
command: -config.file=/etc/loki/loki-config.yaml
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "--spider", "http://localhost:3100/ready"]
|
|
interval: 30s
|
|
timeout: 15s
|
|
retries: 3
|
|
start_period: 120s
|
|
```
|
|
|
|
## 🎯 Leçons Apprises
|
|
|
|
### **1. Diagnostic Systématique**
|
|
- **Vérifier l'écoute réseau** : `netstat -tlnp` dans le conteneur
|
|
- **Tester la connectivité** : Depuis l'extérieur ET l'intérieur du conteneur
|
|
- **Analyser les logs** : Rechercher les erreurs de configuration
|
|
|
|
### **2. Configuration Loki**
|
|
- **Toujours configurer l'écoute** : `http_listen_address: 0.0.0.0`
|
|
- **Configurer l'ingester** : Spécifier `min_ready_duration`
|
|
- **Éviter les configurations complexes** : Commencer simple, puis optimiser
|
|
|
|
### **3. Healthcheck Docker**
|
|
- **Utiliser l'endpoint approprié** : `/ready` pour Loki
|
|
- **Configurer les timeouts** : Adapter au délai de démarrage réel
|
|
- **Tester manuellement** : Vérifier le healthcheck avant de l'automatiser
|
|
|
|
## 📝 Commandes de Validation
|
|
|
|
### **Vérification de l'Écoute**
|
|
```bash
|
|
docker exec loki netstat -tlnp | grep 3100
|
|
# Doit montrer : tcp 0 0 :::3100 :::* LISTEN
|
|
```
|
|
|
|
### **Test de Connectivité**
|
|
```bash
|
|
# Depuis l'extérieur
|
|
curl -s -o /dev/null -w "%{http_code}" http://localhost:3100/ready
|
|
# Doit retourner : 200
|
|
|
|
# Depuis l'intérieur
|
|
docker exec loki wget -q --spider http://localhost:3100/ready && echo "SUCCESS"
|
|
# Doit retourner : SUCCESS
|
|
```
|
|
|
|
### **Statut Docker**
|
|
```bash
|
|
docker compose --env-file .env.master ps loki
|
|
# Doit montrer : (healthy) ✅
|
|
```
|
|
|
|
---
|
|
|
|
**Problème résolu le 2025-09-21**
|
|
**Version** : 1.0
|
|
**Statut** : ✅ RÉSOLU - Loki healthy
|