thanos-query-frontend

by ScriptonBasestar

Helm chartv0.3.0App 0.37.2

Thanos Query Frontend - caching and query splitting layer for Thanos Query

About this chart

Thanos Query Frontend

Thanos Query Frontend is a caching and query splitting layer that sits in front of Thanos Query. It improves query performance by caching responses and splitting large queries into smaller ones.

Features

  • Query Caching: In-memory or Memcached response caching
  • Query Splitting: Splits long time range queries into smaller chunks
  • Query Retries: Automatic retry of failed downstream queries
  • Slow Query Logging: Identify problematic queries
  • Response Compression: Reduce bandwidth usage
  • Horizontal Scaling: Stateless design enables easy HPA

Prerequisites

  • Kubernetes 1.19+
  • Helm 3.2+
  • Thanos Query running and accessible

Installation

helm repo add scripton-charts https://scriptonbasestar-container.github.io/sb-helm-charts
helm install thanos-query-frontend scripton-charts/thanos-query-frontend \
  --set thanos.queryFrontend.downstreamUrl=http://thanos-query:10904

Configuration

Key Parameters

ParameterDescriptionDefault
replicaCountNumber of Query Frontend replicas1
thanos.queryFrontend.downstreamUrlThanos Query URLhttp://thanos-query:10904
thanos.queryFrontend.splitIntervalQuery range splitting interval24h
thanos.queryFrontend.cache.enabledEnable response cachingtrue
thanos.queryFrontend.cache.typeCache type (in-memory/memcached)in-memory
service.httpPortHTTP service port10913
ingress.enabledEnable ingressfalse
autoscaling.enabledEnable HPAfalse

Cache Configuration

In-Memory Cache (Default)

thanos:
  queryFrontend:
    cache:
      enabled: true
      type: "in-memory"
      inMemory:
        maxSize: "250MB"
        maxItems: 2048

Memcached Cache

thanos:
  queryFrontend:
    cache:
      enabled: true
      type: "memcached"
      memcached:
        addresses:
          - memcached-0.memcached:11211
          - memcached-1.memcached:11211
        timeout: "500ms"
        maxIdleConnections: 100

High Availability

replicaCount: 3

podDisruptionBudget:
  enabled: true
  minAvailable: 2

autoscaling:
  enabled: true
  minReplicas: 3
  maxReplicas: 10
  targetCPUUtilizationPercentage: 70

topologySpreadConstraints:
  - maxSkew: 1
    topologyKey: kubernetes.io/hostname
    whenUnsatisfiable: DoNotSchedule
    labelSelector:
      matchLabels:
        app.kubernetes.io/name: thanos-query-frontend

Architecture

                     +---------------------+
    Grafana -------->| Query Frontend (QF) |-----> Thanos Query
                     +---------------------+
                            |
                     +------+------+
                     |    Cache    |
                     | (in-memory/ |
                     |  memcached) |
                     +-------------+

Query Frontend provides:

  1. Caching Layer: Caches query results to reduce load on Query
  2. Query Splitting: Splits queries by time range (e.g., 24h chunks)
  3. Retry Logic: Automatically retries failed queries

Ports

PortProtocolDescription
10902HTTPInternal container port
10913HTTPDefault service port

Metrics

Query Frontend exposes Prometheus metrics at /metrics:

  • thanos_query_frontend_queries_total - Total queries processed
  • thanos_query_frontend_split_queries_total - Queries that were split
  • thanos_query_frontend_cache_hits_total - Cache hit count
  • thanos_query_frontend_cache_requests_total - Total cache requests

Enable ServiceMonitor for Prometheus Operator:

serviceMonitor:
  enabled: true
  interval: "30s"

Troubleshooting

Query Frontend Not Connecting to Query

  1. Verify downstream URL is correct:

    kubectl exec -it <pod> -- wget -qO- http://thanos-query:10904/-/ready
    
  2. Check Query Frontend logs:

    kubectl logs -l app.kubernetes.io/name=thanos-query-frontend
    

Cache Not Working

  1. Verify cache configuration in logs
  2. Check cache metrics at /metrics
  3. For memcached, ensure addresses are reachable

High Latency

  1. Increase splitInterval for fewer query splits
  2. Scale up replicas with HPA
  3. Consider using memcached for larger deployments

Values Reference

See values.yaml for all configuration options.

License

BSD-3-Clause

Deploy thanos-query-frontend with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has thanos-query-frontend on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartthanos-query-frontend is pinned at v0.3.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply