Querier

简要概述

查询服务(querier service)使用PromQL查询语言处理查询操作。

查询服务从摄取器和长期存储中获取时间序列样本数据:摄取器保存了尚未刷新到长期存储的内存中的时间序列样本。由于复制因子的存在,查询服务有可能接收到重复的样本数据;为了解决这个问题,在处理同一时间序列时,查询服务会对具有完全相同时间戳的样本进行内部去重操作。

查询服务是无状态的,并且可以根据需要进行扩展和缩减规模。这意味着可以根据负载和性能需求,灵活地增加或减少查询服务的实例数量,以适应不同的工作负载和流量需求。

通过从摄取器和长期存储中获取样本数据,查询服务能够提供全面的查询支持,并保证查询结果的准确性和一致性。它能够处理来自不同数据源的样本数据,并在查询过程中进行合并和去重,以提供准确的查询结果。由于查询服务的无状态特性,可以根据需要进行水平扩展,以满足不同规模和负载的查询需求。

配置示例

官方文档

querier:
  max_concurrent: 20
  timeout: 2m0s
  iterators: false
  batch_iterators: true
  ingester_streaming: true
  ingester_metadata_streaming: false
  max_samples: 50000000
  query_ingesters_within: 0s
  query_store_for_labels_enabled: false
  at_modifier_enabled: false
  per_step_stats_enabled: false
  query_store_after: 0s
  max_query_into_future: 10m0s
  default_evaluation_interval: 1m0s
  active_query_tracker_dir: ./active-query-tracker
  lookback_delta: 5m0s
  store_gateway_addresses: ""
  store_gateway_client:
    tls_enabled: false
    tls_cert_path: ""
    tls_key_path: ""
    tls_ca_path: ""
    tls_server_name: ""
    tls_insecure_skip_verify: false
    grpc_compression: ""
  shuffle_sharding_ingesters_lookback_period: 0s

数据结构

querier.Config

github.com/cortexproject/cortex/pkg/querier/querier.go

// Config contains the configuration require to create a querier
type Config struct {
    MaxConcurrent             int           `yaml:"max_concurrent"`
    Timeout                   time.Duration `yaml:"timeout"`
    Iterators                 bool          `yaml:"iterators"`
    BatchIterators            bool          `yaml:"batch_iterators"`
    IngesterStreaming         bool          `yaml:"ingester_streaming"`
    IngesterMetadataStreaming bool          `yaml:"ingester_metadata_streaming"`
    MaxSamples                int           `yaml:"max_samples"`
    QueryIngestersWithin      time.Duration `yaml:"query_ingesters_within"`
    QueryStoreForLabels       bool          `yaml:"query_store_for_labels_enabled"`
    AtModifierEnabled         bool          `yaml:"at_modifier_enabled" doc:"hidden"`
    EnablePerStepStats        bool          `yaml:"per_step_stats_enabled"`

    // QueryStoreAfter the time after which queries should also be sent to the store and not just ingesters.
    QueryStoreAfter    time.Duration `yaml:"query_store_after"`
    MaxQueryIntoFuture time.Duration `yaml:"max_query_into_future"`

    // The default evaluation interval for the promql engine.
    // Needs to be configured for subqueries to work as it is the default
    // step if not specified.
    DefaultEvaluationInterval time.Duration `yaml:"default_evaluation_interval"`

    // Directory for ActiveQueryTracker. If empty, ActiveQueryTracker will be disabled and MaxConcurrent will not be applied (!).
    // ActiveQueryTracker logs queries that were active during the last crash, but logs them on the next startup.
    // However, we need to use active query tracker, otherwise we cannot limit Max Concurrent queries in the PromQL
    // engine.
    ActiveQueryTrackerDir string `yaml:"active_query_tracker_dir"`
    // LookbackDelta determines the time since the last sample after which a time
    // series is considered stale.
    LookbackDelta time.Duration `yaml:"lookback_delta"`

    // Blocks storage only.
    StoreGatewayAddresses string       `yaml:"store_gateway_addresses"`
    StoreGatewayClient    ClientConfig `yaml:"store_gateway_client"`

    ShuffleShardingIngestersLookbackPeriod time.Duration `yaml:"shuffle_sharding_ingesters_lookback_period"`

    // Experimental. Use https://github.com/thanos-community/promql-engine rather than
    // the Prometheus query engine.
    ThanosEngine bool `yaml:"thanos_engine"`
}

ClientConfig

type ClientConfig struct {
    TLSEnabled      bool             `yaml:"tls_enabled"`
    TLS             tls.ClientConfig `yaml:",inline"`
    GRPCCompression string           `yaml:"grpc_compression"`
}



最后修改 2023.07.06: refactor: update some (5fe4b38)