From 2dcaa1511c6b6e5f96d0977381827ced5064dc92 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Wed, 4 Sep 2024 13:38:05 +0200 Subject: [PATCH] API: expose lowest TSDB timestamp in /api/v1/status/tsdb Add information about the lowest timestamp in the TSDB to /api/v1/status/tsdb. This feature would be useful to have in Thanos so that the Thanos Sidecar can adjust its advertised range so we can more precisely prune endpoints during fan-out. Signed-off-by: Michael Hoffmann --- web/api/v1/api.go | 17 ++++++++-- .../src/pages/tsdbStatus/TSDBStatus.test.tsx | 9 +++++ .../src/pages/tsdbStatus/TSDBStatus.tsx | 33 ++++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index d58be211f..eb98fb6c7 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -1577,9 +1577,15 @@ type HeadStats struct { MaxTime int64 `json:"maxTime"` } +// TSDBStats has information about the TSDB. +type TSDBStats struct { + MinTime int64 `json:"minTime"` +} + // TSDBStatus has information of cardinality statistics from postings. type TSDBStatus struct { HeadStats HeadStats `json:"headStats"` + TSDBStats TSDBStats `json:"tsdbStats"` SeriesCountByMetricName []TSDBStat `json:"seriesCountByMetricName"` LabelValueCountByLabelName []TSDBStat `json:"labelValueCountByLabelName"` MemoryInBytesByLabelName []TSDBStat `json:"memoryInBytesByLabelName"` @@ -1613,12 +1619,18 @@ func (api *API) serveTSDBStatus(r *http.Request) apiFuncResult { return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("error gathering runtime status: %w", err)}, nil, nil} } chunkCount := int64(math.NaN()) + lowestTimestamp := int64(math.NaN()) for _, mF := range metrics { - if *mF.Name == "prometheus_tsdb_head_chunks" { + switch *mF.Name { + case "prometheus_tsdb_head_chunks": m := mF.Metric[0] if m.Gauge != nil { chunkCount = int64(m.Gauge.GetValue()) - break + } + case "prometheus_tsdb_lowest_timestamp": + m := mF.Metric[0] + if m.Gauge != nil { + lowestTimestamp = int64(m.Gauge.GetValue()) } } } @@ -1630,6 +1642,7 @@ func (api *API) serveTSDBStatus(r *http.Request) apiFuncResult { MaxTime: s.MaxTime, NumLabelPairs: s.IndexPostingStats.NumLabelPairs, }, + TSDBStats: TSDBStats{MinTime: lowestTimestamp}, SeriesCountByMetricName: TSDBStatsFromIndexStats(s.IndexPostingStats.CardinalityMetricsStats), LabelValueCountByLabelName: TSDBStatsFromIndexStats(s.IndexPostingStats.CardinalityLabelStats), MemoryInBytesByLabelName: TSDBStatsFromIndexStats(s.IndexPostingStats.LabelValueStats), diff --git a/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx b/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx index b7c683115..7cdea61e5 100644 --- a/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx +++ b/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx @@ -20,6 +20,9 @@ const fakeTSDBStatusResponse: { minTime: 1591516800000, maxTime: 1598896800143, }, + tsdbStats: { + minTime: 1591516800000, + }, labelValueCountByLabelName: [ { name: '__name__', @@ -64,6 +67,9 @@ const fakeEmptyTSDBStatusResponse: { minTime: 9223372036854776000, maxTime: -9223372036854776000, }, + tsdbStats: { + minTime: 9223372036854776000, + }, labelValueCountByLabelName: [], seriesCountByMetricName: [], memoryInBytesByLabelName: [], @@ -84,6 +90,9 @@ const fakeInvalidTimestampTSDBStatusResponse: { minTime: 9223372036854776000, maxTime: -9223372036854776000, }, + tsdbStats: { + minTime: 9223372036854776000, + }, labelValueCountByLabelName: [], seriesCountByMetricName: [], memoryInBytesByLabelName: [], diff --git a/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.tsx b/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.tsx index bc4dfe99b..3e9069b55 100644 --- a/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.tsx +++ b/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.tsx @@ -19,8 +19,13 @@ interface HeadStats { maxTime: number; } +interface TSDBStats { + minTime: number; +} + export interface TSDBMap { headStats: HeadStats; + tsdbStats: TSDBStats; seriesCountByMetricName: Stats[]; labelValueCountByLabelName: Stats[]; memoryInBytesByLabelName: Stats[]; @@ -45,29 +50,49 @@ export const TSDBStatusContent: FC = ({ } }; const { chunkCount, numSeries, numLabelPairs, minTime, maxTime } = headStats; - const stats = [ + const headStatsKV = [ { header: 'Number of Series', value: numSeries }, { header: 'Number of Chunks', value: chunkCount }, { header: 'Number of Label Pairs', value: numLabelPairs }, { header: 'Current Min Time', value: `${unixToTime(minTime)}` }, { header: 'Current Max Time', value: `${unixToTime(maxTime)}` }, ]; + const tsdbStatsKV = [{ header: 'Current Min Time', value: `${unixToTime(minTime)}` }]; return (

TSDB Status

-

Head Stats

+

TSDB Stats

- {stats.map(({ header }) => { + {tsdbStatsKV.map(({ header }) => { return ; })} - {stats.map(({ header, value }) => { + {tsdbStatsKV.map(({ header, value }) => { + return ; + })} + + +
{header}
{value}
+
+

Head Stats

+
+ + + + {headStatsKV.map(({ header }) => { + return ; + })} + + + + + {headStatsKV.map(({ header, value }) => { return ; })}
{header}
{value}