MCPcopy Index your code
hub / github.com/cortexproject/cortex / New

Function New

pkg/querier/querier.go:220–267  ·  view source on GitHub ↗

New builds a queryable and promql engine.

(cfg Config, limits *validation.Overrides, distributor Distributor, stores []QueryableWithFilter, reg prometheus.Registerer, logger log.Logger, isPartialDataEnabled partialdata.IsCfgEnabledFunc)

Source from the content-addressed store, hash-verified

218
219// New builds a queryable and promql engine.
220func New(cfg Config, limits *validation.Overrides, distributor Distributor, stores []QueryableWithFilter, reg prometheus.Registerer, logger log.Logger, isPartialDataEnabled partialdata.IsCfgEnabledFunc) (storage.SampleAndChunkQueryable, storage.ExemplarQueryable, engine.QueryEngine) {
221 iteratorFunc := getChunksIteratorFunction(cfg)
222
223 distributorQueryable := newDistributorQueryable(distributor, cfg.IngesterMetadataStreaming, cfg.IngesterLabelNamesWithMatchers, iteratorFunc, cfg.QueryIngestersWithin, isPartialDataEnabled, cfg.IngesterQueryMaxAttempts)
224
225 ns := make([]QueryableWithFilter, len(stores))
226 for ix, s := range stores {
227 ns[ix] = storeQueryable{
228 QueryableWithFilter: s,
229 QueryStoreAfter: cfg.QueryStoreAfter,
230 }
231 }
232 queryable := NewQueryable(distributorQueryable, ns, cfg, limits)
233 exemplarQueryable := newDistributorExemplarQueryable(distributor)
234
235 lazyQueryable := storage.QueryableFunc(func(mint int64, maxt int64) (storage.Querier, error) {
236 querier, err := queryable.Querier(mint, maxt)
237 if err != nil {
238 return nil, err
239 }
240 return lazyquery.NewLazyQuerier(querier), nil
241 })
242
243 // Emit max_concurrent config as a metric.
244 maxConcurrentMetric := promauto.With(reg).NewGauge(prometheus.GaugeOpts{
245 Namespace: "cortex",
246 Name: "max_concurrent_queries",
247 Help: "The maximum number of concurrent queries.",
248 })
249 maxConcurrentMetric.Set(float64(cfg.MaxConcurrent))
250
251 opts := promql.EngineOpts{
252 Logger: util_log.GoKitLogToSlog(logger),
253 Reg: reg,
254 ActiveQueryTracker: createActiveQueryTracker(cfg, logger),
255 MaxSamples: cfg.MaxSamples,
256 Timeout: cfg.Timeout,
257 LookbackDelta: cfg.LookbackDelta,
258 EnablePerStepStats: cfg.EnablePerStepStats,
259 EnableAtModifier: true,
260 EnableNegativeOffset: true,
261 NoStepSubqueryIntervalFn: func(int64) int64 {
262 return cfg.DefaultEvaluationInterval.Milliseconds()
263 },
264 }
265 queryEngine := engine.New(opts, cfg.ThanosEngine, reg)
266 return NewSampleAndChunkQueryable(lazyQueryable), exemplarQueryable, queryEngine
267}
268
269// NewSampleAndChunkQueryable creates a SampleAndChunkQueryable from a
270// Queryable with a ChunkQueryable stub, that errors once it gets called.

Calls 10

NewLazyQuerierFunction · 0.92
NewFunction · 0.92
newDistributorQueryableFunction · 0.85
NewQueryableFunction · 0.70
createActiveQueryTrackerFunction · 0.70
SetMethod · 0.65
QuerierMethod · 0.45