querier

package
v3.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: AGPL-3.0 Imports: 73 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildQueryIntervalsWithLookback added in v3.6.0

func BuildQueryIntervalsWithLookback(cfg Config, queryStart, queryEnd time.Time, queryIngestersWithin time.Duration) (*QueryInterval, *QueryInterval)

func DefaultLimitsConfig

func DefaultLimitsConfig() validation.Limits

func InitWorkerService

func InitWorkerService(
	logger log.Logger,
	cfg WorkerServiceConfig,
	reg prometheus.Registerer,
	handler queryrangebase.Handler,
	codec querier_worker.RequestCodec,
) (serve services.Service, err error)

InitWorkerService takes a config object, a map of routes to handlers, an external http router and external http handler, and an auth middleware wrapper. This function creates an internal HTTP router that responds to all the provided query routes/handlers. This router can either be registered with the external Loki HTTP server, or be used internally by a querier worker so that it does not conflict with the routes registered by the Query Frontend module.

  1. Query-Frontend Enabled: If Loki has an All or QueryFrontend target, the internal HTTP router is wrapped with Tenant ID parsing middleware and passed to the frontend worker.

  2. Querier Standalone: The querier will register the internal HTTP router with the external HTTP router for the Prometheus API routes. Then the external HTTP server will be passed as a http.Handler to the frontend worker.

func NewPartitionContext added in v3.4.0

func NewPartitionContext(ctx context.Context) context.Context

NewPartitionContext creates a new partition context This is used to track which ingesters were used in the query and reuse the same ingesters for consecutive queries

func NewQuerierHTTPHandler

func NewQuerierHTTPHandler(h *Handler) http.Handler

func WrapQuerySpanAndTimeout

func WrapQuerySpanAndTimeout(call string, limits querier_limits.Limits) middleware.Interface

WrapQuerySpanAndTimeout applies a context deadline and a span logger to a query call.

The timeout is based on the per-tenant query timeout configuration.

Types

type Config

type Config struct {
	TailMaxDuration           time.Duration    `yaml:"tail_max_duration"`
	ExtraQueryDelay           time.Duration    `yaml:"extra_query_delay,omitempty"`
	QueryIngestersWithin      time.Duration    `yaml:"query_ingesters_within,omitempty"`
	Engine                    logql.EngineOpts `yaml:"engine,omitempty"`
	EngineV2                  engine.Config    `yaml:"engine_v2,omitempty" category:"experimental"`
	MaxConcurrent             int              `yaml:"max_concurrent"`
	QueryStoreOnly            bool             `yaml:"query_store_only"`
	QueryIngesterOnly         bool             `yaml:"query_ingester_only"`
	MultiTenantQueriesEnabled bool             `yaml:"multi_tenant_queries_enabled"`
	PerRequestLimitsEnabled   bool             `yaml:"per_request_limits_enabled"`
	QueryPartitionIngesters   bool             `yaml:"query_partition_ingesters" category:"experimental"`

	IngesterQueryStoreMaxLookback time.Duration `yaml:"-"`
	QueryPatternIngestersWithin   time.Duration `yaml:"-"`
	DataobjStorageLag             time.Duration `yaml:"dataobj_storage_lag" category:"experimental"`
	DataobjStorageStart           string        `yaml:"dataobj_storage_start" category:"experimental"`
}

Config for a querier.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags register flags.

func (*Config) RegisterFlagsWithPrefix added in v3.6.0

func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the config.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewQuerierHandler

func NewQuerierHandler(api *QuerierAPI) *Handler

func (*Handler) Do

type IngesterQuerier

type IngesterQuerier struct {
	// contains filtered or unexported fields
}

IngesterQuerier helps with querying the ingesters.

func NewIngesterQuerier

func NewIngesterQuerier(querierConfig Config, clientCfg client.Config, ring ring.ReadRing, partitionRing *ring.PartitionInstanceRing, getShardCountForTenant func(string) int, metricsNamespace string, logger log.Logger) (*IngesterQuerier, error)

func (*IngesterQuerier) DetectedLabel

func (*IngesterQuerier) GetChunkIDs

func (q *IngesterQuerier) GetChunkIDs(ctx context.Context, from, through model.Time, matchers ...*labels.Matcher) ([]string, error)

func (*IngesterQuerier) Label

func (q *IngesterQuerier) Label(ctx context.Context, req *logproto.LabelRequest) ([][]string, error)

func (*IngesterQuerier) SelectLogs

func (q *IngesterQuerier) SelectLogs(ctx context.Context, params logql.SelectLogParams) ([]iter.EntryIterator, error)

func (*IngesterQuerier) SelectSample

func (q *IngesterQuerier) SelectSample(ctx context.Context, params logql.SelectSampleParams) ([]iter.SampleIterator, error)

func (*IngesterQuerier) Series

func (*IngesterQuerier) Stats

func (q *IngesterQuerier) Stats(ctx context.Context, _ string, from, through model.Time, matchers ...*labels.Matcher) (*index_stats.Stats, error)

func (*IngesterQuerier) Tail

func (*IngesterQuerier) TailDisconnectedIngesters

func (q *IngesterQuerier) TailDisconnectedIngesters(ctx context.Context, req *logproto.TailRequest, connectedIngestersAddr []string) (map[string]logproto.Querier_TailClient, error)

func (*IngesterQuerier) TailersCount

func (q *IngesterQuerier) TailersCount(ctx context.Context) ([]uint32, error)

func (*IngesterQuerier) Volume

func (q *IngesterQuerier) Volume(ctx context.Context, _ string, from, through model.Time, limit int32, targetLabels []string, aggregateBy string, matchers ...*labels.Matcher) (*logproto.VolumeResponse, error)

type MultiTenantQuerier

type MultiTenantQuerier struct {
	Querier
	// contains filtered or unexported fields
}

MultiTenantQuerier is able to query across different tenants.

func NewMultiTenantQuerier

func NewMultiTenantQuerier(querier Querier, logger log.Logger) *MultiTenantQuerier

NewMultiTenantQuerier returns a new querier able to query across different tenants.

func (*MultiTenantQuerier) DetectedFields

func (*MultiTenantQuerier) DetectedLabels

func (*MultiTenantQuerier) IndexShards

func (q *MultiTenantQuerier) IndexShards(
	ctx context.Context,
	req *loghttp.RangeQuery,
	targetBytesPerShard uint64,
) (*logproto.ShardsResponse, error)

func (*MultiTenantQuerier) IndexStats

func (q *MultiTenantQuerier) IndexStats(ctx context.Context, req *loghttp.RangeQuery) (*stats.Stats, error)

func (*MultiTenantQuerier) Label

func (*MultiTenantQuerier) SelectLogs

func (*MultiTenantQuerier) SelectSamples

func (*MultiTenantQuerier) Series

func (*MultiTenantQuerier) Volume

type PartitionContext added in v3.4.0

type PartitionContext struct {
	// contains filtered or unexported fields
}

func ExtractPartitionContext added in v3.4.0

func ExtractPartitionContext(ctx context.Context) *PartitionContext

func (*PartitionContext) AddClient added in v3.4.0

func (p *PartitionContext) AddClient(client logproto.QuerierClient, addr string)

func (*PartitionContext) IsPartitioned added in v3.4.0

func (p *PartitionContext) IsPartitioned() bool

func (*PartitionContext) RemoveClient added in v3.4.0

func (p *PartitionContext) RemoveClient(addr string)

func (*PartitionContext) SetIsPartitioned added in v3.4.0

func (p *PartitionContext) SetIsPartitioned(isPartitioned bool)

type PartitionIngesterUsed added in v3.4.0

type PartitionIngesterUsed struct {
	// contains filtered or unexported fields
}

type Querier

Querier can select logs and samples and handle query requests.

type QuerierAPI

type QuerierAPI struct {
	// contains filtered or unexported fields
}

nolint // QuerierAPI defines HTTP handler functions for the querier.

func NewQuerierAPI

func NewQuerierAPI(cfg Config, mCfg metastore.Config, querier Querier, limits querier_limits.Limits, store objstore.Bucket, reg prometheus.Registerer, logger log.Logger) *QuerierAPI

NewQuerierAPI returns an instance of the QuerierAPI.

func (*QuerierAPI) DetectedFieldsHandler

func (*QuerierAPI) DetectedLabelsHandler

DetectedLabelsHandler returns a response for detected labels

func (*QuerierAPI) IndexShardsHandler

func (q *QuerierAPI) IndexShardsHandler(ctx context.Context, req *loghttp.RangeQuery, targetBytesPerShard uint64) (*logproto.ShardsResponse, error)

func (*QuerierAPI) IndexStatsHandler

func (q *QuerierAPI) IndexStatsHandler(ctx context.Context, req *loghttp.RangeQuery) (*logproto.IndexStatsResponse, error)

IndexStatsHandler queries the index for the data statistics related to a query

func (*QuerierAPI) InstantQueryHandler

func (q *QuerierAPI) InstantQueryHandler(ctx context.Context, req *queryrange.LokiInstantRequest) (logqlmodel.Result, error)

InstantQueryHandler is a http.HandlerFunc for instant queries.

func (*QuerierAPI) LabelHandler

func (q *QuerierAPI) LabelHandler(ctx context.Context, req *logproto.LabelRequest) (*logproto.LabelResponse, error)

LabelHandler is a http.HandlerFunc for handling label queries.

func (*QuerierAPI) PatternsHandler

func (*QuerierAPI) RangeQueryHandler

func (q *QuerierAPI) RangeQueryHandler(ctx context.Context, req *queryrange.LokiRequest) (logqlmodel.Result, error)

RangeQueryHandler is a http.HandlerFunc for range queries and legacy log queries

func (*QuerierAPI) SeriesHandler

SeriesHandler returns the list of time series that match a certain label set. See https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers

func (*QuerierAPI) VolumeHandler

func (q *QuerierAPI) VolumeHandler(ctx context.Context, req *logproto.VolumeRequest) (*logproto.VolumeResponse, error)

VolumeHandler queries the index label volumes related to the passed matchers and given time range. Returns either N values where N is the time range / step and a single value for a time range depending on the request.

type QueryInterval added in v3.6.0

type QueryInterval struct {
	// contains filtered or unexported fields
}

type QueryResponse

type QueryResponse struct {
	ResultType parser.ValueType `json:"resultType"`
	Result     parser.Value     `json:"result"`
}

type SingleTenantQuerier

type SingleTenantQuerier struct {
	// contains filtered or unexported fields
}

SingleTenantQuerier handles single tenant queries.

func New

func New(cfg Config, store Store, ingesterQuerier *IngesterQuerier, limits querier_limits.Limits, d deletion.DeleteGetter, logger log.Logger) (*SingleTenantQuerier, error)

New makes a new Querier.

func (*SingleTenantQuerier) Check

Check implements the grpc healthcheck

func (*SingleTenantQuerier) DetectedFields

TODO(twhitney): Delete this method and the GRPC service signature. This is now handled in the query frontend.

func (*SingleTenantQuerier) DetectedLabels

DetectedLabels fetches labels and values from store and ingesters and filters them by relevance criteria as per logs app.

func (*SingleTenantQuerier) IndexShards

func (q *SingleTenantQuerier) IndexShards(
	ctx context.Context,
	req *loghttp.RangeQuery,
	targetBytesPerShard uint64,
) (*logproto.ShardsResponse, error)

func (*SingleTenantQuerier) IndexStats

func (q *SingleTenantQuerier) IndexStats(ctx context.Context, req *loghttp.RangeQuery) (*stats.Stats, error)

func (*SingleTenantQuerier) Label

Label does the heavy lifting for a Label query.

func (*SingleTenantQuerier) Patterns

func (*SingleTenantQuerier) SelectLogs

Select Implements logql.Querier which select logs via matchers and regex filters.

func (*SingleTenantQuerier) SelectSamples

func (*SingleTenantQuerier) Series

Series fetches any matching series for a list of matcher sets

func (*SingleTenantQuerier) Volume

func (*SingleTenantQuerier) WithPatternQuerier

func (q *SingleTenantQuerier) WithPatternQuerier(pq pattern.PatterQuerier)

type Store

type Store interface {
	SelectSamples(ctx context.Context, req logql.SelectSampleParams) (iter.SampleIterator, error)
	SelectLogs(ctx context.Context, req logql.SelectLogParams) (iter.EntryIterator, error)
	SelectSeries(ctx context.Context, req logql.SelectLogParams) ([]logproto.SeriesIdentifier, error)
	LabelValuesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string, labelName string, matchers ...*labels.Matcher) ([]string, error)
	LabelNamesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string, matchers ...*labels.Matcher) ([]string, error)
	Stats(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) (*stats.Stats, error)
	Volume(ctx context.Context, userID string, from, through model.Time, limit int32, targetLabels []string, aggregateBy string, matchers ...*labels.Matcher) (*logproto.VolumeResponse, error)
	GetShards(
		ctx context.Context,
		userID string,
		from, through model.Time,
		targetBytesPerShard uint64,
		predicate chunk.Predicate,
	) (*logproto.ShardsResponse, error)
}

Store is the store interface we need on the querier.

type StoreCombiner added in v3.5.0

type StoreCombiner struct {
	// contains filtered or unexported fields
}

StoreCombiner combines multiple stores and routes queries to the appropriate store based on time range

func NewStoreCombiner added in v3.5.0

func NewStoreCombiner(stores []StoreConfig) *StoreCombiner

NewStoreCombiner creates a new StoreCombiner with the given store configurations. The stores should be provided in order from newest to oldest time ranges.

func (*StoreCombiner) GetShards added in v3.5.0

func (sc *StoreCombiner) GetShards(ctx context.Context, userID string, from, through model.Time, targetBytesPerShard uint64, predicate chunk.Predicate) (*logproto.ShardsResponse, error)

GetShards implements Store

func (*StoreCombiner) LabelNamesForMetricName added in v3.5.0

func (sc *StoreCombiner) LabelNamesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string, matchers ...*labels.Matcher) ([]string, error)

LabelNamesForMetricName implements Store

func (*StoreCombiner) LabelValuesForMetricName added in v3.5.0

func (sc *StoreCombiner) LabelValuesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string, labelName string, matchers ...*labels.Matcher) ([]string, error)

LabelValuesForMetricName implements Store

func (*StoreCombiner) SelectLogs added in v3.5.0

SelectLogs implements Store

func (*StoreCombiner) SelectSamples added in v3.5.0

SelectSamples implements Store

func (*StoreCombiner) SelectSeries added in v3.5.0

SelectSeries implements Store

func (*StoreCombiner) Stats added in v3.5.0

func (sc *StoreCombiner) Stats(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) (*stats.Stats, error)

Stats implements Store

func (*StoreCombiner) Volume added in v3.5.0

func (sc *StoreCombiner) Volume(ctx context.Context, userID string, from, through model.Time, limit int32, targetLabels []string, aggregateBy string, matchers ...*labels.Matcher) (*logproto.VolumeResponse, error)

Volume implements Store

type StoreConfig added in v3.5.0

type StoreConfig struct {
	Store Store
	From  model.Time // queries >= From will use this store
}

StoreConfig represents a store and its time range configuration

type TenantEntryIterator

type TenantEntryIterator struct {
	iter.EntryIterator
	// contains filtered or unexported fields
}

TenantEntry Iterator wraps an entry iterator and adds the tenant label.

func NewTenantEntryIterator

func NewTenantEntryIterator(iter iter.EntryIterator, id string) *TenantEntryIterator

func (*TenantEntryIterator) Labels

func (i *TenantEntryIterator) Labels() string

type TenantSampleIterator

type TenantSampleIterator struct {
	iter.SampleIterator
	// contains filtered or unexported fields
}

TenantEntry Iterator wraps a sample iterator and adds the tenant label.

func NewTenantSampleIterator

func NewTenantSampleIterator(iter iter.SampleIterator, id string) *TenantSampleIterator

func (*TenantSampleIterator) Labels

func (i *TenantSampleIterator) Labels() string

type WorkerServiceConfig

type WorkerServiceConfig struct {
	AllEnabled            bool
	ReadEnabled           bool
	GrpcListenAddress     string
	GrpcListenPort        int
	QuerierMaxConcurrent  int
	QuerierWorkerConfig   *querier_worker.Config
	QueryFrontendEnabled  bool
	QuerySchedulerEnabled bool
	SchedulerRing         ring.ReadRing
}

func (WorkerServiceConfig) QuerierRunningStandalone

func (cfg WorkerServiceConfig) QuerierRunningStandalone() bool

Directories

Path Synopsis
Package contains methods to marshal logqmodel types to queryrange Protobuf types.
Package contains methods to marshal logqmodel types to queryrange Protobuf types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL