RousselTMLEARNING

Observability

Thanos Store Gateway and Compactor: history, downsampling and retention

Serve history with the Store Gateway and optimize storage with the Compactor: compaction, 5m/1h downsampling, per-resolution retention, caches and bucket tools.

1. Store Gateway #

Reading history from object storage.

Starting the store #

thanos store \
  --data-dir=/var/thanos/store \
  --objstore.config-file=/etc/thanos/bucket.yml \
  --grpc-address=0.0.0.0:10901 \
  --http-address=0.0.0.0:10902 \
  --index-cache-size=2GB \
  --chunk-pool-size=2GB \
  --store.limits.request-series=500000 \
  --min-time=-90d      # ne servir que les 90 derniers jours (partitionnement temporel)
# Docker Compose (extrait)
  store:
    image: quay.io/thanos/thanos:latest
    command:
      - store
      - --data-dir=/var/thanos/store
      - --objstore.config-file=/etc/thanos/bucket.yml
      - --grpc-address=0.0.0.0:10901
      - --http-address=0.0.0.0:10902
    volumes: ["./bucket.yml:/etc/thanos/bucket.yml", "store-data:/var/thanos/store"]
Good to know: The Store Gateway keeps only the lightweight index and headers on disk: data is read on demand from object storage. Provide a persistent volume to avoid downloading everything again at each restart.

2. Compactor #

Compacting, downsampling, deleting.

The three missions #

Resolutions and downsampling
Downsampling speeds up queries over long periods.
  • Compaction: merges small 2h blocks into larger blocks (up to 14 days) and deduplicates replicas vertically.
  • Downsampling: creates 5-minute then 1-hour blocks (min, max, sum, count, counter aggregates).
  • Retention: deletes blocks older than the configured duration, per resolution.
thanos compact \
  --data-dir=/var/thanos/compact \
  --objstore.config-file=/etc/thanos/bucket.yml \
  --http-address=0.0.0.0:10902 \
  --retention.resolution-raw=30d \
  --retention.resolution-5m=180d \
  --retention.resolution-1h=730d \
  --compact.concurrency=2 \
  --downsample.concurrency=2 \
  --delete-delay=48h \
  --wait                  # tourne en continu (sinon une passe puis arrêt)
Common mistake: Only one compactor instance must write to a given bucket. Two simultaneous compactors corrupt blocks. Watch thanos_compact_halted: at 1, the compactor has stopped on a critical error.

3. Bucket tools #

Inspecting and repairing.

thanos tools bucket #

thanos tools bucket ls       --objstore.config-file=bucket.yml            # lister les blocs
thanos tools bucket inspect  --objstore.config-file=bucket.yml            # tableau : ULID, plage, résolution, séries, taille
thanos tools bucket verify   --objstore.config-file=bucket.yml            # vérifier l'intégrité
thanos tools bucket web      --objstore.config-file=bucket.yml            # interface web des blocs
thanos tools bucket downsample --objstore.config-file=bucket.yml          # forcer un downsampling
thanos tools bucket mark --id=<ULID> --marker=deletion-mark.json --details="bloc corrompu" --objstore.config-file=bucket.yml

4. Checking the result #

What does the bucket contain?

Sample output #

Blocks in the bucket
The RES column shows the resolution: 0 = raw, 5m, 1h.
# Métriques utiles
thanos_compact_group_compactions_total
thanos_compact_downsample_total
thanos_compact_todo_compactions
thanos_blocks_meta_synced{state="loaded"}

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!