Skip to content

Blocks storage unable to ingest samples older than 1h after an outage #2366

Closed

Description

@pracucci

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.

Activity

  1. pracucci commented on Mar 31, 2020

    @pracucci
    ContributorAuthor

    @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?

  2. pstibrany commented on Mar 31, 2020

    @pstibrany
    Contributor

    Noting other possible options (not necessarily good options):

    • extend block range (would lead to higher ingester memory usage, and longer WAL replays)
    • change the cutting formula – I was trying to refer to 50% limit, but it's not related to cutting.
  3. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    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?

  4. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    Also, clock skew can cause it.

  5. pstibrany commented on Mar 31, 2020

    @pstibrany
    Contributor

    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.

  6. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    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.

  7. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    We could start Prometheus discussion for it as well to enable that behavior if vertical compaction is enabled for TSDB itself.

  8. pracucci commented on Mar 31, 2020

    @pracucci
    ContributorAuthor

    I think we are getting into the backfilling area.

    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.

  9. brancz commented on Mar 31, 2020

    @brancz
    Contributor

    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)

  10. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    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?

  11. pracucci commented on Mar 31, 2020

    @pracucci
    ContributorAuthor

    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.

  12. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    I guess the boundary is then 1.5x block size (once we exceed WAL (3h))?

  13. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    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 🤔 ?

  14. brancz commented on Mar 31, 2020

    @brancz
    Contributor

    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.

  15. bwplotka commented on Mar 31, 2020

    @bwplotka
    Contributor

    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.

    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?

  16. 33 remaining items

  17. removed
    keepalive
    on Sep 28, 2020
  18. MedoDome commented on Nov 20, 2020

    @MedoDome

    Any information about this? I would like to add some historical data into Cortex

  19. pracucci commented on Nov 20, 2020

    @pracucci
    ContributorAuthor

    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:

    1. 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
    2. 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.

  20. MedoDome commented on Nov 20, 2020

    @MedoDome

    Thank you on the fast reply, I appreciate it

  21. added
    keepalive
    on Feb 4, 2021
  22. bboreham commented on Mar 20, 2021

    @bboreham
    Contributor

    Any update after a few months?

  23. rajsameer commented on Apr 8, 2021

    @rajsameer

    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.

  24. damnever commented on Apr 9, 2021

    @damnever
    Contributor

    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.

  25. bboreham commented on Apr 9, 2021

    @bboreham
    Contributor

    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.

  26. alexku7 commented on Oct 9, 2021

    @alexku7
    Contributor

    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 ?

  27. codesome commented on Oct 11, 2021

    @codesome
    Contributor

    prometheus/prometheus#8535 (comment) <- which will eventually get into Cortex

  28. bwplotka commented on Oct 28, 2021

    @bwplotka
    Contributor

    Super simple idea: prometheus/prometheus#9607

    Quick win, immidiate value.

  29. kojderszymon commented on Oct 6, 2022

    @kojderszymon

    Any update after changes in Prometheus - prometheus/prometheus#11075 ?

  30. sandy2008 commented on Oct 28, 2026

    @sandy2008
    Contributor

    This is covered since 1.15.0: #4964 added out-of-order ingestion, and with the per-tenant -ingester.out-of-order-time-window limit set (

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepalivestorage/blocks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions