From c53aa4a2073e4ec57bf5ef89a907bb8d064d40fe Mon Sep 17 00:00:00 2001 From: Ridwan Sharif Date: Tue, 31 Mar 2026 13:53:49 +0000 Subject: [PATCH] chore: simplify explicit ST setting Signed-off-by: Ridwan Sharif --- docs/feature_flags.md | 8 ++++---- scrape/scrape_append_v2.go | 14 ++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/docs/feature_flags.md b/docs/feature_flags.md index c5648c000f..1357cdade2 100644 --- a/docs/feature_flags.md +++ b/docs/feature_flags.md @@ -111,10 +111,10 @@ Enables the use of start timestamps (ST) in PromQL functions such as `rate()`, ` `--enable-feature=st-synthesis` -Enables the synthesis of start timestamps (ST) for cumulative metrics (Counters, Classic Histograms, and Native Histograms) when they are not provided by the source. It tracks previous values to detect resets and subtracts the initial reference point to synthesize a zero-based timeline from the first sample. - -> NOTE: This is an experimental feature. Enabling this option can cause increased allocations and memory footprint because it requires caching the previous value per series. - +Enables the synthesis of start timestamps (ST) for cumulative metrics (Counters, Classic Histograms, and Native Histograms) +when they are not provided by the source. Similar to [the official OpenTelemetry metricstarttimeprocessor](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/metricstarttimeprocessor#strategy-subtract-initial-point), +it tracks previous values to detect resets and subtracts the initial reference point to synthesize a zero-based timeline +from the first sample. ## Concurrent evaluation of independent rules diff --git a/scrape/scrape_append_v2.go b/scrape/scrape_append_v2.go index 16e2452d2e..48622e4a17 100644 --- a/scrape/scrape_append_v2.go +++ b/scrape/scrape_append_v2.go @@ -150,7 +150,7 @@ loop: var ( et textparse.Entry shouldCache, isHistogram bool - st, explicitST int64 + st int64 met []byte parsedTimestamp *int64 val float64 @@ -256,12 +256,10 @@ loop: break loop } - explicitST = 0 if sl.parseST { // p.StartTimestamp() tend to be expensive (e.g. OM1). Do it only if we care. - explicitST = p.StartTimestamp() + st = p.StartTimestamp() } - st = explicitST if sl.synthesizeST && st == 0 { st, val, h, fh, skipAppend, stCache = sl.checkAndSynthesizeStartTime(st, lset, ce, lastMFName, val, h, fh, t) @@ -355,12 +353,8 @@ loop: } } - if ce != nil { - if sl.synthesizeST && explicitST != 0 { - ce.st = nil // Reset cache if explicit ST provided. - } else if stCache != nil { - ce.st = stCache - } + if ce != nil && sl.synthesizeST { + ce.st = stCache } // Track staleness uniformly, bypassing logic if there is an explicit timestamp.