Skip to content

Commit d22fb88

Browse files
authored
Refactor end-to-end tests to reduce duplication (#758)
* Externalize common scripts in e2e tests * Fix script directory * Fix script path for e2e-batch test * Externalize redis-cluster e2e test scripts * Add wait-for-it to Kafka and Zookeper initialization
1 parent 0ec49cd commit d22fb88

File tree

4 files changed

+180
-527
lines changed

4 files changed

+180
-527
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
3+
# Get Feast project repository root and scripts directory
4+
export PROJECT_ROOT_DIR=$(git rev-parse --show-toplevel)
5+
export SCRIPTS_DIR=${PROJECT_ROOT_DIR}/infra/scripts
6+
7+
install_test_tools() {
8+
apt-get -qq update
9+
apt-get -y install wget netcat kafkacat build-essential
10+
}
11+
12+
install_gcloud_sdk() {
13+
print_banner "Installing Google Cloud SDK"
14+
if [[ ! $(command -v gsutil) ]]; then
15+
CURRENT_DIR=$(dirname "$BASH_SOURCE")
16+
. "${CURRENT_DIR}"/install-google-cloud-sdk.sh
17+
fi
18+
19+
export GOOGLE_APPLICATION_CREDENTIALS
20+
gcloud auth activate-service-account --key-file ${GOOGLE_APPLICATION_CREDENTIALS}
21+
}
22+
23+
install_and_start_local_redis() {
24+
print_banner "Installing and tarting Redis at localhost:6379"
25+
# Allow starting serving in this Maven Docker image. Default set to not allowed.
26+
echo "exit 0" >/usr/sbin/policy-rc.d
27+
apt-get -y install redis-server >/var/log/redis.install.log
28+
redis-server --daemonize yes
29+
redis-cli ping
30+
}
31+
32+
install_and_start_local_redis_cluster() {
33+
print_banner "Installing Redis at localhost:6379"
34+
echo "exit 0" >/usr/sbin/policy-rc.d
35+
${SCRIPTS_DIR}/setup-redis-cluster.sh
36+
redis-cli -c -p 7000 ping
37+
}
38+
39+
install_and_start_local_postgres() {
40+
print_banner "Installing and starting Postgres at localhost:5432"
41+
apt-get -y install postgresql >/var/log/postgresql.install.log
42+
service postgresql start
43+
# Initialize with database: 'postgres', user: 'postgres', password: 'password'
44+
cat <<EOF >/tmp/update-postgres-role.sh
45+
psql -c "ALTER USER postgres PASSWORD 'password';"
46+
EOF
47+
chmod +x /tmp/update-postgres-role.sh
48+
su -s /bin/bash -c /tmp/update-postgres-role.sh postgres
49+
export PGPASSWORD=password
50+
pg_isready
51+
}
52+
53+
install_and_start_local_zookeeper_and_kafka() {
54+
print_banner "Installing and starting Zookeeper at localhost:2181 and Kafka at localhost:9092"
55+
wget -qO- https://www-eu.apache.org/dist/kafka/2.3.0/kafka_2.12-2.3.0.tgz | tar xz
56+
mv kafka_2.12-2.3.0/ /tmp/kafka
57+
58+
nohup /tmp/kafka/bin/zookeeper-server-start.sh /tmp/kafka/config/zookeeper.properties &>/var/log/zookeeper.log 2>&1 &
59+
${SCRIPTS_DIR}/wait-for-it.sh localhost:2181 --timeout=20
60+
tail -n10 /var/log/zookeeper.log
61+
62+
nohup /tmp/kafka/bin/kafka-server-start.sh /tmp/kafka/config/server.properties &>/var/log/kafka.log 2>&1 &
63+
${SCRIPTS_DIR}/wait-for-it.sh localhost:9092 --timeout=40
64+
tail -n10 /var/log/kafka.log
65+
kafkacat -b localhost:9092 -L
66+
}
67+
68+
build_feast_core_and_serving() {
69+
print_banner "Building Feast Core and Feast Serving"
70+
infra/scripts/download-maven-cache.sh \
71+
--archive-uri gs://feast-templocation-kf-feast/.m2.2019-10-24.tar \
72+
--output-dir /root/
73+
74+
# Build jars for Feast
75+
mvn --quiet --batch-mode --define skipTests=true clean package
76+
77+
ls -lh core/target/*jar
78+
ls -lh serving/target/*jar
79+
}
80+
81+
start_feast_core() {
82+
print_banner "Starting Feast Core"
83+
84+
if [ -n "$1" ]; then
85+
echo "Custom Spring application.yml location provided: $1"
86+
export CONFIG_ARG="--spring.config.location=file://$1"
87+
fi
88+
89+
nohup java -jar core/target/feast-core-$FEAST_BUILD_VERSION.jar $CONFIG_ARG &>/var/log/feast-core.log &
90+
${SCRIPTS_DIR}/wait-for-it.sh localhost:6565 --timeout=90
91+
92+
tail -n10 /var/log/feast-core.log
93+
nc -w2 localhost 6565 </dev/null
94+
}
95+
96+
start_feast_serving() {
97+
print_banner "Starting Feast Online Serving"
98+
99+
if [ -n "$1" ]; then
100+
echo "Custom Spring application.yml location provided: $1"
101+
export CONFIG_ARG="--spring.config.location=file://$1"
102+
fi
103+
104+
nohup java -jar serving/target/feast-serving-$FEAST_BUILD_VERSION.jar $CONFIG_ARG &>/var/log/feast-serving-online.log &
105+
${SCRIPTS_DIR}/wait-for-it.sh localhost:6566 --timeout=60
106+
107+
tail -n100 /var/log/feast-serving-online.log
108+
nc -w2 localhost 6566 </dev/null
109+
}
110+
111+
install_python_with_miniconda_and_feast_sdk() {
112+
print_banner "Installing Python 3.7 with Miniconda and Feast SDK"
113+
# Install Python 3.7 with Miniconda
114+
wget -q https://repo.continuum.io/miniconda/Miniconda3-4.7.12-Linux-x86_64.sh \
115+
-O /tmp/miniconda.sh
116+
bash /tmp/miniconda.sh -b -p /root/miniconda -f
117+
/root/miniconda/bin/conda init
118+
source ~/.bashrc
119+
120+
# Install Feast Python SDK and test requirements
121+
make compile-protos-python
122+
pip install -qe sdk/python
123+
pip install -qr tests/e2e/requirements.txt
124+
}
125+
126+
print_banner() {
127+
echo "
128+
============================================================
129+
$1
130+
============================================================
131+
"
132+
}

infra/scripts/test-end-to-end-batch.sh

Lines changed: 18 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ test -z ${TEMP_BUCKET} && TEMP_BUCKET="feast-templocation-kf-feast"
2424
test -z ${JOBS_STAGING_LOCATION} && JOBS_STAGING_LOCATION="gs://${TEMP_BUCKET}/staging-location"
2525

2626
# Get the current build version using maven (and pom.xml)
27-
FEAST_BUILD_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
27+
export FEAST_BUILD_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
2828
echo Building version: $FEAST_BUILD_VERSION
2929

30+
# Get Feast project repository root and scripts directory
31+
export PROJECT_ROOT_DIR=$(git rev-parse --show-toplevel)
32+
export SCRIPTS_DIR=${PROJECT_ROOT_DIR}/infra/scripts
33+
3034
echo "
3135
This script will run end-to-end tests for Feast Core and Batch Serving.
3236
@@ -38,152 +42,24 @@ This script will run end-to-end tests for Feast Core and Batch Serving.
3842
tests/e2e via pytest.
3943
"
4044

41-
apt-get -qq update
42-
apt-get -y install wget netcat kafkacat build-essential
43-
44-
45-
echo "
46-
============================================================
47-
Installing gcloud SDK
48-
============================================================
49-
"
50-
if [[ ! $(command -v gsutil) ]]; then
51-
CURRENT_DIR=$(dirname "$BASH_SOURCE")
52-
. "${CURRENT_DIR}"/install-google-cloud-sdk.sh
53-
fi
54-
55-
export GOOGLE_APPLICATION_CREDENTIALS
56-
gcloud auth activate-service-account --key-file ${GOOGLE_APPLICATION_CREDENTIALS}
57-
58-
59-
60-
echo "
61-
============================================================
62-
Installing Redis at localhost:6379
63-
============================================================
64-
"
65-
# Allow starting serving in this Maven Docker image. Default set to not allowed.
66-
echo "exit 0" > /usr/sbin/policy-rc.d
67-
apt-get -y install redis-server > /var/log/redis.install.log
68-
redis-server --daemonize yes
69-
redis-cli ping
70-
71-
echo "
72-
============================================================
73-
Installing Postgres at localhost:5432
74-
============================================================
75-
"
76-
apt-get -y install postgresql > /var/log/postgresql.install.log
77-
service postgresql start
78-
# Initialize with database: 'postgres', user: 'postgres', password: 'password'
79-
cat <<EOF > /tmp/update-postgres-role.sh
80-
psql -c "ALTER USER postgres PASSWORD 'password';"
81-
EOF
82-
chmod +x /tmp/update-postgres-role.sh
83-
su -s /bin/bash -c /tmp/update-postgres-role.sh postgres
84-
export PGPASSWORD=password
85-
pg_isready
45+
source ${SCRIPTS_DIR}/setup-common-functions.sh
8646

87-
echo "
88-
============================================================
89-
Installing Zookeeper at localhost:2181
90-
Installing Kafka at localhost:9092
91-
============================================================
92-
"
93-
wget -qO- https://www-eu.apache.org/dist/kafka/2.3.0/kafka_2.12-2.3.0.tgz | tar xz
94-
mv kafka_2.12-2.3.0/ /tmp/kafka
95-
nohup /tmp/kafka/bin/zookeeper-server-start.sh /tmp/kafka/config/zookeeper.properties &> /var/log/zookeeper.log 2>&1 &
96-
sleep 5
97-
tail -n10 /var/log/zookeeper.log
98-
nohup /tmp/kafka/bin/kafka-server-start.sh /tmp/kafka/config/server.properties &> /var/log/kafka.log 2>&1 &
99-
sleep 20
100-
tail -n10 /var/log/kafka.log
101-
kafkacat -b localhost:9092 -L
47+
install_test_tools
48+
install_gcloud_sdk
49+
install_and_start_local_redis
50+
install_and_start_local_postgres
51+
install_and_start_local_zookeeper_and_kafka
10252

10353
if [[ ${SKIP_BUILD_JARS} != "true" ]]; then
104-
echo "
105-
============================================================
106-
Building jars for Feast
107-
============================================================
108-
"
109-
110-
infra/scripts/download-maven-cache.sh \
111-
--archive-uri gs://feast-templocation-kf-feast/.m2.2019-10-24.tar \
112-
--output-dir /root/
113-
114-
# Build jars for Feast
115-
mvn --quiet --batch-mode --define skipTests=true clean package
116-
117-
ls -lh core/target/*jar
118-
ls -lh serving/target/*jar
54+
build_feast_core_and_serving
11955
else
12056
echo "[DEBUG] Skipping building jars"
12157
fi
12258

123-
echo "
124-
============================================================
125-
Starting Feast Core
126-
============================================================
127-
"
128-
# Start Feast Core in background
129-
cat <<EOF > /tmp/core.application.yml
130-
grpc:
131-
port: 6565
132-
enable-reflection: true
133-
134-
feast:
135-
jobs:
136-
polling_interval_milliseconds: 10000
137-
job_update_timeout_seconds: 240
138-
139-
active_runner: direct
140-
141-
runners:
142-
- name: direct
143-
type: DirectRunner
144-
options: {}
145-
146-
metrics:
147-
enabled: false
148-
149-
stream:
150-
type: kafka
151-
options:
152-
topic: feast-features
153-
bootstrapServers: localhost:9092
154-
replicationFactor: 1
155-
partitions: 1
156-
157-
spring:
158-
jpa:
159-
properties.hibernate:
160-
format_sql: true
161-
event:
162-
merge:
163-
entity_copy_observer: allow
164-
hibernate.naming.physical-strategy=org.hibernate.boot.model.naming: PhysicalNamingStrategyStandardImpl
165-
hibernate.ddl-auto: update
166-
datasource:
167-
url: jdbc:postgresql://localhost:5432/postgres
168-
username: postgres
169-
password: password
170-
EOF
171-
172-
nohup java -jar core/target/feast-core-${FEAST_BUILD_VERSION}.jar \
173-
--spring.config.location=file:///tmp/core.application.yml \
174-
&> /var/log/feast-core.log &
175-
sleep 35
176-
tail -n10 /var/log/feast-core.log
177-
nc -w2 localhost 6565 < /dev/null
178-
179-
echo "
180-
============================================================
181-
Starting Feast Warehouse Serving
182-
============================================================
183-
"
59+
export FEAST_JOBS_POLLING_INTERVAL_MILLISECONDS=10000
60+
start_feast_core
18461

18562
DATASET_NAME=feast_$(date +%s)
186-
18763
bq --location=US --project_id=${GOOGLE_CLOUD_PROJECT} mk \
18864
--dataset \
18965
--default_table_expiration 86400 \
@@ -232,35 +108,11 @@ server:
232108
233109
EOF
234110

235-
nohup java -jar serving/target/feast-serving-${FEAST_BUILD_VERSION}.jar \
236-
--spring.config.location=file:///tmp/serving.warehouse.application.yml \
237-
&> /var/log/feast-serving-warehouse.log &
238-
sleep 15
239-
tail -n100 /var/log/feast-serving-warehouse.log
240-
nc -w2 localhost 6566 < /dev/null
111+
start_feast_serving /tmp/serving.warehouse.application.yml
241112

242-
echo "
243-
============================================================
244-
Installing Python 3.7 with Miniconda and Feast SDK
245-
============================================================
246-
"
247-
# Install Python 3.7 with Miniconda
248-
wget -q https://repo.continuum.io/miniconda/Miniconda3-4.7.12-Linux-x86_64.sh \
249-
-O /tmp/miniconda.sh
250-
bash /tmp/miniconda.sh -b -p /root/miniconda -f
251-
/root/miniconda/bin/conda init
252-
source ~/.bashrc
253-
254-
# Install Feast Python SDK and test requirements
255-
make compile-protos-python
256-
pip install -qe sdk/python
257-
pip install -qr tests/e2e/requirements.txt
113+
install_python_with_miniconda_and_feast_sdk
258114

259-
echo "
260-
============================================================
261-
Running end-to-end tests with pytest at 'tests/e2e'
262-
============================================================
263-
"
115+
print_banner "Running end-to-end tests with pytest at 'tests/e2e'"
264116
# Default artifact location setting in Prow jobs
265117
LOGS_ARTIFACT_PATH=/logs/artifacts
266118

@@ -282,12 +134,7 @@ fi
282134

283135
cd ${ORIGINAL_DIR}
284136

285-
echo "
286-
============================================================
287-
Cleaning up
288-
============================================================
289-
"
137+
print_banner "Cleaning up"
290138

291139
bq rm -r -f ${GOOGLE_CLOUD_PROJECT}:${DATASET_NAME}
292-
293140
exit ${TEST_EXIT_CODE}

0 commit comments

Comments
 (0)