Add scripts to test deployment by docker-compose (#7448)

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
This commit is contained in:
zhuwenxing 2021-09-03 17:15:51 +08:00 committed by GitHub
parent 1db573731b
commit 4783f5bcbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 438 additions and 0 deletions

View File

@ -1,6 +1,9 @@
# python files
.pytest_cache
**/.pytest_cache
**/volumes
**/logs
**/docker-compose.yml
.idea
*.html

View File

@ -0,0 +1,58 @@
## overview
To test deployment by docker-compose(Both standalone and cluster)
* re-install milvus to check data persistence
1. Deploy Milvus
2. Insert data
3. Build index
4. Search
5. Stop Milvus
6. Repeat from step #1
* upgrade milvus to check data compatibility
1. Deploy Milvus Previous RC)
2. Insert data
3. Search
4. Stop Milvus
5. Deploy Milvus (Latest RC)
6. Build index
7. Search
## project structure
```
.
├── README.md
├── cluster # dir to deploy cluster
│ ├── logs # dir to save logs
│ └──docker-compose.yml
├── standalone # dir to deploy standalone
│ ├── logs # dir to save logs
│ └──docker-compose.yml
├── scripts
│ ├── action_after_upgrade.py
│ ├── action_before_upgrade.py
│ ├── action_reinstall.py
│ └── utils.py
├── test.sh # script to run a single task
└── run.sh # script to run all tasks
```
## usage
Make sure you have installed `docker`,`docker-compose` and `pymilvus`!
For different version, you should modify the value of `latest_tag`, `latest_rc_tag` and `Release`. Password of root is needed for deleting volumes dir.
single test task
```bash
$ bash test.sh -m ${Mode} -t ${Task} -p ${Password}
# Mode, the mode of milvus deploy. standalone or cluster"
# Task, the task type of test. reinstall or upgrade
# Password, the password of root"
```
run all tasks
```bash
$ bash run.sh -p ${Password}
# Password, the password of root"
````

View File

@ -0,0 +1,28 @@
#!/bin/bash
set -x
func() {
echo "Usage:"
echo "run.sh [-p Password]"
echo "Password, the password of root"
exit -1
}
while getopts "hp:" OPT;do
case $OPT in
p) Password="$OPTARG";;
h) func;;
?) func;;
esac
done
pw=$Password
# start test standalone reinstall
bash test.sh -m standalone -t reinstall -p $pw
# start test standalone upgrade
bash test.sh -m standalone -t upgrade -p $pw
# start test cluster reinstall
bash test.sh -m cluster -t reinstall -p $pw
# start test cluster upgrade
bash test.sh -m cluster -t pgrade -p $pw

View File

@ -0,0 +1,15 @@
import docker
from utils import *
connections.connect()
list_containers()
get_collections()
load_and_search()
create_index()
load_and_search()

View File

@ -0,0 +1,13 @@
import docker
from utils import *
connections.connect()
list_containers()
get_collections()
load_and_search()
create_collections_and_insert_data()

View File

@ -0,0 +1,18 @@
import docker
from utils import *
connections.connect()
list_containers()
get_collections()
load_and_search()
create_collections_and_insert_data()
create_index()
load_and_search()

View File

@ -0,0 +1,100 @@
import docker
from pymilvus import (
connections, FieldSchema, CollectionSchema, DataType,
Collection, list_collections,
)
def list_containers():
client = docker.from_env()
containers = client.containers.list()
for c in containers:
if "milvus" in c.name:
print(c.image)
def get_collections():
print(f"\nList collections...")
col_list = list_collections()
print(f"collections_nums: {len(col_list)}")
# list entities if collections
for name in col_list:
c = Collection(name = name)
print(f"{name}: {c.num_entities}")
def create_collections_and_insert_data(col_name="hello_milvus"):
import random
dim = 128
default_fields = [
FieldSchema(name="count", dtype=DataType.INT64, is_primary=True),
FieldSchema(name="random_value", dtype=DataType.DOUBLE),
FieldSchema(name="float_vector", dtype=DataType.FLOAT_VECTOR, dim=dim)
]
default_schema = CollectionSchema(fields=default_fields, description="test collection")
print(f"\nCreate collection...")
collection = Collection(name=col_name, schema=default_schema)
print(f"\nList collections...")
print(list_collections())
# insert data
nb = 3000
vectors = [[random.random() for _ in range(dim)] for _ in range(nb)]
collection.insert(
[
[i for i in range(nb)],
[float(random.randrange(-20, -10)) for _ in range(nb)],
vectors
]
)
print(f"\nGet collection entities...")
print(collection.num_entities)
def create_index():
# create index
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
col_list = list_collections()
print(f"\nCreate index...")
for name in col_list:
c = Collection(name = name)
print(name)
print(c)
c.create_index(field_name="float_vector", index_params=default_index)
def load_and_search():
print("search data starts")
col_list = list_collections()
for name in col_list:
c = Collection(name=name)
print(f"collection name: {name}")
c.load()
topK = 5
vectors = [[1.0 for _ in range(128)] for _ in range(3000)]
search_params = {"metric_type": "L2", "params": {"nprobe": 10}}
import time
start_time = time.time()
print(f"\nSearch...")
# define output_fields of search result
res = c.search(
vectors[-2:], "float_vector", search_params, topK,
"count > 500", output_fields=["count", "random_value"]
)
end_time = time.time()
# show result
for hits in res:
for hit in hits:
# Get value of the random value field for search result
print(hit, hit.entity.get("random_value"))
print("###########")
print("search latency = %.4fs" % (end_time - start_time))
c.release()
print("search data ends")

View File

@ -0,0 +1,203 @@
#!/bin/bash
set -e
# set -x
func() {
echo "Usage:"
echo "test.sh [-t Task] [-m Mode] [-r Release] [-p Password]"
echo "Description"
echo "Task, the task type of test. reinstall or upgrade"
echo "Mode, the mode of milvus deploy. standalone or cluster"
echo "Release, the release of milvus. e.g. 2.0.0-rc5"
echo "Password, the password of root"
exit -1
}
echo "check os env"
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='Linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='Mac'
fi
echo "platform: $platform"
Task="reinstall"
Mode="standalone"
Release="2.0.0-rc5"
while getopts "hm:t:p:" OPT;do
case $OPT in
m) Mode="$OPTARG";;
t) Task="$OPTARG";;
p) Password="$OPTARG";;
h) func;;
?) func;;
esac
done
ROOT_FOLDER=$(cd "$(dirname "$0")";pwd)
# to export docker-compose logs before exit
function error_exit {
pushd ${ROOT_FOLDER}/${Deploy_Dir}
echo "test failed"
current=`date "+%Y-%m-%d-%H-%M-%S"`
if [ ! -d logs ];
then
mkdir logs
fi
docker-compose logs > ./logs/${Deploy_Dir}-${Task}-${current}.log
echo "log saved to `pwd`/logs/${Deploy_Dir}-${Task}-${current}.log"
popd
exit 1
}
function replace_image_tag {
image_tag=$1
if [ "$platform" == "Mac" ];
then
# for mac os
sed -i "" "s/milvusdb\/milvus.*/milvusdb\/milvus-dev\:${image_tag}/g" docker-compose.yml
else
#for linux os
sed -i "s/milvusdb\/milvus.*/milvusdb\/milvus-dev\:${image_tag}/g" docker-compose.yml
fi
}
#to check containers all running and minio is healthy
function check_healthy {
cnt=`docker-compose ps | grep -E "Running|Up" | wc -l`
healthy=`docker-compose ps | grep "Healthy" | wc -l`
time_cnt=0
echo "running num $cnt expect num $Expect"
echo "healthy num $healthy expect num 1"
while [[ $cnt -ne $Expect || $healthy -ne 1 ]];
do
printf "waiting all containers get running\n"
sleep 5s
let time_cnt+=5
# if time is greater than 300s, the condition still not satisfied, we regard it as a failure
if [ $time_cnt -gt 300 ];
then
printf "timeout,there are some issue with deployment!"
error_exit
fi
cnt=`docker-compose ps | grep -E "Running|Up" | wc -l`
healthy=`docker-compose ps | grep "healthy" | wc -l`
echo "running num $cnt expect num $Expect"
echo "healthy num $healthy expect num 1"
done
}
Deploy_Dir=$Mode
Task=$Task
Release=$Release
pw=$Password
echo "mode: $Mode"
echo "task: $Task"
echo "password: $pw"
## if needed, install dependency
#echo "install dependency"
#pip install -r scripts/requirements.txt
if [ ! -d ${Deploy_Dir} ];
then
mkdir ${Deploy_Dir}
fi
latest_tag=2.0.0-rc5-latest # the version you are testing now
latest_rc_tag=2.0.0-rc4-latest # a previous version based on current version
pushd ${Deploy_Dir}
# download docker-compose.yml
wget https://github.com/milvus-io/milvus/releases/download/v${Release}/milvus-${Deploy_Dir}-docker-compose.yml -O docker-compose.yml
# clean env to deoploy a fresh milvus
docker-compose down
sleep 10s
docker-compose ps
echo "$pw"| sudo -S rm -rf ./volumes
# first deployment
if [ "$Task" == "reinstall" ];
then
printf "start to deploy latest rc tag milvus\n"
replace_image_tag $latest_tag
fi
if [ "$Task" == "upgrade" ];
then
printf "start to deploy previous rc tag milvus\n"
replace_image_tag $latest_rc_tag
fi
cat docker-compose.yml|grep milvusdb
Expect=`grep "container_name" docker-compose.yml | wc -l`
docker-compose up -d
check_healthy
docker-compose ps
popd
# test for first deploymnent
printf "test for first deployment\n"
if [ "$Task" == "reinstall" ];
then
python scripts/action_reinstall.py || error_exit
fi
if [ "$Task" == "upgrade" ];
then
python scripts/action_before_upgrade.py || error_exit
fi
pushd ${Deploy_Dir}
# uninstall milvus
printf "start to uninstall milvus\n"
docker-compose down
sleep 10s
printf "check all containers removed\n"
docker-compose ps
# second deployment
if [ "$Task" == "reinstall" ];
then
printf "start to reinstall milvus\n"
#because the task is reinstall, so don't change images tag
fi
if [ "$Task" == "upgrade" ];
then
printf "start to upgrade milvus\n"
# because the task is upgrade, so replace image tag to latest, like rc4-->rc5
replace_image_tag $latest_tag
fi
cat docker-compose.yml|grep milvusdb
docker-compose up -d
check_healthy
docker-compose ps
popd
# test for second deployment
printf "test for second deployment\n"
if [ "$Task" == "reinstall" ];
then
python scripts/action_reinstall.py || error_exit
fi
if [ "$Task" == "upgrade" ];
then
python scripts/action_after_upgrade.py || error_exit
fi
pushd ${Deploy_Dir}
# clean env
docker-compose ps
docker-compose down
sleep 10s
docker-compose ps
echo "$pw"|sudo -S rm -rf ./volumes
popd