From 460b7be5bce8a8d27230b785e6bc9af5def285a2 Mon Sep 17 00:00:00 2001 From: Ying WANG Date: Tue, 24 Dec 2024 14:45:04 +0100 Subject: [PATCH] tsdb: Add MustIndex() function to Head --- tsdb/head_read.go | 4 ++++ tsdb/head_read_test.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/tsdb/head_read.go b/tsdb/head_read.go index a3cd7b653d..9ec0595dbd 100644 --- a/tsdb/head_read.go +++ b/tsdb/head_read.go @@ -37,6 +37,10 @@ func (h *Head) Index() (IndexReader, error) { return h.indexRange(math.MinInt64, math.MaxInt64), nil } +func (h *Head) MustIndex() IndexReader { + return h.indexRange(math.MinInt64, math.MaxInt64) +} + func (h *Head) indexRange(mint, maxt int64) *headIndexReader { if hmin := h.MinTime(); hmin > mint { mint = hmin diff --git a/tsdb/head_read_test.go b/tsdb/head_read_test.go index eb8487fde0..e59a73caf6 100644 --- a/tsdb/head_read_test.go +++ b/tsdb/head_read_test.go @@ -428,6 +428,9 @@ func TestHeadIndexReader_PostingsForLabelMatching(t *testing.T) { ir, err := h.Index() require.NoError(t, err) + + irMust := h.MustIndex() + require.Equal(t, irMust, ir) return ir }) }