github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/docs/blocks-storage/querier.template (about)

     1  ---
     2  title: "Querier"
     3  linkTitle: "Querier"
     4  weight: 2
     5  slug: querier
     6  ---
     7  
     8  {{ .GeneratedFileWarning }}
     9  
    10  The **querier** service handles queries using the [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/) query language. The querier service is used both by the chunks and blocks storage, and the [general architecture documentation](../architecture.md#querier) applies to the blocks storage too, except for the differences described in this document.
    11  
    12  The querier is **stateless**.
    13  
    14  ## How it works
    15  
    16  The querier needs to have an almost up-to-date view over the entire storage bucket, in order to find the right blocks to lookup at query time. The querier can keep the bucket view updated in to two different ways:
    17  
    18  1. Periodically scanning the bucket (default)
    19  2. Periodically downloading the [bucket index](./bucket-index.md)
    20  
    21  ### Bucket index disabled (default)
    22  
    23  At startup, **queriers** iterate over the entire storage bucket to discover all tenants blocks and download the `meta.json` for each block. During this initial bucket scanning phase, a querier is not ready to handle incoming queries yet and its `/ready` readiness probe endpoint will fail.
    24  
    25  While running, queriers periodically iterate over the storage bucket to discover new tenants and recently uploaded blocks. Queriers do **not** download any content from blocks except a small `meta.json` file containing the block's metadata (including the minimum and maximum timestamp of samples within the block).
    26  
    27  Queriers use the metadata to compute the list of blocks that need to be queried at query time and fetch matching series from the [store-gateway](./store-gateway.md) instances holding the required blocks.
    28  
    29  ### Bucket index enabled
    30  
    31  When [bucket index](./bucket-index.md) is enabled, queriers lazily download the bucket index upon the first query received for a given tenant, cache it in memory and periodically keep it update. The bucket index contains the list of blocks and block deletion marks of a tenant, which is later used during the query execution to find the set of blocks that need to be queried for the given query.
    32  
    33  Given the bucket index removes the need to scan the bucket, it brings few benefits:
    34  
    35  1. The querier is expected to be ready shortly after startup.
    36  2. Lower volume of API calls to object storage.
    37  
    38  ### Anatomy of a query request
    39  
    40  When a querier receives a query range request, it contains the following parameters:
    41  
    42  - `query`: the PromQL query expression itself (e.g. `rate(node_cpu_seconds_total[1m])`)
    43  - `start`: the start time
    44  - `end`: the end time
    45  - `step`: the query resolution (e.g. `30` to have 1 resulting data point every 30s)
    46  
    47  Given a query, the querier analyzes the `start` and `end` time range to compute a list of all known blocks containing at least 1 sample within this time range. Given the list of blocks, the querier then computes a list of store-gateway instances holding these blocks and sends a request to each matching store-gateway instance asking to fetch all the samples for the series matching the `query` within the `start` and `end` time range.
    48  
    49  The request sent to each store-gateway contains the list of block IDs that are expected to be queried, and the response sent back by the store-gateway to the querier contains the list of block IDs that were actually queried. This list may be a subset of the requested blocks, for example due to recent blocks resharding event (ie. last few seconds). The querier runs a consistency check on responses received from the store-gateways to ensure all expected blocks have been queried; if not, the querier retries to fetch samples from missing blocks from different store-gateways (if the `-store-gateway.sharding-ring.replication-factor` is greater than `1`) and if the consistency check fails after all retries, the query execution fails as well (correctness is always guaranteed).
    50  
    51  If the query time range covers a period within `-querier.query-ingesters-within` duration, the querier also sends the request to all ingesters, in order to fetch samples that have not been uploaded to the long-term storage yet.
    52  
    53  Once all samples have been fetched from both store-gateways and ingesters, the querier proceeds with running the PromQL engine to execute the query and send back the result to the client.
    54  
    55  ### How queriers connect to store-gateway
    56  
    57  Queriers need to discover store-gateways in order to connect to them at query time. The service discovery mechanism used depends whether blocks sharding is enabled in the store-gateways.
    58  
    59  When blocks sharding is **enabled**, queriers need to access to the store-gateways hash ring and thus queriers need to be configured with the same `-store-gateway.sharding-ring.*` flags (or their respective YAML config options) store-gateways have been configured.
    60  
    61  When blocks sharding is **disabled**, queriers need the `-querier.store-gateway-addresses` CLI flag (or its respective YAML config option) being set to a comma separated list of store-gateway addresses in [DNS Service Discovery format]((../configuration/arguments.md#dns-service-discovery). Queriers will evenly balance the requests to query blocks across the resolved addresses.
    62  
    63  ## Caching
    64  
    65  The querier supports the following caches:
    66  
    67  - [Metadata cache](#metadata-cache)
    68  
    69  Caching is optional, but **highly recommended** in a production environment. Please also check out the [production tips](./production-tips.md#caching) for more information about configuring the cache.
    70  
    71  ### Metadata cache
    72  
    73  [Store-gateway](./store-gateway.md) and querier can use memcached for caching bucket metadata:
    74  
    75  - List of tenants
    76  - List of blocks per tenant
    77  - Block's `meta.json` content
    78  - Block's `deletion-mark.json` existence and content
    79  - Tenant's `bucket-index.json.gz` content
    80  
    81  Using the metadata cache can significantly reduce the number of API calls to object storage and protects from linearly scale the number of these API calls with the number of querier and store-gateway instances (because the bucket is periodically scanned and synched by each querier and store-gateway).
    82  
    83  To enable metadata cache, please set `-blocks-storage.bucket-store.metadata-cache.backend`. Only `memcached` backend is supported currently. Memcached client has additional configuration available via flags with `-blocks-storage.bucket-store.metadata-cache.memcached.*` prefix.
    84  
    85  Additional options for configuring metadata cache have `-blocks-storage.bucket-store.metadata-cache.*` prefix. By configuring TTL to zero or negative value, caching of given item type is disabled.
    86  
    87  _The same memcached backend cluster should be shared between store-gateways and queriers._
    88  
    89  ## Querier configuration
    90  
    91  This section described the querier configuration. For the general Cortex configuration and references to common config blocks, please refer to the [configuration documentation](../configuration/config-file-reference.md).
    92  
    93  {{ .QuerierConfigBlock }}
    94  
    95  {{ .BlocksStorageConfigBlock }}