Skip to content

tsdb: Track stale series in the Head block based on stale sample#16925

Merged
codesome merged 4 commits intomainfrom
codesome/stale-series-tracking
Aug 19, 2025
Merged

tsdb: Track stale series in the Head block based on stale sample#16925
codesome merged 4 commits intomainfrom
codesome/stale-series-tracking

Conversation

@codesome
Copy link
Member

@codesome codesome commented Jul 25, 2025

Related to #13616 and prometheus/proposals#55. But irrespective of what we do for compaction of stale series, it will be good to have tracking of how many stale series we have in the Head block

[FEATURE] tsdb: Track stale series in the memory based on stale samples. Exposed via `prometheus_tsdb_head_stale_series`.

@codesome codesome changed the title Track stale series in the Head block of TSDB Track stale series in the Head block based on stale sample Aug 6, 2025
@codesome codesome force-pushed the codesome/stale-series-tracking branch from fd57aea to 42ce9d8 Compare August 6, 2025 23:32
@codesome codesome marked this pull request as ready for review August 6, 2025 23:34
@codesome codesome requested a review from jesusvazquez as a code owner August 6, 2025 23:34
@codesome codesome requested a review from bboreham August 6, 2025 23:34
Signed-off-by: Ganesh Vernekar <ganesh.vernekar@reddit.com>
Signed-off-by: Ganesh Vernekar <ganesh.vernekar@reddit.com>
Signed-off-by: Ganesh Vernekar <ganesh.vernekar@reddit.com>
Signed-off-by: Ganesh Vernekar <ganesh.vernekar@reddit.com>
@codesome codesome force-pushed the codesome/stale-series-tracking branch from 42ce9d8 to 3904b3c Compare August 19, 2025 22:07
@codesome codesome changed the title Track stale series in the Head block based on stale sample tsdb: Track stale series in the Head block based on stale sample Aug 19, 2025
@codesome codesome enabled auto-merge August 19, 2025 22:13
@codesome codesome disabled auto-merge August 19, 2025 22:21
@codesome codesome merged commit a86d9a3 into main Aug 19, 2025
46 of 53 checks passed
@codesome codesome deleted the codesome/stale-series-tracking branch August 19, 2025 22:35
SuperQ added a commit that referenced this pull request Aug 26, 2025
Add changelog entry to pull in #16925 to v3.6.0.

Signed-off-by: SuperQ <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Aug 26, 2025
SuperQ added a commit that referenced this pull request Aug 26, 2025
Add changelog entry to pull in #16925 to v3.6.0.

Signed-off-by: SuperQ <superq@gmail.com>
machine424 added a commit that referenced this pull request Sep 9, 2025
codesome added a commit that referenced this pull request Jan 24, 2026
…ction

tsdb: Early compaction of stale series

Closes #13616

Based on prometheus/proposals#55

Stale series tracking was added in #16925. This PR compacts the stale series into its own block before the normal compaction hits. Here is how the settings:

stale_series_compaction_threshold: As soon as the ratio of stale series in the head block crosses StaleSeriesImmediateCompactionThreshold, TSDB performs a stale series compaction and puts all the stale series into a block and removed it from the head, but it does not remove it from the WAL. (technically this condition is checked every minute and not exactly immediate)
Additional details

WAL replay: after a stale series compaction, tombstones are added with (MinInt64, MaxInt64) for all these stale series. During WAL replay we add a special condition where when we find such tombstone, it immediately removes the series from the memory instead of storing the tombstone. This is required so that we don't spike up memory during WAL replay and also don't keep the compacted stale series in the memory.
Head block truncation ignores this block via the added metadata, similar to out-of-order blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants