Skip to content

Commit 8808b90

Browse files
authored
Add integration test to run Cortex with the getting started single binary config file (#2143)
* Add integration test to run Cortex with the getting started single binary config file Signed-off-by: Marco Pracucci <[email protected]> * Fixed circleci config and lint issues Signed-off-by: Marco Pracucci <[email protected]>
1 parent 952786f commit 8808b90

12 files changed

+110
-40
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ jobs:
141141
command: |
142142
export CORTEX_IMAGE_PREFIX="${IMAGE_PREFIX:-quay.io/cortexproject/}"
143143
export CORTEX_IMAGE="${CORTEX_IMAGE_PREFIX}cortex:${CIRCLE_TAG:-$(./tools/image-tag)}"
144+
export CORTEX_CHECKOUT_DIR="/home/circleci/.go_workspace/src/github.com/cortexproject/cortex"
144145
echo "Running integration tests with image: $CORTEX_IMAGE"
145146
go test -timeout 300s -v -count=1 ./integration
146147

docs/configuration/single-process-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ingester:
3737

3838
# We want to start immediately and flush on shutdown.
3939
join_after: 0
40+
min_ready_duration: 0s
4041
claim_on_rollout: false
4142
final_sleep: 0s
4243
num_tokens: 512

integration/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Supported environment variables
44

55
- `CORTEX_IMAGE`: Docker image used to run Cortex in integration tests (defaults to `quay.io/cortexproject/cortex:latest`)
6+
- `CORTEX_CHECKOUT_DIR`: The absolute path of the Cortex repository local checkout (defaults to `$GOPATH/src/github.com/cortexproject/cortex`)
67

78
## Owners
89

integration/backward_compatibility_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
5-
"os"
6-
"path/filepath"
74
"testing"
85
"time"
96

@@ -34,11 +31,7 @@ func TestBackwardCompatibilityWithChunksStorage(t *testing.T) {
3431
require.NoError(t, s.StartAndWaitReady(dynamo, consul))
3532

3633
// Start Cortex components (ingester running on previous version).
37-
require.NoError(t, ioutil.WriteFile(
38-
filepath.Join(s.SharedDir(), cortexSchemaConfigFile),
39-
[]byte(cortexSchemaConfigYaml),
40-
os.ModePerm),
41-
)
34+
require.NoError(t, writeFileToSharedDir(s, cortexSchemaConfigFile, []byte(cortexSchemaConfigYaml)))
4235
tableManager := e2ecortex.NewTableManager("table-manager", ChunksStorage, previousVersionImage)
4336
ingester1 := e2ecortex.NewIngester("ingester-1", consul.NetworkHTTPEndpoint(networkName), ChunksStorage, "")
4437
distributor := e2ecortex.NewDistributor("distributor", consul.NetworkHTTPEndpoint(networkName), ChunksStorage, "")

integration/configs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
)
1010

1111
const (
12-
cortexSchemaConfigFile = "chunks-storage-schema-dynamodb.yaml"
12+
cortexConfigFile = "config.yaml"
13+
cortexSchemaConfigFile = "schema.yaml"
1314
cortexSchemaConfigYaml = `configs:
1415
- from: "2019-03-20"
1516
store: aws-dynamo

integration/e2e/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ metric_b 1000
5555
defer srv.Close()
5656

5757
go func() {
58-
srv.ListenAndServe()
58+
_ = srv.ListenAndServe()
5959
}()
6060

6161
s := &HTTPService{
@@ -112,7 +112,7 @@ metric_b 1000
112112
defer srv.Close()
113113

114114
go func() {
115-
srv.ListenAndServe()
115+
_ = srv.ListenAndServe()
116116
}()
117117

118118
s := &HTTPService{

integration/e2ecortex/services.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,20 @@ func NewTableManager(name string, flags map[string]string, image string) *e2e.HT
103103
80,
104104
)
105105
}
106+
107+
func NewSingleBinary(name string, flags map[string]string, image string, httpPort int, otherPorts ...int) *e2e.HTTPService {
108+
if image == "" {
109+
image = GetDefaultImage()
110+
}
111+
112+
return e2e.NewHTTPService(
113+
name,
114+
image,
115+
e2e.NewCommandWithoutEntrypoint("cortex", e2e.BuildArgs(e2e.MergeFlags(map[string]string{
116+
"-log.level": "warn",
117+
}, flags))...),
118+
e2e.NewReadinessProbe(httpPort, "/ready", 204),
119+
httpPort,
120+
otherPorts...,
121+
)
122+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"path/filepath"
5+
"testing"
6+
"time"
7+
8+
"github.com/prometheus/common/model"
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/cortexproject/cortex/integration/e2e"
13+
"github.com/cortexproject/cortex/integration/e2ecortex"
14+
)
15+
16+
func TestGettingStartedSingleProcessConfig(t *testing.T) {
17+
s, err := e2e.NewScenario(networkName)
18+
require.NoError(t, err)
19+
defer s.Close()
20+
21+
// Start Cortex components.
22+
require.NoError(t, copyFileToSharedDir(s, "docs/configuration/single-process-config.yaml", cortexConfigFile))
23+
24+
// Start Cortex in single binary mode, reading the config from file.
25+
flags := map[string]string{
26+
"-config.file": filepath.Join(e2e.ContainerSharedDir, cortexConfigFile),
27+
}
28+
29+
cortex := e2ecortex.NewSingleBinary("cortex-1", flags, "", 9009)
30+
require.NoError(t, s.StartAndWaitReady(cortex))
31+
32+
c, err := e2ecortex.NewClient(cortex.Endpoint(9009), cortex.Endpoint(9009), "user-1")
33+
require.NoError(t, err)
34+
35+
// Push some series to Cortex.
36+
now := time.Now()
37+
series, expectedVector := generateSeries("series_1", now)
38+
39+
res, err := c.Push(series)
40+
require.NoError(t, err)
41+
require.Equal(t, 200, res.StatusCode)
42+
43+
// Query the series.
44+
result, err := c.Query("series_1", now)
45+
require.NoError(t, err)
46+
require.Equal(t, model.ValVector, result.Type())
47+
assert.Equal(t, expectedVector, result.(model.Vector))
48+
}

integration/ingester_flush_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package main
22

33
import (
44
"fmt"
5-
"io/ioutil"
6-
"os"
7-
"path/filepath"
85
"testing"
96
"time"
107

@@ -31,11 +28,7 @@ func TestIngesterFlushWithChunksStorage(t *testing.T) {
3128
require.NoError(t, s.StartAndWaitReady(dynamo, consul))
3229

3330
// Start Cortex components.
34-
require.NoError(t, ioutil.WriteFile(
35-
filepath.Join(s.SharedDir(), cortexSchemaConfigFile),
36-
[]byte(cortexSchemaConfigYaml),
37-
os.ModePerm),
38-
)
31+
require.NoError(t, writeFileToSharedDir(s, cortexSchemaConfigFile, []byte(cortexSchemaConfigYaml)))
3932

4033
tableManager := e2ecortex.NewTableManager("table-manager", ChunksStorage, "")
4134
ingester1 := e2ecortex.NewIngester("ingester-1", consul.NetworkHTTPEndpoint(networkName), mergeFlags(ChunksStorage, map[string]string{

integration/ingester_hand_over_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
5-
"os"
6-
"path/filepath"
74
"testing"
85
"time"
96

@@ -28,11 +25,8 @@ func TestIngesterHandOverWithChunksStorage(t *testing.T) {
2825
dynamo := e2edb.NewDynamoDB()
2926
require.NoError(t, s.StartAndWaitReady(dynamo))
3027

31-
require.NoError(t, ioutil.WriteFile(
32-
filepath.Join(s.SharedDir(), cortexSchemaConfigFile),
33-
[]byte(cortexSchemaConfigYaml),
34-
os.ModePerm),
35-
)
28+
require.NoError(t, writeFileToSharedDir(s, cortexSchemaConfigFile, []byte(cortexSchemaConfigYaml)))
29+
3630
tableManager := e2ecortex.NewTableManager("table-manager", ChunksStorage, "")
3731
require.NoError(t, s.StartAndWaitReady(tableManager))
3832

integration/integration_memberlist_single_binary_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
5-
"os"
6-
"path/filepath"
74
"testing"
85
"time"
96

@@ -25,11 +22,7 @@ func TestSingleBinaryWithMemberlist(t *testing.T) {
2522
// Look ma, no Consul!
2623
require.NoError(t, s.StartAndWaitReady(dynamo))
2724

28-
require.NoError(t, ioutil.WriteFile(
29-
filepath.Join(s.SharedDir(), cortexSchemaConfigFile),
30-
[]byte(cortexSchemaConfigYaml),
31-
os.ModePerm),
32-
)
25+
require.NoError(t, writeFileToSharedDir(s, cortexSchemaConfigFile, []byte(cortexSchemaConfigYaml)))
3326

3427
cortex1 := newSingleBinary("cortex-1", "")
3528
cortex2 := newSingleBinary("cortex-2", networkName+"-cortex-1:8000")
@@ -80,11 +73,10 @@ func newSingleBinary(name string, join string) *e2e.HTTPService {
8073
flags["-memberlist.join"] = join
8174
}
8275

83-
serv := e2e.NewHTTPService(
76+
serv := e2ecortex.NewSingleBinary(
8477
name,
85-
e2ecortex.GetDefaultImage(),
86-
e2e.NewCommandWithoutEntrypoint("cortex", buildArgs(mergeFlags(ChunksStorage, flags))...),
87-
e2e.NewReadinessProbe(80, "/ready", 204),
78+
mergeFlags(ChunksStorage, flags),
79+
"",
8880
80,
8981
8000,
9082
)

integration/util.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package main
22

33
import (
4+
"io/ioutil"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/pkg/errors"
9+
410
"github.com/cortexproject/cortex/integration/e2e"
511
e2edb "github.com/cortexproject/cortex/integration/e2e/db"
612
)
@@ -11,5 +17,28 @@ var (
1117
mergeFlags = e2e.MergeFlags
1218
newDynamoClient = e2edb.NewDynamoClient
1319
generateSeries = e2e.GenerateSeries
14-
buildArgs = e2e.BuildArgs
1520
)
21+
22+
func getCortexProjectDir() string {
23+
if dir := os.Getenv("CORTEX_CHECKOUT_DIR"); dir != "" {
24+
return dir
25+
}
26+
27+
return os.Getenv("GOPATH") + "/src/github.com/cortexproject/cortex"
28+
}
29+
30+
func writeFileToSharedDir(s *e2e.Scenario, dst string, content []byte) error {
31+
return ioutil.WriteFile(
32+
filepath.Join(s.SharedDir(), dst),
33+
content,
34+
os.ModePerm)
35+
}
36+
37+
func copyFileToSharedDir(s *e2e.Scenario, src, dst string) error {
38+
content, err := ioutil.ReadFile(filepath.Join(getCortexProjectDir(), src))
39+
if err != nil {
40+
return errors.Wrapf(err, "unable to read local file %s", src)
41+
}
42+
43+
return writeFileToSharedDir(s, dst, content)
44+
}

0 commit comments

Comments
 (0)