github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/integration/e2ecortex/services.go (about) 1 package e2ecortex 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/cortexproject/cortex/integration/e2e" 8 ) 9 10 const ( 11 httpPort = 80 12 grpcPort = 9095 13 GossipPort = 9094 14 ) 15 16 // GetDefaultImage returns the Docker image to use to run Cortex. 17 func GetDefaultImage() string { 18 // Get the cortex image from the CORTEX_IMAGE env variable, 19 // falling back to "quay.io/cortexproject/cortex:latest" 20 if os.Getenv("CORTEX_IMAGE") != "" { 21 return os.Getenv("CORTEX_IMAGE") 22 } 23 24 return "quay.io/cortexproject/cortex:latest" 25 } 26 27 func NewDistributor(name string, consulAddress string, flags map[string]string, image string) *CortexService { 28 return NewDistributorWithConfigFile(name, consulAddress, "", flags, image) 29 } 30 31 func NewDistributorWithConfigFile(name, consulAddress, configFile string, flags map[string]string, image string) *CortexService { 32 if configFile != "" { 33 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 34 } 35 36 if image == "" { 37 image = GetDefaultImage() 38 } 39 40 return NewCortexService( 41 name, 42 image, 43 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 44 "-target": "distributor", 45 "-log.level": "warn", 46 "-auth.enabled": "true", 47 "-distributor.replication-factor": "1", 48 // Configure the ingesters ring backend 49 "-ring.store": "consul", 50 "-consul.hostname": consulAddress, 51 }, flags))...), 52 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 53 httpPort, 54 grpcPort, 55 ) 56 } 57 58 func NewQuerier(name string, consulAddress string, flags map[string]string, image string) *CortexService { 59 return NewQuerierWithConfigFile(name, consulAddress, "", flags, image) 60 } 61 62 func NewQuerierWithConfigFile(name, consulAddress, configFile string, flags map[string]string, image string) *CortexService { 63 if configFile != "" { 64 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 65 } 66 67 if image == "" { 68 image = GetDefaultImage() 69 } 70 71 return NewCortexService( 72 name, 73 image, 74 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 75 "-target": "querier", 76 "-log.level": "warn", 77 "-distributor.replication-factor": "1", 78 // Ingesters ring backend. 79 "-ring.store": "consul", 80 "-consul.hostname": consulAddress, 81 // Query-frontend worker. 82 "-querier.frontend-client.backoff-min-period": "100ms", 83 "-querier.frontend-client.backoff-max-period": "100ms", 84 "-querier.frontend-client.backoff-retries": "1", 85 "-querier.worker-parallelism": "1", 86 // Quickly detect query-frontend and query-scheduler when running it. 87 "-querier.dns-lookup-period": "1s", 88 // Store-gateway ring backend. 89 "-store-gateway.sharding-enabled": "true", 90 "-store-gateway.sharding-ring.store": "consul", 91 "-store-gateway.sharding-ring.consul.hostname": consulAddress, 92 "-store-gateway.sharding-ring.replication-factor": "1", 93 }, flags))...), 94 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 95 httpPort, 96 grpcPort, 97 ) 98 } 99 100 func NewStoreGateway(name string, consulAddress string, flags map[string]string, image string) *CortexService { 101 return NewStoreGatewayWithConfigFile(name, consulAddress, "", flags, image) 102 } 103 104 func NewStoreGatewayWithConfigFile(name, consulAddress, configFile string, flags map[string]string, image string) *CortexService { 105 if configFile != "" { 106 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 107 } 108 109 if image == "" { 110 image = GetDefaultImage() 111 } 112 113 return NewCortexService( 114 name, 115 image, 116 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 117 "-target": "store-gateway", 118 "-log.level": "warn", 119 // Store-gateway ring backend. 120 "-store-gateway.sharding-enabled": "true", 121 "-store-gateway.sharding-ring.store": "consul", 122 "-store-gateway.sharding-ring.consul.hostname": consulAddress, 123 "-store-gateway.sharding-ring.replication-factor": "1", 124 // Startup quickly. 125 "-store-gateway.sharding-ring.wait-stability-min-duration": "0", 126 "-store-gateway.sharding-ring.wait-stability-max-duration": "0", 127 }, flags))...), 128 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 129 httpPort, 130 grpcPort, 131 ) 132 } 133 134 func NewIngester(name string, consulAddress string, flags map[string]string, image string) *CortexService { 135 return NewIngesterWithConfigFile(name, consulAddress, "", flags, image) 136 } 137 138 func NewIngesterWithConfigFile(name, consulAddress, configFile string, flags map[string]string, image string) *CortexService { 139 if configFile != "" { 140 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 141 } 142 if image == "" { 143 image = GetDefaultImage() 144 } 145 146 return NewCortexService( 147 name, 148 image, 149 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 150 "-target": "ingester", 151 "-log.level": "warn", 152 "-ingester.final-sleep": "0s", 153 "-ingester.join-after": "0s", 154 "-ingester.min-ready-duration": "0s", 155 "-ingester.concurrent-flushes": "10", 156 "-ingester.max-transfer-retries": "10", 157 "-ingester.num-tokens": "512", 158 // Configure the ingesters ring backend 159 "-ring.store": "consul", 160 "-consul.hostname": consulAddress, 161 }, flags))...), 162 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 163 httpPort, 164 grpcPort, 165 ) 166 } 167 168 func NewTableManager(name string, flags map[string]string, image string) *CortexService { 169 return NewTableManagerWithConfigFile(name, "", flags, image) 170 } 171 172 func NewTableManagerWithConfigFile(name, configFile string, flags map[string]string, image string) *CortexService { 173 if configFile != "" { 174 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 175 } 176 177 if image == "" { 178 image = GetDefaultImage() 179 } 180 181 return NewCortexService( 182 name, 183 image, 184 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 185 "-target": "table-manager", 186 "-log.level": "warn", 187 }, flags))...), 188 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 189 httpPort, 190 grpcPort, 191 ) 192 } 193 194 func NewQueryFrontend(name string, flags map[string]string, image string) *CortexService { 195 return NewQueryFrontendWithConfigFile(name, "", flags, image) 196 } 197 198 func NewQueryFrontendWithConfigFile(name, configFile string, flags map[string]string, image string) *CortexService { 199 if configFile != "" { 200 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 201 } 202 203 if image == "" { 204 image = GetDefaultImage() 205 } 206 207 return NewCortexService( 208 name, 209 image, 210 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 211 "-target": "query-frontend", 212 "-log.level": "warn", 213 // Quickly detect query-scheduler when running it. 214 "-frontend.scheduler-dns-lookup-period": "1s", 215 }, flags))...), 216 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 217 httpPort, 218 grpcPort, 219 ) 220 } 221 222 func NewQueryScheduler(name string, flags map[string]string, image string) *CortexService { 223 return NewQuerySchedulerWithConfigFile(name, "", flags, image) 224 } 225 226 func NewQuerySchedulerWithConfigFile(name, configFile string, flags map[string]string, image string) *CortexService { 227 if configFile != "" { 228 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 229 } 230 231 if image == "" { 232 image = GetDefaultImage() 233 } 234 235 return NewCortexService( 236 name, 237 image, 238 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 239 "-target": "query-scheduler", 240 "-log.level": "warn", 241 }, flags))...), 242 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 243 httpPort, 244 grpcPort, 245 ) 246 } 247 248 func NewCompactor(name string, consulAddress string, flags map[string]string, image string) *CortexService { 249 return NewCompactorWithConfigFile(name, consulAddress, "", flags, image) 250 } 251 252 func NewCompactorWithConfigFile(name, consulAddress, configFile string, flags map[string]string, image string) *CortexService { 253 if configFile != "" { 254 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 255 } 256 257 if image == "" { 258 image = GetDefaultImage() 259 } 260 261 return NewCortexService( 262 name, 263 image, 264 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 265 "-target": "compactor", 266 "-log.level": "warn", 267 // Store-gateway ring backend. 268 "-compactor.sharding-enabled": "true", 269 "-compactor.ring.store": "consul", 270 "-compactor.ring.consul.hostname": consulAddress, 271 // Startup quickly. 272 "-compactor.ring.wait-stability-min-duration": "0", 273 "-compactor.ring.wait-stability-max-duration": "0", 274 }, flags))...), 275 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 276 httpPort, 277 grpcPort, 278 ) 279 } 280 281 func NewSingleBinary(name string, flags map[string]string, image string, otherPorts ...int) *CortexService { 282 if image == "" { 283 image = GetDefaultImage() 284 } 285 286 return NewCortexService( 287 name, 288 image, 289 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 290 "-target": "all", 291 "-log.level": "warn", 292 "-auth.enabled": "true", 293 // Query-frontend worker. 294 "-querier.frontend-client.backoff-min-period": "100ms", 295 "-querier.frontend-client.backoff-max-period": "100ms", 296 "-querier.frontend-client.backoff-retries": "1", 297 "-querier.worker-parallelism": "1", 298 // Distributor. 299 "-distributor.replication-factor": "1", 300 // Ingester. 301 "-ingester.final-sleep": "0s", 302 "-ingester.join-after": "0s", 303 "-ingester.min-ready-duration": "0s", 304 "-ingester.concurrent-flushes": "10", 305 "-ingester.max-transfer-retries": "10", 306 "-ingester.num-tokens": "512", 307 // Startup quickly. 308 "-store-gateway.sharding-ring.wait-stability-min-duration": "0", 309 "-store-gateway.sharding-ring.wait-stability-max-duration": "0", 310 }, flags))...), 311 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 312 httpPort, 313 grpcPort, 314 otherPorts..., 315 ) 316 } 317 318 func NewSingleBinaryWithConfigFile(name string, configFile string, flags map[string]string, image string, httpPort, grpcPort int, otherPorts ...int) *CortexService { 319 if image == "" { 320 image = GetDefaultImage() 321 } 322 323 return NewCortexService( 324 name, 325 image, 326 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 327 // Do not pass any extra default flags because the config should be drive by the config file. 328 "-target": "all", 329 "-log.level": "warn", 330 "-config.file": filepath.Join(e2e.ContainerSharedDir, configFile), 331 }, flags))...), 332 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 333 httpPort, 334 grpcPort, 335 otherPorts..., 336 ) 337 } 338 339 func NewAlertmanager(name string, flags map[string]string, image string) *CortexService { 340 if image == "" { 341 image = GetDefaultImage() 342 } 343 344 return NewCortexService( 345 name, 346 image, 347 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 348 "-target": "alertmanager", 349 "-log.level": "warn", 350 "-experimental.alertmanager.enable-api": "true", 351 }, flags))...), 352 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 353 httpPort, 354 grpcPort, 355 GossipPort, 356 ) 357 } 358 359 func NewAlertmanagerWithTLS(name string, flags map[string]string, image string) *CortexService { 360 if image == "" { 361 image = GetDefaultImage() 362 } 363 364 return NewCortexService( 365 name, 366 image, 367 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 368 "-target": "alertmanager", 369 "-log.level": "warn", 370 "-experimental.alertmanager.enable-api": "true", 371 }, flags))...), 372 e2e.NewTCPReadinessProbe(httpPort), 373 httpPort, 374 grpcPort, 375 GossipPort, 376 ) 377 } 378 379 func NewRuler(name string, consulAddress string, flags map[string]string, image string) *CortexService { 380 if image == "" { 381 image = GetDefaultImage() 382 } 383 384 return NewCortexService( 385 name, 386 image, 387 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 388 "-target": "ruler", 389 "-log.level": "warn", 390 // Configure the ingesters ring backend 391 "-ring.store": "consul", 392 "-consul.hostname": consulAddress, 393 }, flags))...), 394 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 395 httpPort, 396 grpcPort, 397 ) 398 } 399 400 func NewPurger(name string, flags map[string]string, image string) *CortexService { 401 return NewPurgerWithConfigFile(name, "", flags, image) 402 } 403 404 func NewPurgerWithConfigFile(name, configFile string, flags map[string]string, image string) *CortexService { 405 if configFile != "" { 406 flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile) 407 } 408 409 if image == "" { 410 image = GetDefaultImage() 411 } 412 413 return NewCortexService( 414 name, 415 image, 416 e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{ 417 "-target": "purger", 418 "-log.level": "warn", 419 "-purger.object-store-type": "filesystem", 420 "-local.chunk-directory": e2e.ContainerSharedDir, 421 }, flags))...), 422 e2e.NewHTTPReadinessProbe(httpPort, "/ready", 200, 299), 423 httpPort, 424 grpcPort, 425 ) 426 }