MCPcopy Create free account
hub / github.com/cortexproject/cortex / New

Function New

pkg/cortex/cortex.go:358–399  ·  view source on GitHub ↗

New makes a new Cortex.

(cfg Config)

Source from the content-addressed store, hash-verified

356
357// New makes a new Cortex.
358func New(cfg Config) (*Cortex, error) {
359 if cfg.PrintConfig {
360 if err := yaml.NewEncoder(os.Stdout).Encode(&cfg); err != nil {
361 fmt.Println("Error encoding config:", err)
362 }
363 os.Exit(0)
364 }
365
366 // Swap out the default resolver to support multiple tenant IDs separated by a '|'
367 if cfg.TenantFederation.Enabled {
368 users.WithDefaultResolver(users.NewMultiResolver())
369 }
370
371 cfg.API.HTTPAuthMiddleware = fakeauth.SetupAuthMiddleware(&cfg.Server, cfg.AuthEnabled,
372 // Also don't check auth for these gRPC methods, since single call is used for multiple users (or no user like health check).
373 []string{
374 "/grpc.health.v1.Health/Check",
375 "/frontend.Frontend/Process",
376 "/frontend.Frontend/NotifyClientShutdown",
377 "/schedulerpb.SchedulerForFrontend/FrontendLoop",
378 "/schedulerpb.SchedulerForQuerier/QuerierLoop",
379 "/schedulerpb.SchedulerForQuerier/NotifyQuerierShutdown",
380 })
381
382 cortex := &Cortex{
383 Cfg: cfg,
384 }
385
386 // set name validation scheme
387 model.NameValidationScheme = cfg.NameValidationScheme //nolint:staticcheck
388
389 cortex.setupThanosTracing()
390 cortex.setupGRPCHeaderForwarding()
391 cortex.setupRequestSigning()
392
393 if err := cortex.setupModuleManager(); err != nil {
394 return nil, err
395 }
396
397 cortex.setupPromQLFunctions()
398 return cortex, nil
399}
400
401// setupThanosTracing appends a gRPC middleware used to inject our tracer into the custom
402// context used by Thanos, in order to get Thanos spans correctly attached to our traces.

Callers 3

mainFunction · 0.92
TestCortexFunction · 0.70
TestGrpcAuthMiddlewareFunction · 0.70

Calls 9

setupThanosTracingMethod · 0.95
setupRequestSigningMethod · 0.95
setupModuleManagerMethod · 0.95
setupPromQLFunctionsMethod · 0.95
WithDefaultResolverFunction · 0.92
NewMultiResolverFunction · 0.92
SetupAuthMiddlewareFunction · 0.92
EncodeMethod · 0.65

Tested by 2

TestCortexFunction · 0.56
TestGrpcAuthMiddlewareFunction · 0.56