单一存储 TSDB (tsdb)
从 Loki v2.8 开始,TSDB 是推荐的 Loki 索引。它深受 Prometheus 的 TSDB 子项目启发。要获得更深入的解释,你可以阅读 Loki 维护者 Owen 的博客文章。简单来说,这个新索引更高效、更快且更具可扩展性。它也像之前的 boltdb-shipper 索引一样驻留在对象存储中。
配置示例
要开始使用 TSDB,请将以下配置添加到你的 config.yaml
文件中
schema_config:
configs:
# Old boltdb-shipper schema. Included in example for reference but does not need changing.
- from: "2023-01-03" # <---- A date in the past
index:
period: 24h
prefix: index_
object_store: gcs
schema: v12
store: boltdb-shipper
# New TSDB schema below
- from: "2023-01-05" # <---- A date in the future
index:
period: 24h
prefix: index_
object_store: gcs
schema: v13
store: tsdb
storage_config:
# Old boltdb-shipper configuration. Included in example for reference but does not need changing.
boltdb_shipper:
active_index_directory: /data/index
build_per_tenant_index: true
cache_location: /data/boltdb-cache
index_gateway_client:
# only applicable if using microservices where index-gateways are independently deployed.
# This example is using kubernetes-style naming.
server_address: dns:///index-gateway.<namespace>.svc.cluster.local:9095
# New tsdb-shipper configuration
tsdb_shipper:
active_index_directory: /data/tsdb-index
cache_location: /data/tsdb-cache
index_gateway_client:
# only applicable if using microservices where index-gateways are independently deployed.
# This example is using kubernetes-style naming.
server_address: dns:///index-gateway.<namespace>.svc.cluster.local:9095
query_scheduler:
# the TSDB index dispatches many more, but each individually smaller, requests.
# We increase the pending request queue sizes to compensate.
max_outstanding_requests_per_tenant: 32768
querier:
# Each `querier` component process runs a number of parallel workers to process queries simultaneously.
# You may want to adjust this up or down depending on your resource usage
# (more available cpu and memory can tolerate higher values and vice versa),
# but we find the most success running at around `16` with tsdb
max_concurrent: 16
操作
限制
我们在 limits_config
中添加了一个名为 tsdb_max_query_parallelism
的每租户用户限制。它的功能与之前的 max_query_parallelism
配置相同,但应用于 TSDB 查询。由于 TSDB 索引会创建比其之前的其他索引类型多得多的较小查询,我们添加了一个单独的配置,以便它们可以共存。这在不同索引类型之间迁移时很有帮助。默认并行度为 128
,适用于大多数情况,但你可以根据需要在 limits_config
中全局扩展它,或在 overrides
文件中按租户扩展。
动态查询分片
以前我们根据此处配置的索引行分片静态分片查询。TSDB 根据查询将处理的数据量进行动态查询分片。我们还在 TSDB 索引中为每个块额外存储大小(KB)和行数,然后由Query Frontend 用于规划查询。根据我们操作多个 Loki 集群的经验,我们将 TSDB 配置为目标是每个查询分片处理 300-600 MB 的数据。这意味着使用 TSDB 时,我们将运行更多但更小的查询。
无需索引缓存
TSDB 是一种紧凑且优化的格式。Loki 目前不为 TSDB 使用索引缓存。如果你已经在 Loki 中使用其他索引类型,建议保留索引缓存,直到所有现有数据超出保留期,或者超出limits_config 中配置的 max_query_lookback
。在此之后,我们建议不使用索引缓存运行(TSDB 不使用它)。