Skip to content

Commit 9349981

Browse files
authored
Merge pull request #1271 from cortexproject/integration-tests
Integration test running ingesters
2 parents 5dc04ff + 8fc55c3 commit 9349981

File tree

8 files changed

+168
-35
lines changed

8 files changed

+168
-35
lines changed

.circleci/config.yml

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2
1+
version: 2.1
22

33
# https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/
44
defaults: &defaults
@@ -20,6 +20,8 @@ workflows:
2020
tags:
2121
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
2222
- integration:
23+
requires:
24+
- build
2325
filters:
2426
tags:
2527
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
@@ -39,6 +41,18 @@ workflows:
3941
tags:
4042
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
4143

44+
commands:
45+
install-docker:
46+
steps:
47+
- run:
48+
name: Install Docker client
49+
command: |
50+
set -x
51+
VER="17.03.0-ce"
52+
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
53+
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
54+
mv /tmp/docker/* /usr/bin
55+
4256
jobs:
4357
lint:
4458
<<: *defaults
@@ -63,33 +77,37 @@ jobs:
6377
command: make BUILD_IN_CONTAINER=false test
6478

6579
integration:
66-
docker:
67-
- image: cortexproject/build-image:master-561033f49
68-
- image: circleci/postgres:9.6.2-alpine
69-
environment:
70-
POSTGRES_DB: configs_test
80+
machine:
81+
image: ubuntu-1604:201903-01
7182

72-
working_directory: /go/src/github.com/cortexproject/cortex
83+
working_directory: ~/src/github.com/cortexproject/cortex
7384
steps:
7485
- checkout
86+
- restore_cache:
87+
key: v1-cortex-{{ .Branch }}-{{ .Revision }}
7588
- run:
7689
name: Integration Test
77-
command: MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations make BUILD_IN_CONTAINER=false configs-integration-test
90+
command: |
91+
touch build-image/.uptodate
92+
MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations make BUILD_IMAGE=cortexproject/build-image:1370-pin-protoc-7ae297930 configs-integration-test
93+
- run:
94+
name: Load Images
95+
command: ln -s /tmp/images ./images; make BUILD_IN_CONTAINER=false load-images
96+
- run:
97+
name: Ingester hand-over test
98+
command: ./integration-tests/test-handover.sh
99+
- run:
100+
name: Ingester flush test
101+
command: |
102+
./integration-tests/stop-components.sh
103+
./integration-tests/test-flush.sh
78104
79105
build:
80106
<<: *defaults
81107
steps:
82108
- checkout
83109
- setup_remote_docker
84-
85-
- run:
86-
name: Install Docker client
87-
command: |
88-
set -x
89-
VER="17.03.0-ce"
90-
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
91-
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
92-
mv /tmp/docker/* /usr/bin
110+
- install-docker
93111

94112
- run:
95113
name: Build
@@ -108,34 +126,29 @@ jobs:
108126

109127
- run:
110128
name: Save Images
111-
command: make BUILD_IN_CONTAINER=false save-images
129+
command: |
130+
mkdir /tmp/images
131+
ln -s /tmp/images ./images
132+
make BUILD_IN_CONTAINER=false save-images
112133
113134
- save_cache:
114135
key: v1-cortex-{{ .Branch }}-{{ .Revision }}
115136
paths:
116-
- images/
137+
- /tmp/images/
117138

118139
deploy:
119140
<<: *defaults
120141
steps:
121142
- checkout
122143
- setup_remote_docker
123-
124-
- run:
125-
name: Install Docker client
126-
command: |
127-
set -x
128-
VER="17.03.0-ce"
129-
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
130-
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
131-
mv /tmp/docker/* /usr/bin
144+
- install-docker
132145

133146
- restore_cache:
134147
key: v1-cortex-{{ .Branch }}-{{ .Revision }}
135148

136149
- run:
137150
name: Load Images
138-
command: make BUILD_IN_CONTAINER=false load-images
151+
command: ln -s /tmp/images ./images; make BUILD_IN_CONTAINER=false load-images
139152

140153
- run:
141154
name: Deploy

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ build-image/$(UPTODATE): build-image/*
6464
# All the boiler plate for building golang follows:
6565
SUDO := $(shell docker info >/dev/null 2>&1 || echo "sudo -E")
6666
BUILD_IN_CONTAINER := true
67+
BUILD_IMAGE ?= $(IMAGE_PREFIX)build-image
6768
# RM is parameterized to allow CircleCI to run builds, as it
6869
# currently disallows `docker run --rm`. This value is overridden
6970
# in circle.yml
@@ -93,23 +94,23 @@ exes $(EXES) protos $(PROTO_GOS) lint test shell mod-check check-protos: build-i
9394
-v $(shell pwd)/.cache:/go/cache \
9495
-v $(shell pwd)/.pkg:/go/pkg \
9596
-v $(shell pwd):/go/src/github.com/cortexproject/cortex \
96-
$(IMAGE_PREFIX)build-image $@;
97+
$(BUILD_IMAGE) $@;
9798

9899
configs-integration-test: build-image/$(UPTODATE)
99100
@mkdir -p $(shell pwd)/.pkg
100101
@mkdir -p $(shell pwd)/.cache
101-
DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=configs_test' postgres:9.6)"; \
102-
@echo
103-
@echo ">>>> Entering build container: $@"
104-
@$(SUDO) docker run $(RM) $(TTY) -i \
102+
@DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=configs_test' postgres:9.6)"; \
103+
echo ; \
104+
echo ">>>> Entering build container: $@"; \
105+
$(SUDO) docker run $(RM) $(TTY) -i \
105106
-v $(shell pwd)/.cache:/go/cache \
106107
-v $(shell pwd)/.pkg:/go/pkg \
107108
-v $(shell pwd):/go/src/github.com/cortexproject/cortex \
108109
-v $(shell pwd)/cmd/cortex/migrations:/migrations \
109110
--workdir /go/src/github.com/cortexproject/cortex \
110111
--link "$$DB_CONTAINER":configs-db.cortex.local \
111112
-e DB_ADDR=configs-db.cortex.local \
112-
$(IMAGE_PREFIX)build-image $@; \
113+
$(BUILD_IMAGE) $@; \
113114
status=$$?; \
114115
test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \
115116
exit $$status

integration-tests/common.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# file intended to be sourced by other shell scripts
2+
3+
TEST_DIR="$( cd "$(dirname "$0")" ; pwd -P )"
4+
5+
IMAGE_TAG=$($TEST_DIR/../tools/image-tag)
6+
7+
COMMON_ARGS="-consul.hostname=consul:8500"
8+
STORAGE_ARGS="-config-yaml=/tests/schema1.yaml -dynamodb.url=dynamodb://u:[email protected].:8000"
9+
INGESTER_ARGS="$COMMON_ARGS $STORAGE_ARGS -ingester.num-tokens=4 -ingester.min-ready-duration=1s --ingester.final-sleep=0s -ingester.concurrent-flushes=5"
10+
RUN_ARGS="--net=cortex -v $TEST_DIR:/tests"
11+
AVALANCHE_IMAGE=quay.io/freshtracks.io/avalanche:master-2019-07-28-47b00e3
12+
13+
# Execute command $1 repeatedly until it returns true; description in $2, optional repeat limit in $3
14+
wait_for() {
15+
reps=${3:-10}
16+
for i in $(seq 1 $reps); do
17+
echo "Waiting for $2"
18+
if $1; then
19+
return
20+
fi
21+
sleep 1
22+
done
23+
echo "Timed out waiting for $2" >&2
24+
exit 1
25+
}
26+
27+
container_ip() {
28+
docker inspect -f "{{.NetworkSettings.Networks.cortex.IPAddress}}" $@
29+
}

integration-tests/schema1.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
configs:
2+
- from: "2019-03-20"
3+
store: aws-dynamo
4+
schema: v9
5+
index:
6+
prefix: cortex_
7+
period: 168h0m0s
8+
chunks:
9+
prefix: cortex_chunks_
10+
period: 168h0m0s

integration-tests/start-components.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
THIS_DIR=$(dirname "$0")
6+
. "$THIS_DIR/common.sh"
7+
8+
docker network create cortex
9+
10+
docker run $RUN_ARGS -d --name=consul --hostname=consul consul:0.9 agent -ui -server -client=0.0.0.0 -bootstrap
11+
docker run $RUN_ARGS -d --name=dynamodb --hostname=dynamodb amazon/dynamodb-local:1.11.477 -jar DynamoDBLocal.jar -inMemory -sharedDb
12+
docker run $RUN_ARGS -d --name=distributor --hostname=distributor -p 8080:80 quay.io/cortexproject/cortex:$IMAGE_TAG -target=distributor $COMMON_ARGS -distributor.replication-factor=1

integration-tests/stop-components.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
docker rm -f tm i2 i1 distributor dynamodb consul || true
6+
docker network rm cortex || true

integration-tests/test-flush.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
. "$(dirname "$0")/common.sh"
6+
7+
"$(dirname "$0")/start-components.sh"
8+
9+
# TODO: wait for DynamoDB ready
10+
sleep 5
11+
echo Start table-manager
12+
docker run $RUN_ARGS -d --name=tm --hostname=tm --restart=always quay.io/cortexproject/cortex:$IMAGE_TAG -target=table-manager $STORAGE_ARGS -table-manager.retention-period=168h
13+
14+
echo Start ingester
15+
docker run $RUN_ARGS -d --name=i1 --hostname=i1 quay.io/cortexproject/cortex:$IMAGE_TAG -target=ingester $INGESTER_ARGS
16+
17+
sleep 5
18+
I1_ADDR=$(container_ip i1)
19+
wait_for "curl -s -f -m 3 $I1_ADDR/ready" "ingester ready"
20+
21+
has_tokens_owned() {
22+
curl -s -f -m 3 $1/metrics | grep 'cortex_ring_tokens_owned' >/dev/null
23+
}
24+
DIST_ADDR=$(container_ip distributor)
25+
wait_for "has_tokens_owned $DIST_ADDR" "distributor to see ingester in ring"
26+
27+
docker run $RUN_ARGS --rm $AVALANCHE_IMAGE --metric-count=2 --label-count=2 --series-count=2 --remote-requests-count=1 --remote-url=http://distributor/api/prom/push
28+
29+
echo Stop ingester so it should flush
30+
docker stop -t=60 i1 # allow 1 minute for flush to complete

integration-tests/test-handover.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
. "$(dirname "$0")/common.sh"
6+
7+
"$(dirname "$0")/start-components.sh"
8+
9+
# Note we haven't created any tables in the DB yet - we aren't going to run long enough to flush anything
10+
11+
echo Start first ingester
12+
docker run $RUN_ARGS -d --name=i1 --hostname=i1 quay.io/cortexproject/cortex:$IMAGE_TAG -target=ingester $INGESTER_ARGS -ingester.claim-on-rollout=true
13+
14+
I1_ADDR=$(container_ip i1)
15+
wait_for "curl -s -f -m 3 $I1_ADDR/ready" "ingester ready"
16+
17+
has_tokens_owned() {
18+
curl -s -f -m 3 $1/metrics | grep -q 'cortex_ring_tokens_owned'
19+
}
20+
DIST_ADDR=$(container_ip distributor)
21+
wait_for "has_tokens_owned $DIST_ADDR" "distributor to see ingester in ring"
22+
23+
docker run $RUN_ARGS --rm $AVALANCHE_IMAGE --metric-count=2 --label-count=2 --series-count=2 --remote-requests-count=1 --remote-url=http://distributor/api/prom/push
24+
25+
echo Start second ingester, waiting for first
26+
docker run $RUN_ARGS -d --name=i2 --hostname=i2 quay.io/cortexproject/cortex:$IMAGE_TAG -target=ingester $INGESTER_ARGS -ingester.join-after=300s -ingester.claim-on-rollout=true
27+
28+
echo Stop first ingester so it should hand over
29+
docker stop i1
30+
31+
I2_ADDR=$(container_ip i2)
32+
wait_for "curl -s -f -m 3 $I2_ADDR/ready" "ingester ready"

0 commit comments

Comments
 (0)