From 0eedc046f4a64b00be24112f4d3a0c7fced4fa82 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Mon, 14 Apr 2025 15:48:25 +0100 Subject: [PATCH] Check ref value when appending staleness markers Signed-off-by: Lukasz Mierzwa --- scrape/target.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scrape/target.go b/scrape/target.go index 30b47976a3..73fed40498 100644 --- a/scrape/target.go +++ b/scrape/target.go @@ -332,7 +332,9 @@ type limitAppender struct { } func (app *limitAppender) Append(ref storage.SeriesRef, lset labels.Labels, t int64, v float64) (storage.SeriesRef, error) { - if !value.IsStaleNaN(v) { + // Bypass sample_limit checks only if we have a staleness marker for a known series (ref value is non-zero). + // This ensures that if a series is already in TSDB then we always write the marker. + if ref == 0 || !value.IsStaleNaN(v) { app.i++ if app.i > app.limit { return 0, errSampleLimit