RousselTMLEARNING

Observability

Thanos best practices: architecture, storage, queries and operations

Thanos best practices: adopting components gradually, external labels, objstore, single compactor, downsampling, caches, Query Frontend, security, monitoring and production checklist.

1. Designing the architecture #

Gradual adoption and identity.

Principles #

Thanos best practices
Each component adds value but also operational work: adopt them as needed.
  • 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: use thanos tools bucket mark and 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=500000
Good 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 questionExpected 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 #

Thanos high availability
The compactor also deduplicates blocks in the bucket.
count(up{job="prometheus"}) by (cluster)       # 1 avec déduplication
thanos tools bucket inspect --objstore.config-file=bucket.yml | head

Related articles

Thanos: extending Prometheus (high availability, global view and long retention)

Understand why and how to use Thanos: Prometheus limits, components (Sidecar, Query, Store Gateway, Compactor…

Thanos Sidecar: attaching Thanos to Prometheus and uploading to object storage

Set up Thanos Sidecar: Prometheus settings (external labels, 2h blocks), objstore configuration, Docker Compo…

Thanos Query and Query Frontend: a global, deduplicated view

Configure Thanos Query: StoreAPI endpoints, deduplication by replica label, partial response, web interface, …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!