1. Designing the architecture #
Gradual adoption and identity.
Principles #
- Start with Sidecar + Query + Store Gateway + Compactor; add Ruler, Receive or Query Frontend when a need requires it.
- Unique, immutable external_labels (
cluster,replica): changing them amounts to creating new series. - One bucket per environment, with versioning and encryption enabled.
thanos tools bucket ls --objstore.config-file=bucket.yml
thanos tools bucket inspect --objstore.config-file=bucket.yml | head
curl -s localhost:10902/api/v1/stores | jq '.data | keys'2. Storage and compaction #
One compactor, well-thought-out retention.
Settings #
thanos compact --data-dir=/var/thanos/compact --objstore.config-file=/etc/thanos/bucket.yml --wait \
--retention.resolution-raw=30d --retention.resolution-5m=180d --retention.resolution-1h=730d \
--compact.concurrency=2 --delete-delay=48h --deduplication.replica-label=replica- A single compactor instance per bucket (logical lock).
- Short raw retention (30 d), longer for 5 min and 1 h: downsampling reduces cost and query time.
- Size the compactor's temporary disk: it must hold the largest blocks being compacted.
Common mistake: Never delete blocks by hand in the bucket: usethanos tools bucket markand let the compactor apply the--delete-delay.
3. Fast queries #
Query Frontend, caches and limits.
Configuration #
thanos query-frontend --http-address=0.0.0.0:9090 --query-frontend.downstream-url=http://query:10902 \
--query-range.split-interval=24h --query-range.response-cache-config-file=/etc/thanos/cache.yml
thanos query --query.auto-downsampling --query.max-concurrent=20 --query.timeout=2m --store.response-timeout=30s
thanos store --index-cache.config-file=/etc/thanos/index-cache.yml --store.limits.request-series=500000Good practice: Use recording rules for heavy dashboard queries: they avoid scanning months of raw data at each refresh.
4. Security, monitoring and review #
Ready for production.
Essential alerts #
thanos_compact_halted == 1
increase(thanos_shipper_uploads_failed_total[1h]) > 0
thanos_sidecar_prometheus_up == 0
count(thanos_store_nodes_grpc_connections) < 3
rate(grpc_server_handled_total{grpc_code!="OK", job=~"thanos-.*"}[5m]) > 0.05| Review question | Expected answer |
|---|---|
| Does a single compactor write to the bucket? | Yes |
| Are the external_labels unique? | Yes, cluster + replica |
| Do components communicate over TLS? | Yes (--grpc-server-tls-* flags) |
| Has restoring been tested? | Yes: reading an old block via Store |
| Are bucket permissions minimal? | Read/write limited to the environment prefix |
Reference diagram and quick check #
Visualize the principle and check it from the command line.
Reference diagram #
count(up{job="prometheus"}) by (cluster) # 1 avec déduplication
thanos tools bucket inspect --objstore.config-file=bucket.yml | head