prometheus/tsdb
George Krajcsovits 3f59fe1a80
fix(chunkenc): appending histograms with empty buckets (#16893)
* test(chunkenc): appending histograms with empty buckets and gaps

Append such native histograms that have empty buckets and gaps
between the indexes of those buckets.

There is a special case for appending counter native histograms to a chunk in TSDB: if we append a histogram that is missing some buckets that are already in chunk, then usually that's a counter reset. However if the missing bucket is empty, meaning its value is 0, then we don't consider it missing.

For this case to trigger , we need to write empty buckets into the chunk. Normally native histograms are compacted when we emit them , so this is very rare and compact make sure that there are no multiple continuous empty buckets with gaps between them.

The code that I've added in #14513 did not take into account that you can bypass compact and write histograms with many empty buckets, with gaps between them. These are still valid, so the code has to account for them.

Main fix in the expandIntSpansAndBuckets and expandFloatSpansAndBuckets function. I've also refactored them for clarity. Consequently needed to fix insert and adjustForInserts to also allow gaps between inserts.

I've added some new test cases (data driven test would be nice here, too many cases). And removed the deprecated old function that didn't deal with empty buckets at all.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Signed-off-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Björn Rabenstein <beorn@grafana.com>
2025-07-24 18:01:02 +02:00
..
agent refactor: use the built-in max/min to simplify the code 2025-05-20 14:36:39 +08:00
chunkenc fix(chunkenc): appending histograms with empty buckets (#16893) 2025-07-24 18:01:02 +02:00
chunks tsdb: fix issue where a new segment file is created for every chunk if WithSegmentSize not called (#16635) 2025-05-28 18:21:59 +02:00
docs chore: fix some comments (#16237) 2025-03-19 16:28:34 +01: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 fix(test): fall back to default direct I/O requirements in tests when statx isn't supported by using a higher lever util 2025-05-29 09:35:33 +02:00
goversion remove obsolete build tag 2024-01-17 22:26:32 +08:00
index refactor: use slices.Contains to simplify code 2025-05-09 08:27:10 +02:00
record chore: enable gci linter (#16245) 2025-03-22 15:46:13 +00:00
testdata tsdb: Delete blocks atomically; Remove tmp blocks on start; Added test. (#7772) 2020-08-11 06:56:08 +01:00
tombstones refactor: use the built-in max/min to simplify the code 2025-05-20 14:36:39 +08:00
tsdbutil chore: enable gci linter (#16245) 2025-03-22 15:46:13 +00:00
wlog fix(remote): Unregister metrics emitted by remote.WriteStorage when closed (#16868) 2025-07-17 11:32:15 +02:00
.gitignore Moving tsdb into its own subdirectory 2019-08-13 13:58:49 +05:30
block_test.go [PERF] TSDB: Pass down label value limit into implementation (#16158) 2025-05-06 18:54:48 +01:00
block.go add NumFloatSamples to TSDB block stats 2025-07-07 13:48:18 -07:00
blockwriter_test.go chore: enable gci linter (#16245) 2025-03-22 15:46:13 +00:00
blockwriter.go Upgrade to github.com/oklog/ulid/v2 (#16168) 2025-03-05 16:03:25 +01:00
CHANGELOG.md Rename default branch to main 2021-02-22 20:28:02 +01:00
compact_test.go test(tsdb): disable TestDelayedCompaction/delayed_compaction_enabled on windows 2025-07-22 15:30:05 +01:00
compact.go chore(tsdb): remove NewLeveledCompactorWithChunkSize constructor as unused, library users ca can redefine it on their side 2025-07-09 17:10:13 +01:00
db_test.go chore: fix some minor issues in comments 2025-07-16 11:24:42 +01:00
db.go refactor: use the built-in max/min to simplify the code (#16617) 2025-05-27 14:42:50 +02:00
example_test.go Add context argument to Querier.Select (#12660) 2023-09-12 12:37:38 +02:00
exemplar_test.go tsdb.CircularExemplarStorage: Avoid racing (#15231) 2024-10-29 10:40:46 +01:00
exemplar.go refactor: use the built-in max/min to simplify the code 2025-05-20 14:36:39 +08:00
head_append.go fix: unlock of unlocked mutex (#16332) 2025-07-09 15:37:55 +02:00
head_bench_test.go Create memSeries with pendingCommit=true 2025-03-27 11:11:57 +01: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-parameter from revive 2025-02-19 19:50:28 +01:00
head_read_test.go Create memSeries with pendingCommit=true 2025-03-27 11:11:57 +01:00
head_read.go refactor: use the built-in max/min to simplify the code 2025-05-20 14:36:39 +08:00
head_test.go chore(tsdb): add a few more testcases for unlock of unlocked mtx 16332 (#16848) 2025-07-09 16:24:46 +02:00
head_wal.go refactor: use the built-in max/min to simplify the code 2025-05-20 14:36:39 +08:00
head.go Merge pull request #16333 from colega/fix-series-create-gc-race 2025-04-17 12:15:11 +01:00
isolation_test.go chore: enable unused-parameter from revive 2025-02-19 19:50:28 +01:00
isolation.go chore: enable early-return from revive 2025-02-10 22:08:43 +01:00
mocks_test.go tsdb: use Go standard errors 2023-12-11 12:18:54 +00:00
ooo_head_read_test.go [PERF] TSDB: Pass down label value limit into implementation (#16158) 2025-05-06 18:54:48 +01:00
ooo_head_read.go [PERF] TSDB: Pass down label value limit into implementation (#16158) 2025-05-06 18:54:48 +01:00
ooo_head_test.go Fix linting issues found by golangci-lint v2.0.2 (#16368) 2025-05-03 19:05:13 +02:00
ooo_head.go Add util/compression package to consolidate snappy/zstd use in Prometheus. (#16156) 2025-03-10 10:36:26 +00: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
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
querier_bench_test.go [PERF] TSDB: Pass down label value limit into implementation (#16158) 2025-05-06 18:54:48 +01:00
querier_test.go tsdb tests: fix mockIndex implementation 2025-07-10 15:59:38 -03:00
querier.go [PERF] TSDB: Pass down label value limit into implementation (#16158) 2025-05-06 18:54:48 +01:00
README.md Fixed broken link in tsdb README.md 2022-10-07 16:20:20 +00:00
repair_test.go feat: Allow customizing TSDB postings decoder (#13567) 2024-11-11 07:59:24 +01:00
repair.go chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04: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: