From d7be2753c0627757a02b5db9af3b49eb1eb62d6e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 13 May 2021 08:56:02 +0300 Subject: [PATCH] lib/storage: substitute GetTSDBStatusForDate with GetTSDBStatusWithFiltersForDate with nil tfss --- app/vmstorage/main.go | 2 +- lib/storage/index_db.go | 25 ------------------------- lib/storage/index_db_test.go | 6 +++--- lib/storage/storage.go | 7 ------- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/app/vmstorage/main.go b/app/vmstorage/main.go index 7b052a2067..d31576bd5b 100644 --- a/app/vmstorage/main.go +++ b/app/vmstorage/main.go @@ -208,7 +208,7 @@ func SearchTagEntries(maxTagKeys, maxTagValues int, deadline uint64) ([]storage. // GetTSDBStatusForDate returns TSDB status for the given date. func GetTSDBStatusForDate(date uint64, topN int, deadline uint64) (*storage.TSDBStatus, error) { WG.Add(1) - status, err := Storage.GetTSDBStatusForDate(date, topN, deadline) + status, err := Storage.GetTSDBStatusWithFiltersForDate(nil, date, topN, deadline) WG.Done() return status, err } diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 5b013e86d1..23f9eb5a66 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -1451,31 +1451,6 @@ func (is *indexSearch) getTSDBStatusWithFiltersForDate(tfss []*TagFilters, date return status, nil } -// GetTSDBStatusForDate returns topN entries for tsdb status for the given date. -func (db *indexDB) GetTSDBStatusForDate(date uint64, topN int, deadline uint64) (*TSDBStatus, error) { - is := db.getIndexSearch(deadline) - status, err := is.getTSDBStatusWithFiltersForDate(nil, date, topN) - db.putIndexSearch(is) - if err != nil { - return nil, err - } - if status.hasEntries() { - // The entries were found in the db. There is no need in searching them in extDB. - return status, nil - } - - // The entries weren't found in the db. Try searching them in extDB. - ok := db.doExtDB(func(extDB *indexDB) { - is := extDB.getIndexSearch(deadline) - status, err = is.getTSDBStatusWithFiltersForDate(nil, date, topN) - extDB.putIndexSearch(is) - }) - if ok && err != nil { - return nil, fmt.Errorf("error when obtaining TSDB status from extDB: %w", err) - } - return status, nil -} - // TSDBStatus contains TSDB status data for /api/v1/status/tsdb. // // See https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-stats diff --git a/lib/storage/index_db_test.go b/lib/storage/index_db_test.go index a9bbbe847f..d2b95952ce 100644 --- a/lib/storage/index_db_test.go +++ b/lib/storage/index_db_test.go @@ -1628,10 +1628,10 @@ func TestSearchTSIDWithTimeRange(t *testing.T) { t.Fatalf("expected %d time series for all days, got %d time series", metricsPerDay*days, len(matchedTSIDs)) } - // Check GetTSDBStatusForDate - status, err := db.GetTSDBStatusForDate(baseDate, 5, noDeadline) + // Check GetTSDBStatusWithFiltersForDate with nil filters. + status, err := db.GetTSDBStatusWithFiltersForDate(nil, baseDate, 5, noDeadline) if err != nil { - t.Fatalf("error in GetTSDBStatusForDate: %s", err) + t.Fatalf("error in GetTSDBStatusWithFiltersForDate with nil filters: %s", err) } if !status.hasEntries() { t.Fatalf("expecting non-empty TSDB status") diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 772204ca4c..16530537e4 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1241,13 +1241,6 @@ func (s *Storage) GetSeriesCount(deadline uint64) (uint64, error) { return s.idb().GetSeriesCount(deadline) } -// GetTSDBStatusForDate returns TSDB status data for /api/v1/status/tsdb. -// -// See https://prometheus.io/docs/prometheus/latest/querying/api/#tsdb-stats -func (s *Storage) GetTSDBStatusForDate(date uint64, topN int, deadline uint64) (*TSDBStatus, error) { - return s.idb().GetTSDBStatusForDate(date, topN, deadline) -} - // GetTSDBStatusWithFiltersForDate returns TSDB status data for /api/v1/status/tsdb with match[] filters. func (s *Storage) GetTSDBStatusWithFiltersForDate(tfss []*TagFilters, date uint64, topN int, deadline uint64) (*TSDBStatus, error) { return s.idb().GetTSDBStatusWithFiltersForDate(tfss, date, topN, deadline)