From b895acc09de3b2bf611f18c54055c28b76ed42a5 Mon Sep 17 00:00:00 2001 From: Shannon Price Date: Thu, 13 Aug 2026 12:14:31 -0500 Subject: [PATCH] promql: add temporary debug logging to yrate start-timestamp codepath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Logs when start timestamps are found during yrate/yincrease evaluation and when they trigger counter reset detection. This is temporary logging for integration testing on red.prodref — to be removed after validation. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Shannon Price --- promql/yrate_funcs.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/promql/yrate_funcs.go b/promql/yrate_funcs.go index 3304ed73ce8..5bbc0e290d3 100644 --- a/promql/yrate_funcs.go +++ b/promql/yrate_funcs.go @@ -14,10 +14,15 @@ package promql import ( + "log/slog" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/util/annotations" ) +// TEMPORARY: debug logger for start-timestamp verification. Remove after integration testing. +var yrateSTLogger = slog.Default().With("component", "yrate-st-debug") + // yIncrease is a utility function for yincrease/yrate/ydelta. // It calculates the increase of the range (allowing for counter resets if isCounter is true), // taking into account the sample at the end of the previous range (just before rangeStartMsec). @@ -66,6 +71,17 @@ func yIncrease(points []FPoint, rangeStartMsec, rangeEndMsec int64, isCounter bo if isCounter && isYCounterReset(startTimestamps, prevST, currentST, points[i].T, rangeStartMsec, points[i].F, lastInRange) { // Counter reset: accumulate as if 0 had come before this sample. inRangeResetIncreases += lastInRange + // TEMPORARY: log counter reset detection details. + stTriggered := startTimestamps != nil && currentST != 0 && currentST != prevST + yrateSTLogger.Info("yrate counter reset detected", + "value_drop", points[i].F < lastInRange, + "st_triggered", stTriggered, + "prev_st", prevST, + "current_st", currentST, + "sample_t", points[i].T, + "sample_value", points[i].F, + "last_in_range", lastInRange, + ) if !foundInRangeSample { // This reset was *also* the first in-range sample. Since we just counted @@ -132,8 +148,14 @@ func funcYrate(_ []Vector, matrixVals Matrix, args parser.Expressions, enh *Eval func yStartTimestamps(points []FPoint, enh *EvalNodeHelper) []int64 { if enh.StartTimestamps != nil && len(enh.StartTimestamps.Floats) == len(points) { startTimestamps := enh.StartTimestamps.Floats - for _, startTimestamp := range startTimestamps { + for i, startTimestamp := range startTimestamps { if startTimestamp != 0 { + // TEMPORARY: log when start timestamps are found for yrate/yincrease evaluation. + yrateSTLogger.Info("start timestamps found for yrate evaluation", + "num_points", len(points), + "first_nonzero_st_index", i, + "first_nonzero_st_value", startTimestamp, + ) return startTimestamps } }