@@ -13,6 +13,13 @@ const (
1313 GossipPort = 9094
1414)
1515
16+ type RingStore string
17+
18+ const (
19+ RingStoreConsul RingStore = "consul"
20+ RingStoreEtcd RingStore = "etcd"
21+ )
22+
1623// GetDefaultImage returns the Docker image to use to run Cortex.
1724func GetDefaultImage () string {
1825 // Get the cortex image from the CORTEX_IMAGE env variable,
@@ -24,15 +31,23 @@ func GetDefaultImage() string {
2431 return "quay.io/cortexproject/cortex:latest"
2532}
2633
27- func NewDistributor (name string , consulAddress string , flags map [string ]string , image string ) * CortexService {
28- return NewDistributorWithConfigFile (name , consulAddress , "" , flags , image )
34+ func NewDistributor (name string , store RingStore , address string , flags map [string ]string , image string ) * CortexService {
35+ return NewDistributorWithConfigFile (name , store , address , "" , flags , image )
2936}
3037
31- func NewDistributorWithConfigFile (name , consulAddress , configFile string , flags map [string ]string , image string ) * CortexService {
38+ func NewDistributorWithConfigFile (name string , store RingStore , address , configFile string , flags map [string ]string , image string ) * CortexService {
3239 if configFile != "" {
3340 flags ["-config.file" ] = filepath .Join (e2e .ContainerSharedDir , configFile )
3441 }
3542
43+ // Configure the ingesters ring backend
44+ flags ["-ring.store" ] = string (store )
45+ if store == RingStoreConsul {
46+ flags ["-consul.hostname" ] = address
47+ } else if store == RingStoreEtcd {
48+ flags ["-etcd.endpoints" ] = address
49+ }
50+
3651 if image == "" {
3752 image = GetDefaultImage ()
3853 }
@@ -45,25 +60,39 @@ func NewDistributorWithConfigFile(name, consulAddress, configFile string, flags
4560 "-log.level" : "warn" ,
4661 "-auth.enabled" : "true" ,
4762 "-distributor.replication-factor" : "1" ,
48- // Configure the ingesters ring backend
49- "-ring.store" : "consul" ,
50- "-consul.hostname" : consulAddress ,
5163 }, flags ))... ),
5264 e2e .NewHTTPReadinessProbe (httpPort , "/ready" , 200 , 299 ),
5365 httpPort ,
5466 grpcPort ,
5567 )
5668}
5769
58- func NewQuerier (name string , consulAddress string , flags map [string ]string , image string ) * CortexService {
59- return NewQuerierWithConfigFile (name , consulAddress , "" , flags , image )
70+ func NewQuerier (name string , store RingStore , address string , flags map [string ]string , image string ) * CortexService {
71+ return NewQuerierWithConfigFile (name , store , address , "" , flags , image )
6072}
6173
62- func NewQuerierWithConfigFile (name , consulAddress , configFile string , flags map [string ]string , image string ) * CortexService {
74+ func NewQuerierWithConfigFile (name string , store RingStore , address , configFile string , flags map [string ]string , image string ) * CortexService {
6375 if configFile != "" {
6476 flags ["-config.file" ] = filepath .Join (e2e .ContainerSharedDir , configFile )
6577 }
6678
79+ // Configure the ingesters ring backend and the store-gateway ring backend.
80+ ringBackendFlags := map [string ]string {
81+ "-ring.store" : string (store ),
82+ "-store-gateway.sharding-ring.store" : string (store ),
83+ }
84+
85+ if store == RingStoreConsul {
86+ ringBackendFlags ["-consul.hostname" ] = address
87+ ringBackendFlags ["-store-gateway.sharding-ring.consul.hostname" ] = address
88+ } else if store == RingStoreEtcd {
89+ ringBackendFlags ["-etcd.endpoints" ] = address
90+ ringBackendFlags ["-store-gateway.sharding-ring.etcd.endpoints" ] = address
91+ }
92+
93+ // For backward compatibility
94+ flags = e2e .MergeFlagsWithoutRemovingEmpty (ringBackendFlags , flags )
95+
6796 if image == "" {
6897 image = GetDefaultImage ()
6998 }
@@ -75,9 +104,6 @@ func NewQuerierWithConfigFile(name, consulAddress, configFile string, flags map[
75104 "-target" : "querier" ,
76105 "-log.level" : "warn" ,
77106 "-distributor.replication-factor" : "1" ,
78- // Ingesters ring backend.
79- "-ring.store" : "consul" ,
80- "-consul.hostname" : consulAddress ,
81107 // Query-frontend worker.
82108 "-querier.frontend-client.backoff-min-period" : "100ms" ,
83109 "-querier.frontend-client.backoff-max-period" : "100ms" ,
@@ -87,8 +113,6 @@ func NewQuerierWithConfigFile(name, consulAddress, configFile string, flags map[
87113 "-querier.dns-lookup-period" : "1s" ,
88114 // Store-gateway ring backend.
89115 "-store-gateway.sharding-enabled" : "true" ,
90- "-store-gateway.sharding-ring.store" : "consul" ,
91- "-store-gateway.sharding-ring.consul.hostname" : consulAddress ,
92116 "-store-gateway.sharding-ring.replication-factor" : "1" ,
93117 }, flags ))... ),
94118 e2e .NewHTTPReadinessProbe (httpPort , "/ready" , 200 , 299 ),
@@ -97,15 +121,23 @@ func NewQuerierWithConfigFile(name, consulAddress, configFile string, flags map[
97121 )
98122}
99123
100- func NewStoreGateway (name string , consulAddress string , flags map [string ]string , image string ) * CortexService {
101- return NewStoreGatewayWithConfigFile (name , consulAddress , "" , flags , image )
124+ func NewStoreGateway (name string , store RingStore , address string , flags map [string ]string , image string ) * CortexService {
125+ return NewStoreGatewayWithConfigFile (name , store , address , "" , flags , image )
102126}
103127
104- func NewStoreGatewayWithConfigFile (name , consulAddress , configFile string , flags map [string ]string , image string ) * CortexService {
128+ func NewStoreGatewayWithConfigFile (name string , store RingStore , address string , configFile string , flags map [string ]string , image string ) * CortexService {
105129 if configFile != "" {
106130 flags ["-config.file" ] = filepath .Join (e2e .ContainerSharedDir , configFile )
107131 }
108132
133+ if store == RingStoreConsul {
134+ flags ["-consul.hostname" ] = address
135+ flags ["-store-gateway.sharding-ring.consul.hostname" ] = address
136+ } else if store == RingStoreEtcd {
137+ flags ["-etcd.endpoints" ] = address
138+ flags ["-store-gateway.sharding-ring.etcd.endpoints" ] = address
139+ }
140+
109141 if image == "" {
110142 image = GetDefaultImage ()
111143 }
@@ -118,8 +150,7 @@ func NewStoreGatewayWithConfigFile(name, consulAddress, configFile string, flags
118150 "-log.level" : "warn" ,
119151 // Store-gateway ring backend.
120152 "-store-gateway.sharding-enabled" : "true" ,
121- "-store-gateway.sharding-ring.store" : "consul" ,
122- "-store-gateway.sharding-ring.consul.hostname" : consulAddress ,
153+ "-store-gateway.sharding-ring.store" : string (store ),
123154 "-store-gateway.sharding-ring.replication-factor" : "1" ,
124155 // Startup quickly.
125156 "-store-gateway.sharding-ring.wait-stability-min-duration" : "0" ,
@@ -131,14 +162,23 @@ func NewStoreGatewayWithConfigFile(name, consulAddress, configFile string, flags
131162 )
132163}
133164
134- func NewIngester (name string , consulAddress string , flags map [string ]string , image string ) * CortexService {
135- return NewIngesterWithConfigFile (name , consulAddress , "" , flags , image )
165+ func NewIngester (name string , store RingStore , address string , flags map [string ]string , image string ) * CortexService {
166+ return NewIngesterWithConfigFile (name , store , address , "" , flags , image )
136167}
137168
138- func NewIngesterWithConfigFile (name , consulAddress , configFile string , flags map [string ]string , image string ) * CortexService {
169+ func NewIngesterWithConfigFile (name string , store RingStore , address , configFile string , flags map [string ]string , image string ) * CortexService {
139170 if configFile != "" {
140171 flags ["-config.file" ] = filepath .Join (e2e .ContainerSharedDir , configFile )
141172 }
173+
174+ // Configure the ingesters ring backend
175+ flags ["-ring.store" ] = string (store )
176+ if store == RingStoreConsul {
177+ flags ["-consul.hostname" ] = address
178+ } else if store == RingStoreEtcd {
179+ flags ["-etcd.endpoints" ] = address
180+ }
181+
142182 if image == "" {
143183 image = GetDefaultImage ()
144184 }
@@ -155,9 +195,6 @@ func NewIngesterWithConfigFile(name, consulAddress, configFile string, flags map
155195 "-ingester.concurrent-flushes" : "10" ,
156196 "-ingester.max-transfer-retries" : "10" ,
157197 "-ingester.num-tokens" : "512" ,
158- // Configure the ingesters ring backend
159- "-ring.store" : "consul" ,
160- "-consul.hostname" : consulAddress ,
161198 }, flags ))... ),
162199 e2e .NewHTTPReadinessProbe (httpPort , "/ready" , 200 , 299 ),
163200 httpPort ,
0 commit comments