Skip to content

Commit 457ec09

Browse files
authored
chore(dataobj-index): Handle special cases in the section lookup of the metastore (#19203)
There are three edge cases that this PR improves: * No table (toc) paths could be resolved: return early with empty result * No index paths could be resolved: return early with empty result * No relevant sections could be resolved: return with empty result instead of with an error Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
1 parent 64bbfe0 commit 457ec09

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

pkg/dataobj/metastore/object.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ func (m *ObjectMetastore) Sections(ctx context.Context, start, end time.Time, ma
217217
tablePaths = append(tablePaths, path)
218218
}
219219

220+
// Return early if no toc files are found
221+
if len(tablePaths) == 0 {
222+
m.metrics.indexObjectsTotal.Observe(0)
223+
m.metrics.resolvedSectionsTotal.Observe(0)
224+
duration := sectionsTimer.ObserveDuration()
225+
level.Debug(utillog.WithContext(ctx, m.logger)).Log("msg", "resolved sections", "duration", duration, "sections", 0)
226+
return nil, nil
227+
}
228+
220229
// List index objects from all tables concurrently
221230
indexPaths, err := m.listObjectsFromTables(ctx, tablePaths, start, end)
222231
if err != nil {
@@ -226,6 +235,14 @@ func (m *ObjectMetastore) Sections(ctx context.Context, start, end time.Time, ma
226235
level.Debug(m.logger).Log("msg", "resolved index files", "count", len(indexPaths), "paths", strings.Join(indexPaths, ","))
227236
m.metrics.indexObjectsTotal.Observe(float64(len(indexPaths)))
228237

238+
// Return early if no index files are found
239+
if len(indexPaths) == 0 {
240+
m.metrics.resolvedSectionsTotal.Observe(0)
241+
duration := sectionsTimer.ObserveDuration()
242+
level.Debug(utillog.WithContext(ctx, m.logger)).Log("msg", "resolved sections", "duration", duration, "sections", 0)
243+
return nil, nil
244+
}
245+
229246
// init index files
230247
indexObjects := make([]*dataobj.Object, len(indexPaths))
231248
g, initCtx := errgroup.WithContext(ctx)
@@ -262,9 +279,6 @@ func (m *ObjectMetastore) Sections(ctx context.Context, start, end time.Time, ma
262279
}
263280

264281
streamSectionPointers = intersectSections(streamSectionPointers, sectionMembershipEstimates)
265-
if len(streamSectionPointers) == 0 {
266-
return nil, errors.New("no relevant sections returned")
267-
}
268282
}
269283

270284
duration := sectionsTimer.ObserveDuration()

pkg/dataobj/metastore/object_test.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,15 @@ func TestSectionsForStreamMatchers(t *testing.T) {
311311
name string
312312
matchers []*labels.Matcher
313313
predicates []*labels.Matcher
314+
start, end time.Time
314315
wantCount int
315316
}{
316317
{
317318
name: "no matchers returns no sections",
318319
matchers: nil,
319320
predicates: nil,
321+
start: now.Add(-time.Hour),
322+
end: now.Add(time.Hour),
320323
wantCount: 0,
321324
},
322325
{
@@ -325,6 +328,8 @@ func TestSectionsForStreamMatchers(t *testing.T) {
325328
labels.MustNewMatcher(labels.MatchEqual, "app", "foo"),
326329
},
327330
predicates: nil,
331+
start: now.Add(-time.Hour),
332+
end: now.Add(time.Hour),
328333
wantCount: 1,
329334
},
330335
{
@@ -333,6 +338,8 @@ func TestSectionsForStreamMatchers(t *testing.T) {
333338
labels.MustNewMatcher(labels.MatchEqual, "app", "doesnotexist"),
334339
},
335340
predicates: nil,
341+
start: now.Add(-time.Hour),
342+
end: now.Add(time.Hour),
336343
wantCount: 0,
337344
},
338345
{
@@ -343,13 +350,37 @@ func TestSectionsForStreamMatchers(t *testing.T) {
343350
predicates: []*labels.Matcher{
344351
labels.MustNewMatcher(labels.MatchRegexp, "bar", "something"),
345352
},
353+
start: now.Add(-time.Hour),
354+
end: now.Add(time.Hour),
346355
wantCount: 1,
347356
},
357+
{
358+
name: "stream matcher with not matching predicate returns no matching sections",
359+
matchers: []*labels.Matcher{
360+
labels.MustNewMatcher(labels.MatchEqual, "app", "foo"),
361+
},
362+
predicates: []*labels.Matcher{
363+
labels.MustNewMatcher(labels.MatchEqual, "bar", "something"),
364+
},
365+
start: now.Add(-time.Hour),
366+
end: now.Add(time.Hour),
367+
wantCount: 0,
368+
},
369+
{
370+
name: "matcher returns no matching sections if time range is out of bounds",
371+
matchers: []*labels.Matcher{
372+
labels.MustNewMatcher(labels.MatchEqual, "app", "foo"),
373+
},
374+
predicates: nil,
375+
start: now.Add(-3 * time.Hour),
376+
end: now.Add(-2 * time.Hour),
377+
wantCount: 0,
378+
},
348379
}
349380

350381
for _, tt := range tests {
351382
t.Run(tt.name, func(t *testing.T) {
352-
sections, err := mstore.Sections(ctx, now.Add(-time.Hour), now.Add(time.Hour), tt.matchers, tt.predicates)
383+
sections, err := mstore.Sections(ctx, tt.start, tt.end, tt.matchers, tt.predicates)
353384
require.NoError(t, err)
354385
require.Len(t, sections, tt.wantCount)
355386
for _, section := range sections {

0 commit comments

Comments
 (0)