RousselTMLEARNING

Observability

Thanos Query and Query Frontend: a global, deduplicated view

Configure Thanos Query: StoreAPI endpoints, deduplication by replica label, partial response, web interface, Prometheus-compatible API, Query Frontend and cache.

1. Thanos Query #

The PromQL entry point.

Starting Query #

Thanos Query exposes the Prometheus HTTP API: Grafana connects to it as it would to a regular Prometheus. For each query, it queries all its StoreAPI endpoints in parallel (sidecars, Store Gateway, Receive, other Query instances) and merges the results.

thanos query \
  --http-address=0.0.0.0:10902 \
  --grpc-address=0.0.0.0:10903 \
  --endpoint=sidecar-a:10901 \
  --endpoint=sidecar-b:10901 \
  --endpoint=store:10901 \
  --query.replica-label=replica \
  --query.auto-downsampling
# Docker Compose (extrait)
  query:
    image: quay.io/thanos/thanos:latest
    command:
      - query
      - --http-address=0.0.0.0:10902
      - --endpoint=sidecar:10901
      - --endpoint=store:10901
      - --query.replica-label=replica
    ports: ["10902:10902"]

2. Deduplication #

High availability without duplicates.

Replica label #

Deduplication by replica label
The replica label is removed to compare series.

Thanos Query treats as equivalent the series that differ only by the --query.replica-label. If one of them has a gap (restart, outage), the other fills it: this is what gives the data its high availability.

# Dans l'interface Query : activer/désactiver "Use Deduplication" et comparer
count(up{job="node"})                  # avec dédup : 1 série par instance
# sans dédup : 2 séries (replica=A et replica=B)

# Plusieurs labels de réplicas (par ex. Prometheus + Operator)
thanos query --query.replica-label=replica --query.replica-label=prometheus_replica

3. Using the interface and the API #

Stores, queries and diagnostics.

Web interface and API #

# http://localhost:10902  ->  Graph, Stores (état de chaque endpoint), Alerts, Config

# API compatible Prometheus
curl -s 'http://localhost:10902/api/v1/query?query=up' | jq '.data.result | length'
curl -s 'http://localhost:10902/api/v1/stores' | jq '.data | keys'

# Réponse partielle autorisée si un store est indisponible (par défaut) ou refusée
curl -s 'http://localhost:10902/api/v1/query?query=up&partial_response=false'

# Choisir la résolution (downsampling) : max_source_resolution en ms
curl -s 'http://localhost:10902/api/v1/query_range?query=up&start=...&end=...&step=3600&max_source_resolution=3600000'
Common mistake: A partial response can hide the absence of an entire cluster: watch the Stores page and alert on thanos_store_nodes_grpc_connections.

4. Query Frontend #

Cache and parallelization.

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.max-retries-per-request=5 \
  --query-frontend.log-queries-longer-than=5s \
  --query-range.response-cache-config-file=/etc/thanos/cache.yml
# cache.yml
type: IN-MEMORY
config:
  max_size: 512MB
  max_size_items: 0
  validity: 10m
Good practice: Point Grafana to the Query Frontend (not directly to Query): range queries are split by day, executed in parallel and cached.

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 Store Gateway and Compactor: history, downsampling and retention

Serve history with the Store Gateway and optimize storage with the Compactor: compaction, 5m/1h downsampling,…

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!