github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/tsdb/lazy_index.go (about)

     1  package tsdb
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/prometheus/common/model"
     7  	"github.com/prometheus/prometheus/model/labels"
     8  
     9  	"github.com/grafana/loki/pkg/storage/chunk"
    10  	"github.com/grafana/loki/pkg/storage/stores/index/stats"
    11  	"github.com/grafana/loki/pkg/storage/stores/tsdb/index"
    12  )
    13  
    14  // Index adapter for a function which returns an index when queried.
    15  type LazyIndex func() (Index, error)
    16  
    17  func (f LazyIndex) Bounds() (model.Time, model.Time) {
    18  	i, err := f()
    19  	if err != nil {
    20  		return 0, 0
    21  	}
    22  	return i.Bounds()
    23  }
    24  
    25  func (f LazyIndex) SetChunkFilterer(chunkFilter chunk.RequestChunkFilterer) {
    26  	i, err := f()
    27  	if err == nil {
    28  		i.SetChunkFilterer(chunkFilter)
    29  	}
    30  }
    31  
    32  func (f LazyIndex) Close() error {
    33  	i, err := f()
    34  	if err != nil {
    35  		return err
    36  	}
    37  	return i.Close()
    38  }
    39  
    40  func (f LazyIndex) GetChunkRefs(ctx context.Context, userID string, from, through model.Time, res []ChunkRef, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]ChunkRef, error) {
    41  	i, err := f()
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  	return i.GetChunkRefs(ctx, userID, from, through, res, shard, matchers...)
    46  }
    47  func (f LazyIndex) Series(ctx context.Context, userID string, from, through model.Time, res []Series, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]Series, error) {
    48  	i, err := f()
    49  	if err != nil {
    50  		return nil, err
    51  	}
    52  	return i.Series(ctx, userID, from, through, res, shard, matchers...)
    53  }
    54  func (f LazyIndex) LabelNames(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) ([]string, error) {
    55  	i, err := f()
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  	return i.LabelNames(ctx, userID, from, through, matchers...)
    60  }
    61  func (f LazyIndex) LabelValues(ctx context.Context, userID string, from, through model.Time, name string, matchers ...*labels.Matcher) ([]string, error) {
    62  	i, err := f()
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	return i.LabelValues(ctx, userID, from, through, name, matchers...)
    67  }
    68  
    69  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) {
    70  	i, err := f()
    71  	if err != nil {
    72  		return nil, err
    73  	}
    74  	return i.Stats(ctx, userID, from, through, blooms, shard, matchers...)
    75  }