From dd72f6cd6a9242297789a1b964fb0baa6e5df965 Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Fri, 3 Jan 2025 17:19:47 +0100 Subject: [PATCH] Fix logs, log min/maxt Signed-off-by: Oleg Zaytsev --- tsdb/head_read.go | 5 ++++- tsdb/querier.go | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tsdb/head_read.go b/tsdb/head_read.go index f85120a97..b94b44ad9 100644 --- a/tsdb/head_read.go +++ b/tsdb/head_read.go @@ -76,7 +76,10 @@ func (h *headIndexReader) SortedLabelValues(ctx context.Context, name string, ma // If matchers are specified the returned result set is reduced // to label values of metrics matching the matchers. func (h *headIndexReader) LabelValues(ctx context.Context, name string, matchers ...*labels.Matcher) ([]string, error) { - if h.maxt < h.head.MinTime() || h.mint > h.head.MaxTime() { + headMinTime := h.head.MinTime() + headMaxTime := h.head.MaxTime() + if h.maxt < headMinTime || h.mint > headMaxTime { + fmt.Println("Returning empty label values for ", name, "because out of range:", "h.maxt=", h.maxt, "<", headMinTime, "=headMinTime || h.mint=", h.mint, " > ", headMaxTime, "=headMaxTime") return []string{}, nil } diff --git a/tsdb/querier.go b/tsdb/querier.go index fa52c036c..4118ce2b4 100644 --- a/tsdb/querier.go +++ b/tsdb/querier.go @@ -214,13 +214,17 @@ func PostingsForMatchers(ctx context.Context, ix IndexPostingsReader, ms ...*lab } return fmt.Sprintf("%T", p) } + if hr, ok := ix.(*headIndexReader); ok { + debug("h.maxt=%d, h.mint=%d", hr.maxt, hr.mint) + debug("h.head.MaxTime=%d, h.head.MinTime=%d", hr.head.MaxTime(), hr.head.MinTime()) + } var its, notIts []index.Postings if troubleshoot { defer func() { selector := (&parser.VectorSelector{LabelMatchers: ms}).String() traceID := trace.SpanFromContext(ctx).SpanContext().TraceID().String() - fmt.Printf("PostingsForMatchers(ix=%T, ms=%s, traceID=%s): %s", ix, selector, traceID, strings.Join(troubleshootData, ", ")) + fmt.Printf("PostingsForMatchers(ix=%T, ms=%s, traceID=%s): %s\n", ix, selector, traceID, strings.Join(troubleshootData, ", ")) }() } // See which label must be non-empty.