You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Blocks storage unable to ingest samples older than 1h after an outage #2366
TSDB doesn't allow to append samples whose timestamp is older than the last block cut from the head. Given a block is cut from the head up until -50% of the max timestamp within the head and given the default block range period is 2h, this means that the blocks storage doesn't allow to append a sample whose timestamp is older than 1h compared to the most recent timestamp in the head.
Let's consider this scenario:
Multiple Prometheus servers remote writing to the same Cortex tenant
Some Prometheus servers stop remote writing to Cortex (for any reason, ie. networking issue) and they fall behind more than 1h
When the Prometheus servers will be back online, Cortex will discard any sample whose timestamp is older than 1h because the max timestamp in the TSDB head is close to "now" (due to the working Prometheus servers which never stopped to write series) while the failing ones are trying to catch up writing samples older than 1h
We recently had an outage in our staging environment which triggered this condition and we should find a way to solve it.
@bwplotka You may be interested, given I think this issue affects Thanos receive too.
Reacted by Bartlomiej Plotka, Nathan Lowe, Charlie Ward, Chris Farmiloe, Asaf Mesika, Omer, jsha09, Toby Jackson, madmanua, Victor Gavro and 6 more
@codesome Given we have vertical compaction in TSDB and we can have overlapping blocks, what would be the implications to allow to write samples "out of bounds" in the TSDB head?
blocks storage doesn't allow to append a sample whose timestamp is older than 1h compared to the most recent timestamp in the head.
Really? Can we find code path in Prometheus which does it?
New block is cut from the head, when head (in-memory data) covers more than 1.5x of the block range. For 2 hours block range, it means that head needs to have 3h of data to cut a block. Block "start time" is always the minimum sample time in the head, while block "end time" is aligned on block range boundary. New block always covers single "block range" period. Data stored into a block is then removed from the Head. That means that after cutting the block, head will already have at least 1h of data, but possibly even more.
When writing new data via appender, minimum time limit is computed as Max(minT, maxT-0.5*block range), where minT and maxT are minimum/maximum sample times in the head. Limit is then enforced in Add and AddFast methods.
When head covers less than 0.5 of block range (<1h for 2h block range), samples cannot be older than min time in the head. When head covers more than 0.5 of block range (>1h for 2h block range), samples cannot be older than half block range since max time in the head.
It depends. How long time back is considered backfilling? From the Cortex (or Thanos receive) perspective, I think the issue we're describing here is not considered backfilling. At the current stage, we can't tolerate an outage longer than about 1h or we'll lose data.
Maybe it means that remote write is not good enough. You only have up to 2 hours to even still have that WAL around in this scenario, at which point it would be cut to a block. Maybe we need to discuss back-filling with blocks as a remote write extension. Just thinking out loud. (I think I briefly discussed this with @csmarchbanks once before)
I think the issue we're describing here is not considered backfilling. At the current stage, we can't tolerate an outage longer than about 1h or we'll lose data.
I think the issue we're describing here is not considered backfilling. At the current stage, we can't tolerate an outage longer than about 1h or we'll lose data.
Where is the boundary?
From the pure UX side, if it's about a Prometheus server catching up after an outage then I wouldn't consider it backfilling.
Actually user can change that, so we can make even 2 years WAL. If some one will not upload things for 2y and suddenly want to put 2y old sample, would that be still not backfill 🤔 ?
Any information about this? I would like to add some historical data into Cortex
The approach we took in #3025 should work but has some downsides:
The backfilling code path is exercised only during a backfilling, so bugs may slip in and we may not notice it until a backfilling event happens
The ingester memory utilisation could potentially grow 3x, risking to hit the ingester memory limit and causing an outage. If the backfilling covers the case of recovering after an outage, we may end up with an outage after another one
We're still evaluating pros/cons of #3025, while discussing alternative ideas.
hey guys, We had a similar issues , where when writing metrics to cortex for a new tenant after few minutes the ingester would start throwing out of bound error. The reason we found for this is we mistakenly did not disable alert and rules in our Prometheus and added the same rules and alerts for the tenant in cortex. Now if the alert gets evaluated by the cortex first and then it receives the sample form Prometheus which is also calculating the same rules, ingester would start throwing out of bound error , and this will happen for ever because Prometheus will keep on trying to send the same data and cortex would reject. So just to test this hypothesis we disabled rules and alerts on cortex and remote write is working fine. Should we add a note in the documentation stating not have same rules in Prometheus sand alert manager.
We run into this most likely due to the distributor gets overloaded... this means the middlewares(gateway/proxy) and unstable network may cause this issue.
Prometheus which is also calculating the same rules
@rajsameer that doesn't sound like the same thing.
Cortex will reject duplicate data with a 400 error, which means Prometheus will drop it.
For rules, Prometheus will re-evaluate the rule a short while later and send new data, which is also rejected as duplicate and dropped.
Happy to receive PRs about how to configure rules, but it's nothing to do with this issue.
If you have some specific details about your "out of bounds" error please open a new issue so those can be understood.
f.Var(&l.OutOfOrderTimeWindow, "ingester.out-of-order-time-window", "[Experimental] Configures the allowed time window for ingestion of out-of-order samples. Disabled (0s) by default.")
, experimental and disabled by default), ingesters accept samples older than the head's out-of-bounds limit as long as they fall within the window, which is what lagging Prometheus servers need after an outage. Closing as completed; happy to reopen if something is still missing.
Activity
pracucci commentedon Mar 31, 2020
@codesome Given we have vertical compaction in TSDB and we can have overlapping blocks, what would be the implications to allow to write samples "out of bounds" in the TSDB head?
pstibrany commentedon Mar 31, 2020
Noting other possible options (not necessarily good options):
change the cutting formula – I was trying to refer to 50% limit, but it's not related to cutting.bwplotka commentedon Mar 31, 2020
Really? Can we find code path in Prometheus which does it?
bwplotka commentedon Mar 31, 2020
Also, clock skew can cause it.
pstibrany commentedon Mar 31, 2020
New block is cut from the head, when head (in-memory data) covers more than 1.5x of the block range. For 2 hours block range, it means that head needs to have 3h of data to cut a block. Block "start time" is always the minimum sample time in the head, while block "end time" is aligned on block range boundary. New block always covers single "block range" period. Data stored into a block is then removed from the Head. That means that after cutting the block, head will already have at least 1h of data, but possibly even more.
When writing new data via appender, minimum time limit is computed as
Max(minT, maxT-0.5*block range), where minT and maxT are minimum/maximum sample times in the head. Limit is then enforced inAddandAddFastmethods.When head covers less than 0.5 of block range (<1h for 2h block range), samples cannot be older than min time in the head. When head covers more than 0.5 of block range (>1h for 2h block range), samples cannot be older than half block range since max time in the head.
bwplotka commentedon Mar 31, 2020
Thanks for the explanation. I think we are getting into the backfilling area.
I think opening a side block and use vertical compaction would solve it.
bwplotka commentedon Mar 31, 2020
We could start Prometheus discussion for it as well to enable that behavior if vertical compaction is enabled for TSDB itself.
pracucci commentedon Mar 31, 2020
It depends. How long time back is considered backfilling? From the Cortex (or Thanos receive) perspective, I think the issue we're describing here is not considered backfilling. At the current stage, we can't tolerate an outage longer than about 1h or we'll lose data.
brancz commentedon Mar 31, 2020
Maybe it means that remote write is not good enough. You only have up to 2 hours to even still have that WAL around in this scenario, at which point it would be cut to a block. Maybe we need to discuss back-filling with blocks as a remote write extension. Just thinking out loud. (I think I briefly discussed this with @csmarchbanks once before)
bwplotka commentedon Mar 31, 2020
Where is the boundary?
pracucci commentedon Mar 31, 2020
From the pure UX side, if it's about a Prometheus server catching up after an outage then I wouldn't consider it backfilling.
bwplotka commentedon Mar 31, 2020
I guess the boundary is then 1.5x block size (once we exceed WAL (3h))?
bwplotka commentedon Mar 31, 2020
Actually user can change that, so we can make even 2 years WAL. If some one will not upload things for 2y and suddenly want to put 2y old sample, would that be still not backfill 🤔 ?
brancz commentedon Mar 31, 2020
Sounds like concretely for this, we need a way to cut a head block safely that doesn't have the 1.5x time requirement/heuristic.
bwplotka commentedon Mar 31, 2020
What do you mean? When would you cut then? You don't know upfront what writes you expect to see but don't see, no?
33 remaining items
MedoDome commentedon Nov 20, 2020
Any information about this? I would like to add some historical data into Cortex
pracucci commentedon Nov 20, 2020
The approach we took in #3025 should work but has some downsides:
We're still evaluating pros/cons of #3025, while discussing alternative ideas.
MedoDome commentedon Nov 20, 2020
Thank you on the fast reply, I appreciate it
bboreham commentedon Mar 20, 2021
Any update after a few months?
rajsameer commentedon Apr 8, 2021
hey guys, We had a similar issues , where when writing metrics to cortex for a new tenant after few minutes the ingester would start throwing out of bound error. The reason we found for this is we mistakenly did not disable alert and rules in our Prometheus and added the same rules and alerts for the tenant in cortex. Now if the alert gets evaluated by the cortex first and then it receives the sample form Prometheus which is also calculating the same rules, ingester would start throwing out of bound error , and this will happen for ever because Prometheus will keep on trying to send the same data and cortex would reject. So just to test this hypothesis we disabled rules and alerts on cortex and remote write is working fine. Should we add a note in the documentation stating not have same rules in Prometheus sand alert manager.
damnever commentedon Apr 9, 2021
We run into this most likely due to the distributor gets overloaded... this means the middlewares(gateway/proxy) and unstable network may cause this issue.
bboreham commentedon Apr 9, 2021
@rajsameer that doesn't sound like the same thing.
Cortex will reject duplicate data with a 400 error, which means Prometheus will drop it.
For rules, Prometheus will re-evaluate the rule a short while later and send new data, which is also rejected as duplicate and dropped.
Happy to receive PRs about how to configure rules, but it's nothing to do with this issue.
If you have some specific details about your "out of bounds" error please open a new issue so those can be understood.
alexku7 commentedon Oct 9, 2021
Hello
Last week, we faced this issue.Cortex refused to accept metrics after some long outage with the error "out of bound".
We had to restart all the prometheus servers sending their data to Cortex. Only restart solved this problem .
Just wanted to ask to any update regarding this issue . Is there any fix or workaround ?
codesome commentedon Oct 11, 2021
prometheus/prometheus#8535 (comment) <- which will eventually get into Cortex
bwplotka commentedon Oct 28, 2021
Super simple idea: prometheus/prometheus#9607
Quick win, immidiate value.
kojderszymon commentedon Oct 6, 2022
Any update after changes in Prometheus - prometheus/prometheus#11075 ?
sandy2008 commentedon Oct 28, 2026
This is covered since 1.15.0: #4964 added out-of-order ingestion, and with the per-tenant
-ingester.out-of-order-time-windowlimit set (cortex/pkg/util/validation/limits.go
Line 318 in 5d93557