From edd05d70107c92e91bfb87eab2167d7105a8ede1 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Wed, 3 Nov 2021 08:39:54 +0100 Subject: [PATCH] Add Head.AppendableMinValidTime() (#9643) Signed-off-by: Marco Pracucci --- tsdb/head_append.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tsdb/head_append.go b/tsdb/head_append.go index bd2888930..e586999f9 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -141,6 +141,16 @@ func (h *Head) appendableMinValidTime() int64 { return max(h.minValidTime.Load(), h.MaxTime()-h.chunkRange.Load()/2) } +// AppendableMinValidTime returns the minimum valid time for samples to be appended to the Head. +// Returns false if Head hasn't been initialized yet and the minimum time isn't known yet. +func (h *Head) AppendableMinValidTime() (int64, bool) { + if h.MinTime() == math.MaxInt64 { + return 0, false + } + + return h.appendableMinValidTime(), true +} + func max(a, b int64) int64 { if a > b { return a