github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/tsdb/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  type Series struct {
    15  	Labels      labels.Labels
    16  	Fingerprint model.Fingerprint
    17  }
    18  
    19  type ChunkRef struct {
    20  	User        string
    21  	Fingerprint model.Fingerprint
    22  	Start, End  model.Time
    23  	Checksum    uint32
    24  }
    25  
    26  // Compares by (Start, End)
    27  // Assumes User is equivalent
    28  func (r ChunkRef) Less(x ChunkRef) bool {
    29  	if r.Start != x.Start {
    30  		return r.Start < x.Start
    31  	}
    32  	return r.End <= x.End
    33  }
    34  
    35  type Index interface {
    36  	Bounded
    37  	SetChunkFilterer(chunkFilter chunk.RequestChunkFilterer)
    38  	Close() error
    39  	// GetChunkRefs accepts an optional []ChunkRef argument.
    40  	// If not nil, it will use that slice to build the result,
    41  	// allowing us to avoid unnecessary allocations at the caller's discretion.
    42  	// If nil, the underlying index implementation is required
    43  	// to build the resulting slice nonetheless (it should not panic),
    44  	// ideally by requesting a slice from the pool.
    45  	// Shard is also optional. If not nil, TSDB will limit the result to
    46  	// the requested shard. If it is nil, TSDB will return all results,
    47  	// regardless of shard.
    48  	// Note: any shard used must be a valid factor of two, meaning `0_of_2` and `3_of_4` are fine, but `0_of_3` is not.
    49  	GetChunkRefs(ctx context.Context, userID string, from, through model.Time, res []ChunkRef, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]ChunkRef, error)
    50  	// Series follows the same semantics regarding the passed slice and shard as GetChunkRefs.
    51  	Series(ctx context.Context, userID string, from, through model.Time, res []Series, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]Series, error)
    52  	LabelNames(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) ([]string, error)
    53  	LabelValues(ctx context.Context, userID string, from, through model.Time, name string, matchers ...*labels.Matcher) ([]string, error)
    54  	Stats(ctx context.Context, userID string, from, through model.Time, blooms *stats.Blooms, shard *index.ShardAnnotation, matchers ...*labels.Matcher) (*stats.Blooms, error)
    55  }
    56  
    57  type NoopIndex struct{}
    58  
    59  func (NoopIndex) Close() error                       { return nil }
    60  func (NoopIndex) Bounds() (from, through model.Time) { return }
    61  func (NoopIndex) GetChunkRefs(ctx context.Context, userID string, from, through model.Time, res []ChunkRef, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]ChunkRef, error) {
    62  	return nil, nil
    63  }
    64  
    65  // Series follows the same semantics regarding the passed slice and shard as GetChunkRefs.
    66  func (NoopIndex) Series(ctx context.Context, userID string, from, through model.Time, res []Series, shard *index.ShardAnnotation, matchers ...*labels.Matcher) ([]Series, error) {
    67  	return nil, nil
    68  }
    69  func (NoopIndex) LabelNames(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) ([]string, error) {
    70  	return nil, nil
    71  }
    72  func (NoopIndex) LabelValues(ctx context.Context, userID string, from, through model.Time, name string, matchers ...*labels.Matcher) ([]string, error) {
    73  	return nil, nil
    74  }
    75  
    76  func (NoopIndex) Stats(ctx context.Context, userID string, from, through model.Time, blooms *stats.Blooms, shard *index.ShardAnnotation, matchers ...*labels.Matcher) (*stats.Blooms, error) {
    77  	return nil, nil
    78  }
    79  
    80  func (NoopIndex) SetChunkFilterer(chunkFilter chunk.RequestChunkFilterer) {}