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 #
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_replica3. 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: 10mGood practice: Point Grafana to the Query Frontend (not directly to Query): range queries are split by day, executed in parallel and cached.
