New makes a new Cortex.
(cfg Config)
| 356 | |
| 357 | // New makes a new Cortex. |
| 358 | func 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. |