Skip to content

Add --storage.tsdb.retention.percentage (#10287)#12278

Closed
fatpat wants to merge 1 commit into
prometheus:mainfrom
fatpat:retention_size_percentage
Closed

Add --storage.tsdb.retention.percentage (#10287)#12278
fatpat wants to merge 1 commit into
prometheus:mainfrom
fatpat:retention_size_percentage

Conversation

@fatpat

@fatpat fatpat commented Apr 20, 2023

Copy link
Copy Markdown
Contributor

As discussed in #10287, this PR add the --storage.tsdb.retention.percentage.

It takes an uint between 0 (disabled) and 100.
if set, each time BeyondSizeRetention is called, storage.tsdb.rentention.size is temporary overwritten with the percentage of the current size of the partition on which the DB directory is stored.

@fatpat
fatpat requested a review from codesome as a code owner April 20, 2023 15:39
Comment thread util/runtime/statfs_uint32.go Outdated
@roidelapluie

Copy link
Copy Markdown
Member

Can we make it work for windows too to keep feature parity?

@fatpat
fatpat force-pushed the retention_size_percentage branch from a7e9f3a to 8912e88 Compare April 20, 2023 19:04
@fatpat

fatpat commented Apr 20, 2023

Copy link
Copy Markdown
Contributor Author

Can we make it work for windows too to keep feature parity?

yes it should be OK.

would it be possible to add a dependency to github.com/minio/minio/internal/disk as it seems complete and well maintained ?

or just continue to handle disk information directly from prometheus sources ?

@fatpat
fatpat force-pushed the retention_size_percentage branch 2 times, most recently from d794957 to 3b199aa Compare April 21, 2023 04:34
@fatpat

fatpat commented Apr 21, 2023

Copy link
Copy Markdown
Contributor Author

Can we make it work for windows too to keep feature parity?

yes it should be OK.

would it be possible to add a dependency to github.com/minio/minio/internal/disk as it seems complete and well maintained ?

or just continue to handle disk information directly from prometheus sources ?

forget it, I did not realized it was internal and cannot be used from prometheus.

@fatpat
fatpat force-pushed the retention_size_percentage branch 2 times, most recently from fa11739 to a148c5a Compare April 21, 2023 07:13
@roidelapluie

Copy link
Copy Markdown
Member

Did you copy code over from minio?

@fatpat
fatpat force-pushed the retention_size_percentage branch 2 times, most recently from cadc74c to cf74ceb Compare April 21, 2023 09:20
@fatpat

fatpat commented Apr 21, 2023

Copy link
Copy Markdown
Contributor Author

Did you copy code over from minio?

only the strict necessary, but yes it's a piece of code that is inspired by minio code

@roidelapluie

Copy link
Copy Markdown
Member

Minio is released under AGPL-3.0. We might get into troubled waters. Or you could check if the code was present in the Apache-2 releases of minio. We probably want attribution in the headers of the files as well.

@fatpat
fatpat force-pushed the retention_size_percentage branch 3 times, most recently from 5df8a81 to 3378275 Compare April 21, 2023 11:40
@fatpat

fatpat commented Apr 21, 2023

Copy link
Copy Markdown
Contributor Author

Minio is released under AGPL-3.0. We might get into troubled waters. Or you could check if the code was present in the Apache-2 releases of minio. We probably want attribution in the headers of the files as well.

No need I guess. Even if it looks like the same it's just a call to a windows syscall. cf doc from microsoft in the comment

@fatpat
fatpat force-pushed the retention_size_percentage branch from 3378275 to d019d63 Compare April 21, 2023 19:25
@fatpat

fatpat commented Apr 22, 2023

Copy link
Copy Markdown
Contributor Author

I still need to test it on windows

@fatpat

fatpat commented Apr 22, 2023

Copy link
Copy Markdown
Contributor Author

I'm still not fully happy with the solution that I provide.

We clean up old blocks if the prom storage uses more that X% of the partition capacity. But If some other things are filling up the disk, it won't prevent the partition to get full and in this case prom is not working correctly.

I'm thinking about adding the possibility to remove blocks if free disk usage raises over a limit.

Let's say I want to remove old blocks if disk actual usage is over 90% no matter the size of the blocks. I just want to ensure prom will have spare space to write new data even if it means to delete old blocks, continuity of service first.

what do you think ?

@roidelapluie

Copy link
Copy Markdown
Member

I think we should indeed take into consideration the size of the disk and not the size of the blocks, then remove enough blocks to get back below the threshold

@roidelapluie

Copy link
Copy Markdown
Member

We have discussed this during the Prometheus bug scrub. We decided that we should only look at the ration between disk space used by Prometheus vs the disk size.

I will review this PR this week.

@roidelapluie roidelapluie self-assigned this Jun 27, 2023
Comment thread cmd/prometheus/main.go
@frittentheke

frittentheke commented Jul 10, 2023

Copy link
Copy Markdown

I like the simplicity of having a percentage value instead of some calculated number of GiB as a retention.
But if I may bluntly point at my issue about the lack of an "set it and forget it" approach (#11112) with the compaction and retention / expiry mechanism.

To me the most helpful feature would be to be able to just point Prometheus at a storage volume and tell it to use all of this this space and to do housekeeping / automagic expiry to never run out of space. Be there changes in rate or number of time series or whatever - Prometheus simply ensures the disk will not fill up 100%.

So take my comment back to this PR: Can I simply set 99% and be done with it?

@roidelapluie

Copy link
Copy Markdown
Member

I still plan to review this and we agreed again during the bug scrub that we should only take care about the scenario where Prometheus has its own volume/partition.

There might be concerns with the size of the WAL and the size of the snapshots, but it is the same issue with the retention bytes. This PR should basically only set the retention bytes to the % of disk space.

@bboreham

Copy link
Copy Markdown
Member

Hello from the bug-scrub! @roidelapluie do you think you will get back to this?

@frittentheke

Copy link
Copy Markdown

There might be concerns with the size of the WAL and the size of the snapshots, but it is the same issue with the retention bytes. This PR should basically only set the retention bytes to the % of disk space.

YES @roidelapluie, please see my comment / issue #11112 about this

Comment thread cmd/prometheus/main.go
serverOnlyFlag(a, "storage.tsdb.retention.size", "Maximum number of bytes that can be stored for blocks. A unit is required, supported units: B, KB, MB, GB, TB, PB, EB. Ex: \"512MB\". Based on powers-of-2, so 1KB is 1024B.").
BytesVar(&cfg.tsdb.MaxBytes)

serverOnlyFlag(a, "storage.tsdb.retention.percentage", "Maximum percentage of the disk space that can be used to store blocks (prevails over storage.tsdb.retention.size).").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On first reading I interpreted "disk space" to mean "free space"; after looking more deeply I realize you implemented as a percentage of the total disk (partition) size.
Also "can be used to store blocks" might suggest that the head (WAL, chunks, etc.) is not included, whereas I believe it is.

Suggest to make this clearer; maybe add some commentary in the docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the message, no problem. What would you suggest ?

@bboreham

Copy link
Copy Markdown
Member

Hello again from the bug-scrub! We discussed in detail and this seems reasonable; there are a few merge conflicts to resolve.

@fatpat
fatpat force-pushed the retention_size_percentage branch from d019d63 to 88d4be9 Compare October 29, 2024 08:24
@fatpat
fatpat requested a review from jesusvazquez as a code owner October 29, 2024 08:24
@fatpat

fatpat commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

Hello again from the bug-scrub! We discussed in detail and this seems reasonable; there are a few merge conflicts to resolve.

done

@fatpat
fatpat force-pushed the retention_size_percentage branch 2 times, most recently from 66b3ba1 to bf98acf Compare October 29, 2024 10:32
Comment thread cmd/prometheus/main.go
serverOnlyFlag(a, "storage.tsdb.retention.size", "Maximum number of bytes that can be stored for blocks. A unit is required, supported units: B, KB, MB, GB, TB, PB, EB. Ex: \"512MB\". Based on powers-of-2, so 1KB is 1024B.").
BytesVar(&cfg.tsdb.MaxBytes)

serverOnlyFlag(a, "storage.tsdb.retention.percentage", "Maximum percentage of the disk space that can be used to store blocks (prevails over storage.tsdb.retention.size).").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serverOnlyFlag(a, "storage.tsdb.retention.percentage", "Maximum percentage of the disk space that can be used to store blocks (prevails over storage.tsdb.retention.size).").
serverOnlyFlag(a, "storage.tsdb.retention.percentage", "Maximum percentage of disk used for TSDB storage (overrides storage.tsdb.retention.size).").

Then the more detailed commentary can go in docs/storage.md

@frittentheke

Copy link
Copy Markdown

With this PR seemingly moving I'd like to again (#12278 (comment)) mention the usability issue with setting e.g. "95%" and still running out of disk space due to #11112.

It would simply be AWESOME to have Prometheus be able to utilize all of the available space (e.g. running with this new flag set to 95% or even 99%) and not run out of space due to compaction.

So what are "safe" values for all those --storage.tsdb.retention.* settings that don't require complex calculations and constant adjustments (block size, compaction intervals, number of time series, churn, ...)

@bboreham

Copy link
Copy Markdown
Member

Hello from the bug-scrub!

Seems we are nearly there; there is one review comment and one small merge conflict.

@fatpat if you're able to do this, please let us know, otherwise one of the maintainers can pick it up and clean up those things.

@fatpat
fatpat force-pushed the retention_size_percentage branch from bf98acf to a29537a Compare August 27, 2025 03:18
@fatpat

fatpat commented Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

Hello from the bug-scrub!

Seems we are nearly there; there is one review comment and one small merge conflict.

@fatpat if you're able to do this, please let us know, otherwise one of the maintainers can pick it up and clean up those things.

Hi,

rebase's done.

Unfortunately I have no spare time to work on this soon. Feel free to take over, I'd love to see this PR merged. And if possible to take compaction into account would be a game changer for us too.

@ldufr

ldufr commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

After talking with @krajorama, I'll try to bring this to an end, but can't directly edit this PR (I'm not a maintainer), so following up in #18080.

@frittentheke

Copy link
Copy Markdown

Unfortunately I have no spare time to work on this soon. Feel free to take over, I'd love to see this PR merged. And if possible to take compaction into account would be a game changer for us too.

@ldufr will you be tackling the issue with compaction not taking into account when calculating storage percentage then?

@ldufr

ldufr commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

@frittentheke I wasn't going to tackle the issue together and I think it makes more sense here to do it separately.

@roidelapluie

Copy link
Copy Markdown
Member

@frittentheke I wasn't going to tackle the issue together and I think it makes more sense here to do it separately.

Yes 2 different issues especially since that compation issue affects all the TSDB retention mechanisms (and is not as easy as it looks)

@frittentheke

Copy link
Copy Markdown

@frittentheke I wasn't going to tackle the issue together and I think it makes more sense here to do it separately.

Yes 2 different issues especially since that compation issue affects all the TSDB retention mechanisms (and is not as easy as it looks)

@roidelapluie after all there is my issue #11112 which is to track that one anyways.

@roidelapluie

Copy link
Copy Markdown
Member

Thanks for the work put on this, #18080 has been merged, so I am closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants