prometheus/tsdb
Łukasz Mierzwa 8a1086a128
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
feat: Add flag that blocks lvl 1 compactions until upload is confirmed in an external JSON file (#17435)
* Delay compactions until Thanos uploads all blocks

Using Thanos sidecar with Prometheus requires us to disable TSDB compactions on Prometheus side by setting --storage.tsdb.min-block-duration and --storage.tsdb.max-block-duration to the same value. See https://thanos.io/tip/components/sidecar.md. The main problem this avoids is that Prometheus might compact given block before Thanos uploads it, creating a gap in Thanos metrics. Thanos does not upload compacted blocks because that would upload the same sample multiple times. You can tell Thanos to upload compacted blocks but that is aimed at one time migrations. This patch creates a bridge between Thanos and Prometheus by allowing Prometheus to read the shipper file Thanos creates, where it tracks which blocks were already uploaded, and using that data delays compaction of blocks until they are marked as uploaded by Thanos. Thanks to this both services can coordinate with each other (in a way) and we can stop disabling compaction on Prometheus side when Thanos uploads are enabled.

The reason to have this is that disabling compactions have very dramatic performance cost. Since most time series exist for longer than a single block duration (2h by default) large chunks of block index will reference the same series, so 10 * 2h blocks will each have an index that is usually fairly big and is almost the same for all 10 blocks. Compaction de-duplicates the index so merging 10 blocks together would leave us with a single index that is around the same size as each of these 10 2h blocks would have (plus some extra for series that only exists in some blocks, but not all). Every range query that iterates over all 10 blocks would then have to read each index and so we're doing 10x more work then if we had a single compacted block.

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>

* Rename structs and functions to make this more generic

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>

* Address review comments

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>

* Cache UploadMeta for 1 minute

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>

---------

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>
2025-12-02 10:39:45 +00:00
..
agent feat: rename CreatedTimestamp to StartTimestamp (#17523) 2025-11-13 14:17:51 +00:00
chunkenc Add histogram validation in remote-read and during reducing resolution (#17561) 2025-11-21 00:22:24 +01:00
chunks tsdb: guard chunk length overflow in head chunk reader (#17533) 2025-11-15 21:09:00 +01:00
docs docs: Fix chunk format documentation for varint encoding 2025-08-15 10:56:21 +02:00
encoding Attempt for record type 2024-12-05 09:21:47 -08:00
errors tsdb/errors.MultiError: support errors.As (#16544) 2025-05-06 13:45:16 +00:00
fileutil chore(direct_io): fix constructor's name (#17371) 2025-10-23 11:35:16 +02:00
goversion remove obsolete build tag 2024-01-17 22:26:32 +08:00
index [PERF] TSDB: Speed up intersectPostings.Next 2025-11-10 17:00:19 +00:00
record Add histogram validation in remote-read and during reducing resolution (#17561) 2025-11-21 00:22:24 +01:00
testdata tsdb: Delete blocks atomically; Remove tmp blocks on start; Added test. (#7772) 2020-08-11 06:56:08 +01:00
tombstones docs: minor improvement for docs 2025-10-29 14:42:14 +08:00
tsdbutil Apply analyzer "modernize" to the whole codebase 2025-08-27 14:48:41 +02:00
wlog Update golangci-lint (#17478) 2025-11-05 13:47:34 +01:00
.gitignore Moving tsdb into its own subdirectory 2019-08-13 13:58:49 +05:30
block.go add NumFloatSamples to TSDB block stats 2025-07-07 13:48:18 -07:00
block_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
blockwriter.go Phase out native histogram feature flag 2025-10-15 14:50:52 +02:00
blockwriter_test.go chore: enable gci linter (#16245) 2025-03-22 15:46:13 +00:00
CHANGELOG.md Rename default branch to main 2021-02-22 20:28:02 +01:00
compact.go feat: Add flag that blocks lvl 1 compactions until upload is confirmed in an external JSON file (#17435) 2025-12-02 10:39:45 +00:00
compact_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
db.go feat: Add flag that blocks lvl 1 compactions until upload is confirmed in an external JSON file (#17435) 2025-12-02 10:39:45 +00:00
db_test.go Update golangci-lint (#17478) 2025-11-05 13:47:34 +01:00
example_test.go Add context argument to Querier.Select (#12660) 2023-09-12 12:37:38 +02:00
exemplar.go Apply analyzer "modernize" to the whole codebase 2025-08-27 14:48:41 +02:00
exemplar_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
head.go Register missing metric prometheus_tsdb_sample_ooo_delta (#17477) 2025-11-11 11:07:08 +01:00
head_append.go feat: rename CreatedTimestamp to StartTimestamp (#17523) 2025-11-13 14:17:51 +00:00
head_bench_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
head_dedupelabels.go chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
head_other.go chore: enable unused-receiver rule from revive 2025-08-04 09:43:33 +00:00
head_read.go Apply analyzer "modernize" to the whole codebase 2025-08-27 14:48:41 +02:00
head_read_test.go Apply analyzer "modernize" to the whole codebase 2025-08-27 14:48:41 +02:00
head_test.go feat: rename CreatedTimestamp to StartTimestamp (#17523) 2025-11-13 14:17:51 +00:00
head_wal.go Merge pull request #17351 from bboreham/simplify-precreate 2025-11-07 14:39:51 +01:00
isolation.go Apply analyzer "modernize" to the whole codebase 2025-08-27 14:48:41 +02:00
isolation_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
mocks_test.go chore: enable unused-receiver rule from revive 2025-08-04 09:43:33 +00:00
ooo_head.go Update golangci-lint (#17478) 2025-11-05 13:47:34 +01:00
ooo_head_read.go chore: enable unused-receiver rule from revive 2025-08-04 09:43:33 +00:00
ooo_head_read_test.go Phase out native histogram feature flag 2025-10-15 14:50:52 +02:00
ooo_head_test.go Apply analyzer "modernize" to the whole codebase 2025-08-27 14:48:41 +02:00
ooo_isolation.go Fix issue where queries can fail or omit OOO samples if OOO head compaction occurs between creating a querier and reading chunks (#13115) 2023-11-24 12:38:38 +01:00
ooo_isolation_test.go Fix issue where queries can fail or omit OOO samples if OOO head compaction occurs between creating a querier and reading chunks (#13115) 2023-11-24 12:38:38 +01:00
querier.go chore: enable unused-receiver rule from revive 2025-08-04 09:43:33 +00:00
querier_bench_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
querier_test.go Update modernize (#17471) 2025-11-04 05:13:49 +00:00
README.md Fixed broken link in tsdb README.md 2022-10-07 16:20:20 +00:00
repair.go chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
repair_test.go feat: Allow customizing TSDB postings decoder (#13567) 2024-11-11 07:59:24 +01:00
testutil.go Fix linting issues found by golangci-lint v2.0.2 (#16368) 2025-05-03 19:05:13 +02:00
tsdbblockutil.go enable errorf rule from perfsprint linter 2024-11-06 16:50:36 +01:00

TSDB

GoPkg

This directory contains the Prometheus TSDB (Time Series DataBase) library, which handles storage and querying of all Prometheus v2 data.

Documentation

External resources

A series of blog posts explaining different components of TSDB: