mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: do not pass (accountID, projectID) to SearchTagNames(), since they are already passed via tfss
This commit is contained in:
parent
911c6d3bcd
commit
a9287cf564
2 changed files with 53 additions and 2 deletions
|
@ -860,7 +860,7 @@ func nextRetentionDuration(retentionMonths int) time.Duration {
|
|||
}
|
||||
|
||||
// SearchMetricNames returns metric names matching the given tfss on the given tr.
|
||||
func (s *Storage) SearchMetricNames(accountID, projectID uint32, tfss []*TagFilters, tr TimeRange, maxMetrics int, deadline uint64) ([]MetricName, error) {
|
||||
func (s *Storage) SearchMetricNames(tfss []*TagFilters, tr TimeRange, maxMetrics int, deadline uint64) ([]MetricName, error) {
|
||||
tsids, err := s.searchTSIDs(tfss, tr, maxMetrics, deadline)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -871,6 +871,8 @@ func (s *Storage) SearchMetricNames(accountID, projectID uint32, tfss []*TagFilt
|
|||
if err = s.prefetchMetricNames(tsids, deadline); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
accountID := tsids[0].AccountID
|
||||
projectID := tsids[0].ProjectID
|
||||
idb := s.idb()
|
||||
is := idb.getIndexSearch(accountID, projectID, deadline)
|
||||
defer idb.putIndexSearch(is)
|
||||
|
|
|
@ -807,6 +807,15 @@ func testStorageRegisterMetricNames(s *Storage) error {
|
|||
return fmt.Errorf("unexpected tag keys returned from SearchTagKeys;\ngot\n%q\nwant\n%q", tks, tksExpected)
|
||||
}
|
||||
|
||||
// Verify that SearchTagKeys returns empty results for incorrect accountID, projectID
|
||||
tks, err = s.SearchTagKeys(accountID+1, projectID+1, 100, noDeadline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in SearchTagKeys for incorrect accountID, projectID: %w", err)
|
||||
}
|
||||
if len(tks) > 0 {
|
||||
return fmt.Errorf("SearchTagKeys with incorrect accountID, projectID returns unexpected non-empty result:\n%q", tks)
|
||||
}
|
||||
|
||||
// Verify that SearchTagKeysOnTimeRange returns correct result.
|
||||
now := timestampFromTime(time.Now())
|
||||
start := now - msecPerDay
|
||||
|
@ -824,6 +833,15 @@ func testStorageRegisterMetricNames(s *Storage) error {
|
|||
return fmt.Errorf("unexpected tag keys returned from SearchTagKeysOnTimeRange;\ngot\n%q\nwant\n%q", tks, tksExpected)
|
||||
}
|
||||
|
||||
// Verify that SearchTagKeysOnTimeRange returns empty results for incrorrect accountID, projectID
|
||||
tks, err = s.SearchTagKeysOnTimeRange(accountID+1, projectID+1, tr, 100, noDeadline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in SearchTagKeysOnTimeRange for incorrect accountID, projectID: %w", err)
|
||||
}
|
||||
if len(tks) > 0 {
|
||||
return fmt.Errorf("SearchTagKeysOnTimeRange with incorrect accountID, projectID returns unexpected non-empty result:\n%q", tks)
|
||||
}
|
||||
|
||||
// Verify that SearchTagValues returns correct result.
|
||||
addIDs, err := s.SearchTagValues(accountID, projectID, []byte("add_id"), addsCount+100, noDeadline)
|
||||
if err != nil {
|
||||
|
@ -834,6 +852,15 @@ func testStorageRegisterMetricNames(s *Storage) error {
|
|||
return fmt.Errorf("unexpected tag values returned from SearchTagValues;\ngot\n%q\nwant\n%q", addIDs, addIDsExpected)
|
||||
}
|
||||
|
||||
// Verify that SearchTagValues return empty results for incorrect accountID, projectID
|
||||
addIDs, err = s.SearchTagValues(accountID+1, projectID+1, []byte("add_id"), addsCount+100, noDeadline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in SearchTagValues for incorrect accountID, projectID: %w", err)
|
||||
}
|
||||
if len(addIDs) > 0 {
|
||||
return fmt.Errorf("SearchTagValues with incorrect accountID, projectID returns unexpected non-empty result:\n%q", addIDs)
|
||||
}
|
||||
|
||||
// Verify that SearchTagValuesOnTimeRange returns correct result.
|
||||
addIDs, err = s.SearchTagValuesOnTimeRange(accountID, projectID, []byte("add_id"), tr, addsCount+100, noDeadline)
|
||||
if err != nil {
|
||||
|
@ -844,12 +871,21 @@ func testStorageRegisterMetricNames(s *Storage) error {
|
|||
return fmt.Errorf("unexpected tag values returned from SearchTagValuesOnTimeRange;\ngot\n%q\nwant\n%q", addIDs, addIDsExpected)
|
||||
}
|
||||
|
||||
// Verify that SearchTagValuesOnTimeRange returns empty results for incorrect accountID, projectID
|
||||
addIDs, err = s.SearchTagValuesOnTimeRange(accountID+1, projectID+1, []byte("addd_id"), tr, addsCount+100, noDeadline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in SearchTagValuesOnTimeRange for incorrect accoundID, projectID: %w", err)
|
||||
}
|
||||
if len(addIDs) > 0 {
|
||||
return fmt.Errorf("SearchTagValuesOnTimeRange with incorrect accountID, projectID returns unexpected non-empty result:\n%q", addIDs)
|
||||
}
|
||||
|
||||
// Verify that SearchMetricNames returns correct result.
|
||||
tfs := NewTagFilters(accountID, projectID)
|
||||
if err := tfs.Add([]byte("add_id"), []byte("0"), false, false); err != nil {
|
||||
return fmt.Errorf("unexpected error in TagFilters.Add: %w", err)
|
||||
}
|
||||
mns, err := s.SearchMetricNames(accountID, projectID, []*TagFilters{tfs}, tr, metricsPerAdd*addsCount*100+100, noDeadline)
|
||||
mns, err := s.SearchMetricNames([]*TagFilters{tfs}, tr, metricsPerAdd*addsCount*100+100, noDeadline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in SearchMetricNames: %w", err)
|
||||
}
|
||||
|
@ -867,6 +903,19 @@ func testStorageRegisterMetricNames(s *Storage) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Verify that SearchMetricNames returns empty results for incorrect accountID, projectID
|
||||
tfs = NewTagFilters(accountID+1, projectID+1)
|
||||
if err := tfs.Add([]byte("add_id"), []byte("0"), false, false); err != nil {
|
||||
return fmt.Errorf("unexpected error in TagFilters.Add: %w", err)
|
||||
}
|
||||
mns, err = s.SearchMetricNames([]*TagFilters{tfs}, tr, metricsPerAdd*addsCount*100+100, noDeadline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in SearchMetricNames for incorrect accountID, projectID: %w", err)
|
||||
}
|
||||
if len(mns) > 0 {
|
||||
return fmt.Errorf("SearchMetricNames with incorrect accountID, projectID returns unexpected non-empty result:\n%+v", mns)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue