querier

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: Apache-2.0 Imports: 87 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLimitsConfig added in v1.11.0

func DefaultLimitsConfig() validation.Limits

func MetadataHandler added in v1.1.0

func MetadataHandler(d Distributor) http.Handler

MetadataHandler returns metric metadata held by Cortex for a given tenant. It is kept and returned as a set.

func New

New builds a queryable and promql engine.

func NewErrorTranslateQueryable added in v1.10.0

func NewErrorTranslateQueryable(q storage.Queryable) storage.Queryable

func NewErrorTranslateQueryableWithFn added in v1.11.0

func NewErrorTranslateQueryableWithFn(q storage.Queryable, fn ErrTranslateFn) storage.Queryable

func NewErrorTranslateSampleAndChunkQueryable added in v1.11.0

func NewErrorTranslateSampleAndChunkQueryable(q storage.SampleAndChunkQueryable) storage.SampleAndChunkQueryable

func NewErrorTranslateSampleAndChunkQueryableWithFn added in v1.11.0

func NewErrorTranslateSampleAndChunkQueryableWithFn(q storage.SampleAndChunkQueryable, fn ErrTranslateFn) storage.SampleAndChunkQueryable

func NewQueryable

func NewQueryable(distributor QueryableWithFilter, stores []QueryableWithFilter, chunkIterFn chunkIteratorFunc, cfg Config, limits *validation.Overrides, tombstonesLoader purger.TombstonesLoader) storage.Queryable

NewQueryable creates a new Queryable for cortex.

func NewSampleAndChunkQueryable added in v1.7.0

func NewSampleAndChunkQueryable(q storage.Queryable) storage.SampleAndChunkQueryable

NewSampleAndChunkQueryable creates a SampleAndChunkQueryable from a Queryable with a ChunkQueryable stub, that errors once it get's called.

func RemoteReadHandler

func RemoteReadHandler(q storage.Queryable, logger log.Logger) http.Handler

RemoteReadHandler handles Prometheus remote read requests.

func TranslateToPromqlAPIError added in v1.10.0

func TranslateToPromqlAPIError(err error) error

TranslateToPromqlAPIError converts error to one of promql.Errors for consumption in PromQL API. PromQL API only recognizes few errors, and converts everything else to HTTP status code 422.

Specifically, it supports:

promql.ErrQueryCanceled, mapped to 503
promql.ErrQueryTimeout, mapped to 503
promql.ErrStorage mapped to 500
anything else is mapped to 422

Querier code produces different kinds of errors, and we want to map them to above-mentioned HTTP status codes correctly.

Details: - vendor/github.com/prometheus/prometheus/web/api/v1/api.go, respondError function only accepts *apiError types. - translation of error to *apiError happens in vendor/github.com/prometheus/prometheus/web/api/v1/api.go, returnAPIError method.

Types

type BlocksConsistencyChecker added in v1.2.0

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

func NewBlocksConsistencyChecker added in v1.2.0

func NewBlocksConsistencyChecker(uploadGracePeriod, deletionGracePeriod time.Duration, logger log.Logger, reg prometheus.Registerer) *BlocksConsistencyChecker

func (*BlocksConsistencyChecker) Check added in v1.2.0

func (c *BlocksConsistencyChecker) Check(knownBlocks bucketindex.Blocks, knownDeletionMarks map[ulid.ULID]*bucketindex.BlockDeletionMark, queriedBlocks []ulid.ULID) (missingBlocks []ulid.ULID)

type BlocksFinder added in v1.1.0

type BlocksFinder interface {
	services.Service

	// GetBlocks returns known blocks for userID containing samples within the range minT
	// and maxT (milliseconds, both included). Returned blocks are sorted by MaxTime descending.
	GetBlocks(ctx context.Context, userID string, minT, maxT int64) (bucketindex.Blocks, map[ulid.ULID]*bucketindex.BlockDeletionMark, error)
}

BlocksFinder is the interface used to find blocks for a given user and time range.

type BlocksStoreClient added in v1.2.0

type BlocksStoreClient interface {
	storegatewaypb.StoreGatewayClient

	// RemoteAddress returns the address of the remote store-gateway and is used to uniquely
	// identify a store-gateway backend instance.
	RemoteAddress() string
}

BlocksStoreClient is the interface that should be implemented by any client used to query a backend store-gateway.

type BlocksStoreLimits added in v1.3.0

type BlocksStoreLimits interface {
	bucket.TenantConfigProvider

	MaxChunksPerQueryFromStore(userID string) int
	StoreGatewayTenantShardSize(userID string) float64
}

BlocksStoreLimits is the interface that should be implemented by the limits provider.

type BlocksStoreQueryable added in v1.1.0

type BlocksStoreQueryable struct {
	services.Service
	// contains filtered or unexported fields
}

BlocksStoreQueryable is a queryable which queries blocks storage via the store-gateway.

func NewBlocksStoreQueryable added in v1.1.0

func NewBlocksStoreQueryable(
	stores BlocksStoreSet,
	finder BlocksFinder,
	consistency *BlocksConsistencyChecker,
	limits BlocksStoreLimits,
	queryStoreAfter time.Duration,
	logger log.Logger,
	reg prometheus.Registerer,
) (*BlocksStoreQueryable, error)

func NewBlocksStoreQueryableFromConfig added in v1.1.0

func NewBlocksStoreQueryableFromConfig(querierCfg Config, gatewayCfg storegateway.Config, storageCfg cortex_tsdb.BlocksStorageConfig, limits BlocksStoreLimits, logger log.Logger, reg prometheus.Registerer) (*BlocksStoreQueryable, error)

func (*BlocksStoreQueryable) Querier added in v1.1.0

func (q *BlocksStoreQueryable) Querier(mint, maxt int64) (storage.Querier, error)

Querier returns a new Querier on the storage.

type BlocksStoreSet added in v1.1.0

type BlocksStoreSet interface {
	services.Service

	// GetClientsFor returns the store gateway clients that should be used to
	// query the set of blocks in input. The exclude parameter is the map of
	// blocks -> store-gateway addresses that should be excluded.
	GetClientsFor(userID string, blockIDs []ulid.ULID, exclude map[ulid.ULID][]string, attemptedBlocksZones map[ulid.ULID]map[string]int) (map[BlocksStoreClient][]ulid.ULID, error)
}

BlocksStoreSet is the interface used to get the clients to query series on a set of blocks.

type BucketIndexBlocksFinder added in v1.7.0

type BucketIndexBlocksFinder struct {
	services.Service
	// contains filtered or unexported fields
}

BucketIndexBlocksFinder implements BlocksFinder interface and find blocks in the bucket looking up the bucket index.

func NewBucketIndexBlocksFinder added in v1.7.0

func (*BucketIndexBlocksFinder) GetBlocks added in v1.7.0

GetBlocks implements BlocksFinder.

type BucketIndexBlocksFinderConfig added in v1.7.0

type BucketIndexBlocksFinderConfig struct {
	IndexLoader              bucketindex.LoaderConfig
	MaxStalePeriod           time.Duration
	IgnoreDeletionMarksDelay time.Duration
	IgnoreBlocksWithin       time.Duration
}

type BucketScanBlocksFinder added in v1.7.0

type BucketScanBlocksFinder struct {
	services.Service
	// contains filtered or unexported fields
}

BucketScanBlocksFinder is a BlocksFinder implementation periodically scanning the bucket to discover blocks.

func NewBucketScanBlocksFinder added in v1.7.0

func NewBucketScanBlocksFinder(cfg BucketScanBlocksFinderConfig, bucketClient objstore.Bucket, cfgProvider bucket.TenantConfigProvider, logger log.Logger, reg prometheus.Registerer) *BucketScanBlocksFinder

func (*BucketScanBlocksFinder) GetBlocks added in v1.7.0

GetBlocks returns known blocks for userID containing samples within the range minT and maxT (milliseconds, both included). Returned blocks are sorted by MaxTime descending.

type BucketScanBlocksFinderConfig added in v1.7.0

type BucketScanBlocksFinderConfig struct {
	ScanInterval             time.Duration
	TenantsConcurrency       int
	MetasConcurrency         int
	CacheDir                 string
	ConsistencyDelay         time.Duration
	IgnoreDeletionMarksDelay time.Duration
	IgnoreBlocksWithin       time.Duration
}

type ClientConfig added in v1.8.0

type ClientConfig struct {
	TLSEnabled      bool             `yaml:"tls_enabled"`
	TLS             tls.ClientConfig `yaml:",inline"`
	GRPCCompression string           `yaml:"grpc_compression"`
}

func (*ClientConfig) RegisterFlagsWithPrefix added in v1.8.0

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

type Config

type Config struct {
	MaxConcurrent             int           `yaml:"max_concurrent"`
	Timeout                   time.Duration `yaml:"timeout"`
	Iterators                 bool          `yaml:"iterators"`
	BatchIterators            bool          `yaml:"batch_iterators"`
	IngesterStreaming         bool          `yaml:"ingester_streaming"`
	IngesterMetadataStreaming bool          `yaml:"ingester_metadata_streaming"`
	MaxSamples                int           `yaml:"max_samples"`
	QueryIngestersWithin      time.Duration `yaml:"query_ingesters_within"`
	QueryStoreForLabels       bool          `yaml:"query_store_for_labels_enabled"`
	AtModifierEnabled         bool          `yaml:"at_modifier_enabled" doc:"hidden"`
	EnablePerStepStats        bool          `yaml:"per_step_stats_enabled"`

	// QueryStoreAfter the time after which queries should also be sent to the store and not just ingesters.
	QueryStoreAfter    time.Duration `yaml:"query_store_after"`
	MaxQueryIntoFuture time.Duration `yaml:"max_query_into_future"`

	// The default evaluation interval for the promql engine.
	// Needs to be configured for subqueries to work as it is the default
	// step if not specified.
	DefaultEvaluationInterval time.Duration `yaml:"default_evaluation_interval"`

	// Limit of number of steps allowed for every subquery expression in a query.
	MaxSubQuerySteps int64 `yaml:"max_subquery_steps"`

	// Directory for ActiveQueryTracker. If empty, ActiveQueryTracker will be disabled and MaxConcurrent will not be applied (!).
	// ActiveQueryTracker logs queries that were active during the last crash, but logs them on the next startup.
	// However, we need to use active query tracker, otherwise we cannot limit Max Concurrent queries in the PromQL
	// engine.
	ActiveQueryTrackerDir string `yaml:"active_query_tracker_dir"`
	// LookbackDelta determines the time since the last sample after which a time
	// series is considered stale.
	LookbackDelta time.Duration `yaml:"lookback_delta"`

	// Blocks storage only.
	StoreGatewayAddresses string       `yaml:"store_gateway_addresses"`
	StoreGatewayClient    ClientConfig `yaml:"store_gateway_client"`

	ShuffleShardingIngestersLookbackPeriod time.Duration `yaml:"shuffle_sharding_ingesters_lookback_period"`

	// Experimental. Use https://github.com/thanos-io/promql-engine rather than
	// the Prometheus query engine.
	ThanosEngine bool `yaml:"thanos_engine"`
}

Config contains the configuration require to create a querier

func DefaultQuerierConfig added in v1.11.0

func DefaultQuerierConfig() Config

func (*Config) GetStoreGatewayAddresses added in v1.1.0

func (cfg *Config) GetStoreGatewayAddresses() []string

func (*Config) RegisterFlags

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

RegisterFlags adds the flags required to config this to the given FlagSet.

func (*Config) Validate added in v0.7.0

func (cfg *Config) Validate() error

Validate the config

type Distributor

type Distributor interface {
	Query(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (model.Matrix, error)
	QueryStream(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (*client.QueryStreamResponse, error)
	QueryExemplars(ctx context.Context, from, to model.Time, matchers ...[]*labels.Matcher) (*client.ExemplarQueryResponse, error)
	LabelValuesForLabelName(ctx context.Context, from, to model.Time, label model.LabelName, matchers ...*labels.Matcher) ([]string, error)
	LabelValuesForLabelNameStream(ctx context.Context, from, to model.Time, label model.LabelName, matchers ...*labels.Matcher) ([]string, error)
	LabelNames(context.Context, model.Time, model.Time) ([]string, error)
	LabelNamesStream(context.Context, model.Time, model.Time) ([]string, error)
	MetricsForLabelMatchers(ctx context.Context, from, through model.Time, matchers ...*labels.Matcher) ([]metric.Metric, error)
	MetricsForLabelMatchersStream(ctx context.Context, from, through model.Time, matchers ...*labels.Matcher) ([]metric.Metric, error)
	MetricsMetadata(ctx context.Context) ([]scrape.MetricMetadata, error)
}

Distributor is the read interface to the distributor, made an interface here to reduce package coupling.

type DummyAlertmanagerRetriever

type DummyAlertmanagerRetriever struct{}

DummyAlertmanagerRetriever implements AlertmanagerRetriever.

func (DummyAlertmanagerRetriever) Alertmanagers

func (DummyAlertmanagerRetriever) Alertmanagers() []*url.URL

Alertmanagers implements AlertmanagerRetriever.

func (DummyAlertmanagerRetriever) DroppedAlertmanagers

func (DummyAlertmanagerRetriever) DroppedAlertmanagers() []*url.URL

DroppedAlertmanagers implements AlertmanagerRetriever.

type DummyRulesRetriever

type DummyRulesRetriever struct{}

DummyRulesRetriever implements RulesRetriever.

func (DummyRulesRetriever) AlertingRules

func (DummyRulesRetriever) AlertingRules() []*rules.AlertingRule

AlertingRules implements RulesRetriever.

func (DummyRulesRetriever) RuleGroups

func (DummyRulesRetriever) RuleGroups() []*rules.Group

RuleGroups implements RulesRetriever.

type DummyTargetRetriever

type DummyTargetRetriever struct{}

DummyTargetRetriever implements github.com/prometheus/prometheus/web/api/v1.targetRetriever.

func (DummyTargetRetriever) TargetsActive

func (DummyTargetRetriever) TargetsActive() map[string][]*scrape.Target

TargetsActive implements targetRetriever.

func (DummyTargetRetriever) TargetsDropped

func (DummyTargetRetriever) TargetsDropped() map[string][]*scrape.Target

TargetsDropped implements targetRetriever.

func (DummyTargetRetriever) TargetsDroppedCounts added in v1.16.0

func (DummyTargetRetriever) TargetsDroppedCounts() map[string]int

TargetsDroppedCounts implements targetRetriever.

type ErrTranslateFn added in v1.11.0

type ErrTranslateFn func(err error) error

ErrTranslateFn is used to translate or wrap error before returning it by functions in storage.SampleAndChunkQueryable interface. Input error may be nil.

type MockDistributor added in v1.11.0

type MockDistributor struct {
	mock.Mock
}

func (*MockDistributor) LabelNames added in v1.11.0

func (m *MockDistributor) LabelNames(ctx context.Context, from, to model.Time) ([]string, error)

func (*MockDistributor) LabelNamesStream added in v1.13.0

func (m *MockDistributor) LabelNamesStream(ctx context.Context, from, to model.Time) ([]string, error)

func (*MockDistributor) LabelValuesForLabelName added in v1.11.0

func (m *MockDistributor) LabelValuesForLabelName(ctx context.Context, from, to model.Time, lbl model.LabelName, matchers ...*labels.Matcher) ([]string, error)

func (*MockDistributor) LabelValuesForLabelNameStream added in v1.13.0

func (m *MockDistributor) LabelValuesForLabelNameStream(ctx context.Context, from, to model.Time, lbl model.LabelName, matchers ...*labels.Matcher) ([]string, error)

func (*MockDistributor) MetricsForLabelMatchers added in v1.11.0

func (m *MockDistributor) MetricsForLabelMatchers(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) ([]metric.Metric, error)

func (*MockDistributor) MetricsForLabelMatchersStream added in v1.13.0

func (m *MockDistributor) MetricsForLabelMatchersStream(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) ([]metric.Metric, error)

func (*MockDistributor) MetricsMetadata added in v1.11.0

func (m *MockDistributor) MetricsMetadata(ctx context.Context) ([]scrape.MetricMetadata, error)

func (*MockDistributor) Query added in v1.11.0

func (m *MockDistributor) Query(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (model.Matrix, error)

func (*MockDistributor) QueryExemplars added in v1.11.0

func (m *MockDistributor) QueryExemplars(ctx context.Context, from, to model.Time, matchers ...[]*labels.Matcher) (*client.ExemplarQueryResponse, error)

func (*MockDistributor) QueryStream added in v1.11.0

func (m *MockDistributor) QueryStream(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (*client.QueryStreamResponse, error)

type MockLimitingDistributor added in v1.16.0

type MockLimitingDistributor struct {
	MockDistributor
	// contains filtered or unexported fields
}

func (*MockLimitingDistributor) QueryStream added in v1.16.0

func (m *MockLimitingDistributor) QueryStream(ctx context.Context, from, to model.Time, matchers ...*labels.Matcher) (*client.QueryStreamResponse, error)

type QueryableWithFilter added in v1.3.0

type QueryableWithFilter interface {
	storage.Queryable

	// UseQueryable returns true if this queryable should be used to satisfy the query for given time range.
	// Query min and max time are in milliseconds since epoch.
	UseQueryable(now time.Time, queryMinT, queryMaxT int64) bool
}

QueryableWithFilter extends Queryable interface with `UseQueryable` filtering function.

func UseAlwaysQueryable added in v1.3.0

func UseAlwaysQueryable(q storage.Queryable) QueryableWithFilter

Wraps storage.Queryable into QueryableWithFilter, with no query filtering.

func UseBeforeTimestampQueryable added in v1.3.0

func UseBeforeTimestampQueryable(queryable storage.Queryable, ts time.Time) QueryableWithFilter

Returns QueryableWithFilter, that is used only if query starts before given timestamp. If timestamp is zero (time.IsZero), queryable is always used.

type SeriesWithChunks added in v0.7.0

type SeriesWithChunks interface {
	storage.Series

	// Returns all chunks with series data.
	Chunks() []chunk.Chunk
}

SeriesWithChunks extends storage.Series interface with direct access to Cortex chunks.

type TestConfig added in v1.11.0

type TestConfig struct {
	Cfg         Config
	Distributor Distributor
	Stores      []QueryableWithFilter
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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