Store Gateway
2 分钟阅读
简要概述
组件 Store-gateway 存储网关负责从对象存储中获取数据块提供给 Querier 组件使用,它需要对存储桶具有几乎实时的视图,以便发现属于其分片的数据块。
为了保持对存储桶的视图更新,存储网关可以通过以下两种不同的方式来实现:
- 定期扫描存储桶(默认方式):存储网关定期扫描存储桶,以发现新的数据块并更新视图。
- 定期下载存储桶索引:存储网关可以定期下载存储桶的索引,从而快速获取最新的视图信息。
存储网关是半状态的服务,这意味着它在维护存储桶视图的过程中会保持一些状态信息。它需要跟踪已扫描或已下载的数据块,并根据需要更新存储桶的视图。这种半状态的设计使存储网关能够快速响应查询请求,并提供准确的时间序列数据。
如何工作
定期扫描
在启动 Store-gateway 组件时会从所有租户对象存储中的数据块遍历下载 “meta.json”、“index-header” 文件,在这个阶段组件是不可用的也就是 “/ready” 接口处于不可用,如果在 k8s 中编排则服务是处理非健康状态,不会加入到 Service 中不接收流量。
当正常运行时,会定期重新扫描存储桶去发现是否存在新的数据块或是否有数据块被标记删除,新数据块来自 Ingester 组件与 Compactor 组件上传生成,数据块被标记删除是由 Compactor 标记的。控制多久重新扫描一次由参数 blocks-storage.bucket-store.sync-interval
决定。
存储网关永远不会完全下载块和整个索引,既 “chunks/*” 与 “index” 文件,仅 “index” 的部分内容被下载以文件名 “index-header” 保存,以避免在随后重新启动时重新下载。因此,建议(但不是必需的)使用持久磁盘运行存储网关。例如,如果你在 Kubernetes 中运行 Cortex 集群,你可以为存储网关使用具有持久卷声明的StatefulSet。
开启存储桶索引
启用 bucket 索引后,整体工作流程是相同的,但存储网关不是迭代bucket对象,而是为属于其分片的每个租户获取bucket索引,以发现每个租户的块和块删除标记
配置示例
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:"-"`
}