From 82ba06a9a958bc493e6f62aa8a0f95e4a896cb1e Mon Sep 17 00:00:00 2001 From: irisdingbj Date: Thu, 6 Jun 2024 23:02:00 +0000 Subject: [PATCH 1/5] add gmce2e Signed-off-by: irisdingbj --- .github/workflows/scripts/e2e/go_test.sh | 139 +++++++++++++++++- .../config/gmcrouter/gmc-router.yaml | 2 +- .../config/manager/gmc-manager.yaml | 2 +- 3 files changed, 140 insertions(+), 3 deletions(-) diff --git a/.github/workflows/scripts/e2e/go_test.sh b/.github/workflows/scripts/e2e/go_test.sh index 4f90ff047..59047e3b4 100755 --- a/.github/workflows/scripts/e2e/go_test.sh +++ b/.github/workflows/scripts/e2e/go_test.sh @@ -12,19 +12,152 @@ function install_gmc() { # Make sure you have to use image tag $VERSION for microservice-connector installation echo "install microservice-connector, using repo $DOCKER_REGISTRY and tag $VERSION" echo "using namespace $SYSTEM_NAMESPACE and $APP_NAMESPACE" + + init_gmc + + kubectl apply -f $(pwd)/config/crd/bases/gmc.opea.io_gmconnectors.yaml + kubectl apply -f $(pwd)/config/rbac/gmc-manager-rbac.yaml + kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/config/manifests + kubectl apply -f $(pwd)/config/manager/gmc-manager.yaml + + # Wait until the gmc conroller pod is ready + wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller" } function validate_gmc() { - echo "validate microservice-connector" + echo "validate chat-qna" + validate_chatqna + } function cleanup_gmc() { echo "clean up microservice-connector" + kubectl delete ns $APP_NAMESPACE + kubectl delete ns $SYSTEM_NAMESPACE + kubectl delete crd gmconnectors.gmc.opea.io # clean up the images docker rmi $DOCKER_REGISTRY/gmcrouter:$VERSION docker rmi $DOCKER_REGISTRY/gmcmanager:$VERSION } +function validate_chatqna() { + + + # todo select gaudi or xeon + kubectl create ns $APP_NAMESPACE + sed -i "s|namespace: chatqa|namespace: $APP_NAMESPACE|g" $(pwd)/config/samples/chatQnA_xeon.yaml + kubectl apply -f $(pwd)/config/samples/chatQnA_xeon.yaml + + + + output=$(kubectl get pods) + echo $output + + # Wait until the router service is ready + echo "Waiting for the chatqa router service to be ready..." + wait_until_pod_ready "chatqna router" $APP_NAMESPACE "router-service" + + + # deploy client pod for testing + kubectl create deployment client-test -n $APP_NAMESPACE --image=python:3.8.13 -- sleep infinity + + # wait for client pod ready + wait_until_pod_ready "client-test" $APP_NAMESPACE "client-test" + # giving time to populating data + sleep 120 + + # send request to chatqnA + export CLIENT_POD=$(kubectl get pod -n $APP_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name}) + echo "$CLIENT_POD" + accessUrl=$(kubectl get gmc -n $APP_NAMESPACE -o jsonpath="{.items[?(@.metadata.name=='chatqa')].status.accessUrl}") + kubectl exec "$CLIENT_POD" -n $APP_NAMESPACE -- curl $accessUrl -X POST -d '{"text":"What is the revenue of Nike in 2023?","parameters":{"max_new_tokens":17, "do_sample": true}}' -H 'Content-Type: application/json' > $LOG_PATH/curl_chatqna.log + exit_code=$? + if [ $exit_code -ne 0 ]; then + echo "chatqna failed, please check the logs in ${LOG_PATH}!" + exit 1 + fi + + echo "Checking response results, make sure the output is reasonable. " + local status=false + if [[ -f $LOG_PATH/curl_chatqna.log ]] && \ + [[ $(grep -c "billion" $LOG_PATH/curl_chatqna.log) != 0 ]]; then + status=true + fi + if [ $status == false ]; then + echo "Response check failed, please check the logs in artifacts!" + exit 1 + else + echo "Response check succeed!" + fi +} + +function init_gmc() { + # Copy manifest into gmc + mkdir -p $(pwd)/config/manifests + cp $(dirname $(pwd))/manifests/ChatQnA/*.yaml -p $(pwd)/config/manifests/ + + # replace tag with for the gmc-router and gmc-manager image + sed -i "s|opea/\(.*\):latest|opea/\1:$VERSION|g" $(pwd)/config/gmcrouter/gmc-router.yaml + sed -i "s|opea/\(.*\):latest|opea/\1:$VERSION|g" $(pwd)/config/manager/gmc-manager.yaml + cp $(pwd)/config/gmcrouter/gmc-router.yaml -p $(pwd)/config/manifests/ + + + + # replace namespace for gmc-router and gmc-manager + sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" $(pwd)/config/manager/gmc-manager.yaml + sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" $(pwd)/config/rbac/gmc-manager-rbac.yaml + sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" $(pwd)/config/rbac/gmc-manager-rbac.yaml + # replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT" + find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \; + # replace the repository "image: opea/*" with "image: $IMAGE_REPO/opea/" + find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: $IMAGE_REPO/opea/#g" {} \; + # set huggingface token + # find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; + find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; + # replace namespace "default" with real namespace + find . -name '*.yaml' -type f -exec sed -i "s#default.svc#$APP_NAMESPACE.svc#g" {} \; +} + + +function wait_until_pod_ready() { + echo "Waiting for the $1 to be ready..." + max_retries=3000 + retry_count=0 + while ! is_pod_ready $2 $3; do + if [ $retry_count -ge $max_retries ]; then + echo "$1 is not ready after waiting for a significant amount of time" + exit 1 + fi + echo "$1 is not ready yet. Retrying in 10 seconds..." + sleep 10 + output=$(kubectl get pods -n $2) + # Check if the command was successful + if [ $? -eq 0 ]; then + echo "Successfully retrieved $1 information:" + echo "$output" + else + echo "Failed to retrieve $1 information" + exit 1 + fi + retry_count=$((retry_count + 1)) + done +} + +function is_pod_ready() { + if [ "$2" == "gmc-controller" ]; then + pod_status=$(kubectl get pods -n $1 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}') + else + pod_status=$(kubectl get pods -n $1 -l app=$2 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}') + fi + if [ "$pod_status" == "True" ]; then + return 0 + else + return 1 + fi +} + + + if [ $# -eq 0 ]; then echo "Usage: $0 " exit 1 @@ -32,10 +165,14 @@ fi case "$1" in install_gmc) + pushd microservices-connector install_gmc + popd ;; validate_gmc) + pushd microservices-connector validate_gmc + popd ;; cleanup_gmc) cleanup_gmc diff --git a/microservices-connector/config/gmcrouter/gmc-router.yaml b/microservices-connector/config/gmcrouter/gmc-router.yaml index 04d4f04fb..82ff0b2f7 100644 --- a/microservices-connector/config/gmcrouter/gmc-router.yaml +++ b/microservices-connector/config/gmcrouter/gmc-router.yaml @@ -32,7 +32,7 @@ spec: serviceAccountName: default containers: - name: router-server - image: zhlsunshine/gmcrouter:latest + image: opea/gmcrouter:latest imagePullPolicy: IfNotPresent ports: - containerPort: 8080 diff --git a/microservices-connector/config/manager/gmc-manager.yaml b/microservices-connector/config/manager/gmc-manager.yaml index 2d661b081..d30830b06 100644 --- a/microservices-connector/config/manager/gmc-manager.yaml +++ b/microservices-connector/config/manager/gmc-manager.yaml @@ -27,7 +27,7 @@ spec: containers: - command: - /manager - image: zhlsunshine/gmcmanager:latest + image: opea/gmcmanager:latest name: manager volumeMounts: - name: yaml-file From f5bd7db87a9b5ef611b94f9f624b0d522466c12e Mon Sep 17 00:00:00 2001 From: irisdingbj Date: Thu, 6 Jun 2024 23:11:40 +0000 Subject: [PATCH 2/5] print more info Signed-off-by: irisdingbj --- .github/workflows/scripts/e2e/go_test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/scripts/e2e/go_test.sh b/.github/workflows/scripts/e2e/go_test.sh index 59047e3b4..f12f926f1 100755 --- a/.github/workflows/scripts/e2e/go_test.sh +++ b/.github/workflows/scripts/e2e/go_test.sh @@ -42,7 +42,7 @@ function cleanup_gmc() { function validate_chatqna() { - + kubectl get pods -n $SYSTEM_NAMESPACE # todo select gaudi or xeon kubectl create ns $APP_NAMESPACE sed -i "s|namespace: chatqa|namespace: $APP_NAMESPACE|g" $(pwd)/config/samples/chatQnA_xeon.yaml @@ -64,8 +64,8 @@ function validate_chatqna() { # wait for client pod ready wait_until_pod_ready "client-test" $APP_NAMESPACE "client-test" # giving time to populating data - sleep 120 - + sleep 180 + kubectl get pods -n $APP_NAMESPACE # send request to chatqnA export CLIENT_POD=$(kubectl get pod -n $APP_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name}) echo "$CLIENT_POD" From 99ba7508d4dc3a8d41022b721488d3959478ef22 Mon Sep 17 00:00:00 2001 From: irisdingbj Date: Thu, 6 Jun 2024 23:35:45 +0000 Subject: [PATCH 3/5] add more info for tgi pod Signed-off-by: irisdingbj --- .github/workflows/scripts/e2e/go_test.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/scripts/e2e/go_test.sh b/.github/workflows/scripts/e2e/go_test.sh index f12f926f1..880749987 100755 --- a/.github/workflows/scripts/e2e/go_test.sh +++ b/.github/workflows/scripts/e2e/go_test.sh @@ -19,7 +19,7 @@ function install_gmc() { kubectl apply -f $(pwd)/config/rbac/gmc-manager-rbac.yaml kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/config/manifests kubectl apply -f $(pwd)/config/manager/gmc-manager.yaml - + # Wait until the gmc conroller pod is ready wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller" } @@ -47,7 +47,7 @@ function validate_chatqna() { kubectl create ns $APP_NAMESPACE sed -i "s|namespace: chatqa|namespace: $APP_NAMESPACE|g" $(pwd)/config/samples/chatQnA_xeon.yaml kubectl apply -f $(pwd)/config/samples/chatQnA_xeon.yaml - + output=$(kubectl get pods) @@ -57,15 +57,20 @@ function validate_chatqna() { echo "Waiting for the chatqa router service to be ready..." wait_until_pod_ready "chatqna router" $APP_NAMESPACE "router-service" + # Wait until the tgi pod is ready + TGI_POD_NAME=$(kubectl get pods --namespace=$APP_NAMESPACE | grep ^tgi-service | awk '{print $1}') + kubectl describe pod $TGI_POD_NAME -n $APP_NAMESPACE + kubectl wait --for=condition=ready pod/$TGI_POD_NAME --namespace=$APP_NAMESPACE --timeout=300s + # deploy client pod for testing - kubectl create deployment client-test -n $APP_NAMESPACE --image=python:3.8.13 -- sleep infinity + kubectl create deployment client-test -n $APP_NAMESPACE --image=python:3.8.13 -- sleep infinity # wait for client pod ready wait_until_pod_ready "client-test" $APP_NAMESPACE "client-test" # giving time to populating data - sleep 180 - kubectl get pods -n $APP_NAMESPACE + sleep 120 + kubectl get pods -n $APP_NAMESPACE # send request to chatqnA export CLIENT_POD=$(kubectl get pod -n $APP_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name}) echo "$CLIENT_POD" @@ -181,3 +186,4 @@ case "$1" in echo "Unknown function: $1" ;; esac + From 7599698e6b69e6523fb059273ea7a3287dd0c61c Mon Sep 17 00:00:00 2001 From: irisdingbj Date: Fri, 7 Jun 2024 03:06:33 +0000 Subject: [PATCH 4/5] fix mount dir Signed-off-by: irisdingbj --- .github/workflows/scripts/e2e/go_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/e2e/go_test.sh b/.github/workflows/scripts/e2e/go_test.sh index 880749987..1e41c3d65 100755 --- a/.github/workflows/scripts/e2e/go_test.sh +++ b/.github/workflows/scripts/e2e/go_test.sh @@ -113,7 +113,7 @@ function init_gmc() { sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" $(pwd)/config/rbac/gmc-manager-rbac.yaml sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" $(pwd)/config/rbac/gmc-manager-rbac.yaml # replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT" - find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \; + find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \; # replace the repository "image: opea/*" with "image: $IMAGE_REPO/opea/" find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: $IMAGE_REPO/opea/#g" {} \; # set huggingface token From 47da7c7232c0d7c082b8e9c6a7112e05b6b2fdb1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Jun 2024 03:07:20 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/scripts/e2e/go_test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/scripts/e2e/go_test.sh b/.github/workflows/scripts/e2e/go_test.sh index 1e41c3d65..6654da524 100755 --- a/.github/workflows/scripts/e2e/go_test.sh +++ b/.github/workflows/scripts/e2e/go_test.sh @@ -20,7 +20,7 @@ function install_gmc() { kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/config/manifests kubectl apply -f $(pwd)/config/manager/gmc-manager.yaml - # Wait until the gmc conroller pod is ready + # Wait until the gmc controller pod is ready wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller" } @@ -186,4 +186,3 @@ case "$1" in echo "Unknown function: $1" ;; esac -