-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
lazy_index.go
90 lines (79 loc) · 3.02 KB
/
lazy_index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package tsdb
import (
"context"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/grafana/loki/v3/pkg/storage/chunk"
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/tsdb/index"
)
// Index adapter for a function which returns an index when queried.
type LazyIndex func() (Index, error)
func (f LazyIndex) Bounds() (model.Time, model.Time) {
i, err := f()
if err != nil {
return 0, 0
}
return i.Bounds()
}
func (f LazyIndex) SetChunkFilterer(chunkFilter chunk.RequestChunkFilterer) {
i, err := f()
if err == nil {
i.SetChunkFilterer(chunkFilter)
}
}
func (f LazyIndex) Close() error {
i, err := f()
if err != nil {
return err
}
return i.Close()
}
func (f LazyIndex) GetChunkRefs(ctx context.Context, userID string, from, through model.Time, res []ChunkRef, fpFilter index.FingerprintFilter, matchers ...*labels.Matcher) ([]ChunkRef, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.GetChunkRefs(ctx, userID, from, through, res, fpFilter, matchers...)
}
func (f LazyIndex) Series(ctx context.Context, userID string, from, through model.Time, res []Series, fpFilter index.FingerprintFilter, matchers ...*labels.Matcher) ([]Series, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.Series(ctx, userID, from, through, res, fpFilter, matchers...)
}
func (f LazyIndex) LabelNames(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) ([]string, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.LabelNames(ctx, userID, from, through, matchers...)
}
func (f LazyIndex) LabelValues(ctx context.Context, userID string, from, through model.Time, name string, matchers ...*labels.Matcher) ([]string, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.LabelValues(ctx, userID, from, through, name, matchers...)
}
func (f LazyIndex) Stats(ctx context.Context, userID string, from, through model.Time, acc IndexStatsAccumulator, fpFilter index.FingerprintFilter, shouldIncludeChunk shouldIncludeChunk, matchers ...*labels.Matcher) error {
i, err := f()
if err != nil {
return err
}
return i.Stats(ctx, userID, from, through, acc, fpFilter, shouldIncludeChunk, matchers...)
}
func (f LazyIndex) Volume(ctx context.Context, userID string, from, through model.Time, acc VolumeAccumulator, fpFilter index.FingerprintFilter, shouldIncludeChunk shouldIncludeChunk, targetLabels []string, aggregateBy string, matchers ...*labels.Matcher) error {
i, err := f()
if err != nil {
return err
}
return i.Volume(ctx, userID, from, through, acc, fpFilter, shouldIncludeChunk, targetLabels, aggregateBy, matchers...)
}
func (f LazyIndex) ForSeries(ctx context.Context, userID string, fpFilter index.FingerprintFilter, from model.Time, through model.Time, fn func(labels.Labels, model.Fingerprint, []index.ChunkMeta) (stop bool), matchers ...*labels.Matcher) error {
i, err := f()
if err != nil {
return err
}
return i.ForSeries(ctx, userID, fpFilter, from, through, fn, matchers...)
}