forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazy_index.go
75 lines (66 loc) · 2.21 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
package tsdb
import (
"context"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/grafana/loki/pkg/storage/chunk"
"github.com/grafana/loki/pkg/storage/stores/index/stats"
"github.com/grafana/loki/pkg/storage/stores/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, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]ChunkRef, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.GetChunkRefs(ctx, userID, from, through, res, shard, matchers...)
}
func (f LazyIndex) Series(ctx context.Context, userID string, from, through model.Time, res []Series, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]Series, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.Series(ctx, userID, from, through, res, shard, 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, blooms *stats.Blooms, shard *index.ShardAnnotation, matchers ...*labels.Matcher) (*stats.Blooms, error) {
i, err := f()
if err != nil {
return nil, err
}
return i.Stats(ctx, userID, from, through, blooms, shard, matchers...)
}