Store Gateway

简要概述

存储网关(store gateway)是Cortex中负责从数据块中查询时间序列的服务,它需要对存储桶具有几乎实时的视图,以便发现属于其分片的数据块。为了保持对存储桶的视图更新,存储网关可以通过以下两种不同的方式来实现:

  1. 定期扫描存储桶(默认方式):存储网关定期扫描存储桶,以发现新的数据块并更新视图。
  2. 定期下载存储桶索引:存储网关可以定期下载存储桶的索引,从而快速获取最新的视图信息。

通过这两种方式,存储网关能够保持对存储桶的准确视图,以便有效地进行时间序列查询操作。

存储网关是半状态的服务,这意味着它在维护存储桶视图的过程中会保持一些状态信息。它需要跟踪已扫描或已下载的数据块,并根据需要更新存储桶的视图。这种半状态的设计使存储网关能够快速响应查询请求,并提供准确的时间序列数据。

存储网关在Cortex中扮演着重要的角色,它是查询服务的一部分,负责从数据块中检索时间序列数据。通过定期扫描存储桶或下载存储桶索引,存储网关能够保持对存储桶的实时视图,从而提供高效且准确的查询功能。详细信息可参阅存储网关的文档。

配置示例

auth_enabled: false

target: store-gateway

server:
  http_listen_port: 9091

store_gateway:
  sharding_enabled: true
  sharding_ring:
    kvstore:
      store: "etcd"
      prefix: "/cortex/store-gateway/"
      etcd:
        endpoints: ["192.168.30.125:2379"]
        dial_timeout: 10s
        max_retries: 10
        tls_enabled: false
        tls_insecure_skip_verify: false
    heartbeat_period: 5s
    heartbeat_timeout: 1m0s
    instance_id: node1
    instance_interface_names:
    - en0

blocks_storage:
  tsdb:
    dir: ./data/cortex/tsdb1
  bucket_store:
    sync_dir: ./data/cortex/tsdb-sync1
  backend: filesystem

数据结构

Config

// Config holds the store gateway config.
type Config struct {
    ShardingEnabled  bool       `yaml:"sharding_enabled"`
    ShardingRing     RingConfig `yaml:"sharding_ring" doc:"description=The hash ring configuration. This option is required only if blocks sharding is enabled."`
    ShardingStrategy string     `yaml:"sharding_strategy"`
}

RingConfig

// RingConfig masks the ring lifecycler config which contains
// many options not really required by the store gateways ring. This config
// is used to strip down the config to the minimum, and avoid confusion
// to the user.
type RingConfig struct {
    KVStore              kv.Config     `yaml:"kvstore" doc:"description=The key-value store used to share the hash ring across multiple instances. This option needs be set both on the store-gateway and querier when running in microservices mode."`
    HeartbeatPeriod      time.Duration `yaml:"heartbeat_period"`
    HeartbeatTimeout     time.Duration `yaml:"heartbeat_timeout"`
    ReplicationFactor    int           `yaml:"replication_factor"`
    TokensFilePath       string        `yaml:"tokens_file_path"`
    ZoneAwarenessEnabled bool          `yaml:"zone_awareness_enabled"`

    // Wait ring stability.
    WaitStabilityMinDuration time.Duration `yaml:"wait_stability_min_duration"`
    WaitStabilityMaxDuration time.Duration `yaml:"wait_stability_max_duration"`

    // Instance details
    InstanceID             string   `yaml:"instance_id" doc:"hidden"`
    InstanceInterfaceNames []string `yaml:"instance_interface_names"`
    InstancePort           int      `yaml:"instance_port" doc:"hidden"`
    InstanceAddr           string   `yaml:"instance_addr" doc:"hidden"`
    InstanceZone           string   `yaml:"instance_availability_zone"`

    // Injected internally
    ListenPort      int           `yaml:"-"`
    RingCheckPeriod time.Duration `yaml:"-"`
}



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