From 2e62ecc18a80ee3788ed2a2daae984e4ad8492e4 Mon Sep 17 00:00:00 2001 From: Steve Zhang Date: Fri, 28 Jun 2024 18:15:51 +0800 Subject: [PATCH] add docsum example e2e test for GMC. (#347) * add docsum example e2e test for GMC. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * fix curl error for docsum. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * change the manifest e2e yaml. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * change the image format. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * fixing image mapping error. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * change the gmc e2e test. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * accelarate the e2e test. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * change the gmc e2e configuration. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * retrigger. Signed-off-by: zhlsunshine Co-authored-by: Yingchun Guo * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Yingchun Guo Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Malini Bhandaru --- .github/workflows/gmc-e2e.yaml | 8 +- .github/workflows/manifest-e2e.yml | 2 +- .../manifests/docsum_gaudi_llm.yaml | 74 ++++++++ ChatQnA/kubernetes/manifests/docsum_llm.yaml | 74 ++++++++ ChatQnA/tests/test_gmc_on_gaudi.sh | 2 +- ChatQnA/tests/test_gmc_on_xeon.sh | 2 +- CodeGen/tests/test_gmc_on_gaudi.sh | 2 +- CodeGen/tests/test_gmc_on_xeon.sh | 2 +- CodeTrans/tests/test_gmc_on_gaudi.sh | 2 +- CodeTrans/tests/test_gmc_on_xeon.sh | 2 +- DocSum/kubernetes/docsum_gaudi.yaml | 35 ++++ DocSum/kubernetes/docsum_xeon.yaml | 35 ++++ DocSum/tests/test_gmc_on_gaudi.sh | 167 +++++++++++++++++ DocSum/tests/test_gmc_on_xeon.sh | 168 ++++++++++++++++++ 14 files changed, 564 insertions(+), 11 deletions(-) create mode 100644 ChatQnA/kubernetes/manifests/docsum_gaudi_llm.yaml create mode 100644 ChatQnA/kubernetes/manifests/docsum_llm.yaml create mode 100644 DocSum/kubernetes/docsum_gaudi.yaml create mode 100644 DocSum/kubernetes/docsum_xeon.yaml create mode 100755 DocSum/tests/test_gmc_on_gaudi.sh create mode 100755 DocSum/tests/test_gmc_on_xeon.sh diff --git a/.github/workflows/gmc-e2e.yaml b/.github/workflows/gmc-e2e.yaml index e96123926..dede3411a 100644 --- a/.github/workflows/gmc-e2e.yaml +++ b/.github/workflows/gmc-e2e.yaml @@ -93,12 +93,12 @@ jobs: if: always() run: | if $should_cleanup; then - if ! kubectl delete ns $APP_NAMESPACE --timeout=$KUBECTL_TIMEOUT_SECONDS; then - kubectl delete pods --namespace $APP_NAMESPACE --force --grace-period=0 --all - kubectl delete ns $APP_NAMESPACE --force --grace-period=0 --timeout=$KUBECTL_TIMEOUT_SECONDS - fi if ! kubectl delete ns $SYSTEM_NAMESPACE --timeout=$KUBECTL_TIMEOUT_SECONDS; then kubectl delete pods --namespace $SYSTEM_NAMESPACE --force --grace-period=0 --all kubectl delete ns $SYSTEM_NAMESPACE --force --grace-period=0 --timeout=$KUBECTL_TIMEOUT_SECONDS fi + if ! kubectl delete ns $APP_NAMESPACE --timeout=$KUBECTL_TIMEOUT_SECONDS; then + kubectl delete pods --namespace $APP_NAMESPACE --force --grace-period=0 --all + kubectl delete ns $APP_NAMESPACE --force --grace-period=0 --timeout=$KUBECTL_TIMEOUT_SECONDS + fi fi diff --git a/.github/workflows/manifest-e2e.yml b/.github/workflows/manifest-e2e.yml index 29e915d9f..291055b7c 100644 --- a/.github/workflows/manifest-e2e.yml +++ b/.github/workflows/manifest-e2e.yml @@ -58,7 +58,7 @@ jobs: - name: Set variables run: | if [ ${{ matrix.hardware }} == "gaudi" ]; then IMAGE_REPO=${{ vars.IMAGE_REPO_GAUDI }}; else IMAGE_REPO=${{ vars.IMAGE_REPO_XEON }}; fi - echo "IMAGE_REPO=${IMAGE_REPO}" >> $GITHUB_ENV + echo "IMAGE_REPO=$OPEA_IMAGE_REPO" >> $GITHUB_ENV echo "IMAGE_TAG=${{needs.mega-image-build.outputs.image_tag}}" >> $GITHUB_ENV lower_example=$(echo "${{ matrix.example }}" | tr '[:upper:]' '[:lower:]') echo "NAMESPACE=$lower_example-$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV diff --git a/ChatQnA/kubernetes/manifests/docsum_gaudi_llm.yaml b/ChatQnA/kubernetes/manifests/docsum_gaudi_llm.yaml new file mode 100644 index 000000000..aa48d00fe --- /dev/null +++ b/ChatQnA/kubernetes/manifests/docsum_gaudi_llm.yaml @@ -0,0 +1,74 @@ +# Source: llm-uservice/charts/tgi/templates/service.yaml +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: Service +metadata: + name: docsum-llm-uservice + labels: + helm.sh/chart: llm-uservice-0.1.0 + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + app.kubernetes.io/version: "1.0.0" + app.kubernetes.io/managed-by: Helm +spec: + type: ClusterIP + ports: + - port: 9000 + targetPort: 9000 + protocol: TCP + name: llm-uservice + selector: + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum +--- +# Source: llm-uservice/templates/deployment.yaml +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: docsum-llm-uservice + labels: + helm.sh/chart: llm-uservice-0.1.0 + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + app.kubernetes.io/version: "1.0.0" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + template: + metadata: + labels: + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + spec: + securityContext: {} + containers: + - name: docsum + envFrom: + - configMapRef: + name: qna-config + env: + - name: HUGGING_FACE_HUB_TOKEN + value: $(HUGGINGFACEHUB_API_TOKEN) + - name: HF_TOKEN + value: $(HUGGINGFACEHUB_API_TOKEN) + - name: LANGCHAIN_TRACING_V2 + value: "false" + - name: LANGCHAIN_PROJECT + value: "opea-llm-service" + securityContext: {} + image: "opea/llm-docsum-tgi:latest" + imagePullPolicy: IfNotPresent + ports: + - name: llm-uservice + containerPort: 9000 + protocol: TCP + resources: {} diff --git a/ChatQnA/kubernetes/manifests/docsum_llm.yaml b/ChatQnA/kubernetes/manifests/docsum_llm.yaml new file mode 100644 index 000000000..aa48d00fe --- /dev/null +++ b/ChatQnA/kubernetes/manifests/docsum_llm.yaml @@ -0,0 +1,74 @@ +# Source: llm-uservice/charts/tgi/templates/service.yaml +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v1 +kind: Service +metadata: + name: docsum-llm-uservice + labels: + helm.sh/chart: llm-uservice-0.1.0 + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + app.kubernetes.io/version: "1.0.0" + app.kubernetes.io/managed-by: Helm +spec: + type: ClusterIP + ports: + - port: 9000 + targetPort: 9000 + protocol: TCP + name: llm-uservice + selector: + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum +--- +# Source: llm-uservice/templates/deployment.yaml +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: docsum-llm-uservice + labels: + helm.sh/chart: llm-uservice-0.1.0 + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + app.kubernetes.io/version: "1.0.0" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + template: + metadata: + labels: + app.kubernetes.io/name: llm-uservice + app.kubernetes.io/instance: docsum + spec: + securityContext: {} + containers: + - name: docsum + envFrom: + - configMapRef: + name: qna-config + env: + - name: HUGGING_FACE_HUB_TOKEN + value: $(HUGGINGFACEHUB_API_TOKEN) + - name: HF_TOKEN + value: $(HUGGINGFACEHUB_API_TOKEN) + - name: LANGCHAIN_TRACING_V2 + value: "false" + - name: LANGCHAIN_PROJECT + value: "opea-llm-service" + securityContext: {} + image: "opea/llm-docsum-tgi:latest" + imagePullPolicy: IfNotPresent + ports: + - name: llm-uservice + containerPort: 9000 + protocol: TCP + resources: {} diff --git a/ChatQnA/tests/test_gmc_on_gaudi.sh b/ChatQnA/tests/test_gmc_on_gaudi.sh index 7b0ba138f..659a454ba 100755 --- a/ChatQnA/tests/test_gmc_on_gaudi.sh +++ b/ChatQnA/tests/test_gmc_on_gaudi.sh @@ -22,7 +22,7 @@ function init_chatqna() { 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" {} \; - find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; # replace namespace "default" with real namespace diff --git a/ChatQnA/tests/test_gmc_on_xeon.sh b/ChatQnA/tests/test_gmc_on_xeon.sh index 5658bfe41..c8dd49075 100755 --- a/ChatQnA/tests/test_gmc_on_xeon.sh +++ b/ChatQnA/tests/test_gmc_on_xeon.sh @@ -22,7 +22,7 @@ function init_chatqna() { 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" {} \; - find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; # replace namespace "default" with real namespace diff --git a/CodeGen/tests/test_gmc_on_gaudi.sh b/CodeGen/tests/test_gmc_on_gaudi.sh index 4bfbeac8d..b3ae1e477 100755 --- a/CodeGen/tests/test_gmc_on_gaudi.sh +++ b/CodeGen/tests/test_gmc_on_gaudi.sh @@ -22,7 +22,7 @@ function init_codegen() { 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" {} \; - find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; # replace namespace "default" with real namespace diff --git a/CodeGen/tests/test_gmc_on_xeon.sh b/CodeGen/tests/test_gmc_on_xeon.sh index 500c52d49..2d12a300a 100755 --- a/CodeGen/tests/test_gmc_on_xeon.sh +++ b/CodeGen/tests/test_gmc_on_xeon.sh @@ -22,7 +22,7 @@ function init_codegen() { 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" {} \; - find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; # replace namespace "default" with real namespace diff --git a/CodeTrans/tests/test_gmc_on_gaudi.sh b/CodeTrans/tests/test_gmc_on_gaudi.sh index 1c23cd47a..8dfa68c97 100755 --- a/CodeTrans/tests/test_gmc_on_gaudi.sh +++ b/CodeTrans/tests/test_gmc_on_gaudi.sh @@ -22,7 +22,7 @@ function init_codetrans() { 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" {} \; - find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; # replace namespace "default" with real namespace diff --git a/CodeTrans/tests/test_gmc_on_xeon.sh b/CodeTrans/tests/test_gmc_on_xeon.sh index 4847d5389..78fb67192 100755 --- a/CodeTrans/tests/test_gmc_on_xeon.sh +++ b/CodeTrans/tests/test_gmc_on_xeon.sh @@ -22,7 +22,7 @@ function init_codetrans() { 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" {} \; - find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \; # replace namespace "default" with real namespace diff --git a/DocSum/kubernetes/docsum_gaudi.yaml b/DocSum/kubernetes/docsum_gaudi.yaml new file mode 100644 index 000000000..7a3755c23 --- /dev/null +++ b/DocSum/kubernetes/docsum_gaudi.yaml @@ -0,0 +1,35 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: gmc.opea.io/v1alpha3 +kind: GMConnector +metadata: + labels: + app.kubernetes.io/name: gmconnector + app.kubernetes.io/managed-by: kustomize + gmc/platform: gaudi + name: docsum + namespace: docsum +spec: + routerConfig: + name: router + serviceName: router-service + nodes: + root: + routerType: Sequence + steps: + - name: DocSumGaudi + data: $response + internalService: + serviceName: docsum-llm-uservice + config: + endpoint: /v1/chat/docsum + PORT: "9009" + - name: TgiGaudi + internalService: + serviceName: tgi-gaudi-svc + config: + LANGCHAIN_TRACING_V2: "false" + LANGCHAIN_PROJECT: "opea-llm-service" + endpoint: /generate + isDownstreamService: true diff --git a/DocSum/kubernetes/docsum_xeon.yaml b/DocSum/kubernetes/docsum_xeon.yaml new file mode 100644 index 000000000..c07f03e6f --- /dev/null +++ b/DocSum/kubernetes/docsum_xeon.yaml @@ -0,0 +1,35 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: gmc.opea.io/v1alpha3 +kind: GMConnector +metadata: + labels: + app.kubernetes.io/name: gmconnector + app.kubernetes.io/managed-by: kustomize + gmc/platform: xeon + name: docsum + namespace: docsum +spec: + routerConfig: + name: router + serviceName: router-service + nodes: + root: + routerType: Sequence + steps: + - name: DocSum + data: $response + internalService: + serviceName: docsum-llm-uservice + config: + endpoint: /v1/chat/docsum + PORT: "9009" + - name: Tgi + internalService: + serviceName: tgi-svc + config: + LANGCHAIN_TRACING_V2: "false" + LANGCHAIN_PROJECT: "opea-llm-service" + endpoint: /generate + isDownstreamService: true diff --git a/DocSum/tests/test_gmc_on_gaudi.sh b/DocSum/tests/test_gmc_on_gaudi.sh new file mode 100755 index 000000000..f73d15330 --- /dev/null +++ b/DocSum/tests/test_gmc_on_gaudi.sh @@ -0,0 +1,167 @@ +#!/bin/bash +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +set -xe +USER_ID=$(whoami) +LOG_PATH=/home/$(whoami)/logs +MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub +IMAGE_REPO=${IMAGE_REPO:-} + +function init_docsum() { + wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/crd/bases/gmc.opea.io_gmconnectors.yaml + wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/rbac/gmc-manager-rbac.yaml + wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/manager/gmc-manager.yaml + wget -O manifests/gmc-router.yaml https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/gmcrouter/gmc-router.yaml + + # replace namespace for gmc-router and gmc-manager + sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager.yaml + sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager-rbac.yaml + sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" ./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/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" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(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 install_docsum() { + # 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" + + kubectl apply -f ./gmc.opea.io_gmconnectors.yaml + kubectl apply -f ./gmc-manager-rbac.yaml + kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/../kubernetes/manifests + kubectl apply -f ./gmc-manager.yaml + + # Wait until the gmc controller pod is ready + wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller" + kubectl get pods -n $SYSTEM_NAMESPACE + rm -f ./gmc.opea.io_gmconnectors.yaml ./gmc-manager-rbac.yaml ./gmc-manager.yaml manifests/gmc-router.yaml +} + +function validate_docsum() { + kubectl create ns $APP_NAMESPACE + sed -i "s|namespace: docsum|namespace: $APP_NAMESPACE|g" ./docsum_gaudi.yaml + kubectl apply -f ./docsum_gaudi.yaml + + # Wait until the router service is ready + echo "Waiting for the docsum router service to be ready..." + wait_until_pod_ready "docsum router" $APP_NAMESPACE "router-service" + output=$(kubectl get pods -n $APP_NAMESPACE) + echo $output + + # 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 60 + + kubectl get pods -n $APP_NAMESPACE + # send request to codetrans + 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=='docsum')].status.accessUrl}") + kubectl exec "$CLIENT_POD" -n $APP_NAMESPACE -- curl $accessUrl -X POST -d '{"query":"Text Embeddings Inference (TEI) is a toolkit for deploying and serving open source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5."}' -H 'Content-Type: application/json' > $LOG_PATH/gmc_docsum.log + exit_code=$? + if [ $exit_code -ne 0 ]; then + echo "docsum failed, please check the logs in ${LOG_PATH}!" + exit 1 + fi + + cat $LOG_PATH/gmc_docsum.log + echo "Checking response results, make sure the output is reasonable. " + local status=false + if [[ -f $LOG_PATH/gmc_docsum.log ]] && \ + [[ $(grep -c "[DONE]" $LOG_PATH/gmc_docsum.log) != 0 ]]; then + status=true + fi + if [ $status == false ]; then + if [[ -f $LOG_PATH/gmc_docsum.log ]]; then + cat $LOG_PATH/gmc_docsum.log + fi + echo "Response check failed, please check the logs in artifacts!" + exit 1 + else + echo "Response check succeed!" + fi +} + +function wait_until_pod_ready() { + echo "Waiting for the $1 to be ready..." + max_retries=30 + 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" + get_gmc_controller_logs + exit 1 + fi + echo "$1 is not ready yet. Retrying in 10 seconds..." + sleep 10 + output=$(kubectl get pods -n $2) + echo $output + 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 +} + +function get_gmc_controller_logs() { + # Fetch the name of the pod with the app-name gmc-controller in the specified namespace + pod_name=$(kubectl get pods -n $SYSTEM_NAMESPACE -l control-plane=gmc-controller -o jsonpath='{.items[0].metadata.name}') + + # Check if the pod name was found + if [ -z "$pod_name" ]; then + echo "No pod found with app-name gmc-controller in namespace $SYSTEM_NAMESPACE" + return 1 + fi + + # Get the logs of the found pod + echo "Fetching logs for pod $pod_name in namespace $SYSTEM_NAMESPACE..." + kubectl logs $pod_name -n $SYSTEM_NAMESPACE +} + +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +case "$1" in + init_DocSum) + pushd ChatQnA/kubernetes + init_docsum + popd + ;; + install_DocSum) + pushd ChatQnA/kubernetes + install_docsum + popd + ;; + validate_DocSum) + pushd DocSum/kubernetes + validate_docsum + popd + ;; + *) + echo "Unknown function: $1" + ;; +esac diff --git a/DocSum/tests/test_gmc_on_xeon.sh b/DocSum/tests/test_gmc_on_xeon.sh new file mode 100755 index 000000000..9c0b414fb --- /dev/null +++ b/DocSum/tests/test_gmc_on_xeon.sh @@ -0,0 +1,168 @@ +#!/bin/bash +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +set -xe +USER_ID=$(whoami) +LOG_PATH=/home/$(whoami)/logs +MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub +IMAGE_REPO=${IMAGE_REPO:-} + +function init_docsum() { + wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/crd/bases/gmc.opea.io_gmconnectors.yaml + wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/rbac/gmc-manager-rbac.yaml + wget https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/manager/gmc-manager.yaml + wget -O manifests/gmc-router.yaml https://raw.githubusercontent.com/opea-project/GenAIInfra/main/microservices-connector/config/gmcrouter/gmc-router.yaml + + # replace namespace for gmc-router and gmc-manager + sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager.yaml + sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager-rbac.yaml + sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" ./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/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" {} \; + 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#\${HUGGINGFACEHUB_API_TOKEN}#$(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 install_docsum() { + # 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" + + kubectl apply -f ./gmc.opea.io_gmconnectors.yaml + kubectl apply -f ./gmc-manager-rbac.yaml + kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/../kubernetes/manifests + kubectl apply -f ./gmc-manager.yaml + + # Wait until the gmc controller pod is ready + wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller" + kubectl get pods -n $SYSTEM_NAMESPACE + rm -f ./gmc.opea.io_gmconnectors.yaml ./gmc-manager-rbac.yaml ./gmc-manager.yaml manifests/gmc-router.yaml +} + +function validate_docsum() { + kubectl create ns $APP_NAMESPACE + sed -i "s|namespace: docsum|namespace: $APP_NAMESPACE|g" ./docsum_xeon.yaml + kubectl apply -f ./docsum_xeon.yaml + + # Wait until the router service is ready + echo "Waiting for the docsum router service to be ready..." + wait_until_pod_ready "docsum router" $APP_NAMESPACE "router-service" + output=$(kubectl get pods -n $APP_NAMESPACE) + echo $output + + + # 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 60 + + kubectl get pods -n $APP_NAMESPACE + # send request to docsum + 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=='docsum')].status.accessUrl}") + kubectl exec "$CLIENT_POD" -n $APP_NAMESPACE -- curl $accessUrl -X POST -d '{"query":"Text Embeddings Inference (TEI) is a toolkit for deploying and serving open source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5."}' -H 'Content-Type: application/json' > $LOG_PATH/gmc_docsum.log + exit_code=$? + if [ $exit_code -ne 0 ]; then + echo "docsum failed, please check the logs in ${LOG_PATH}!" + exit 1 + fi + + cat $LOG_PATH/gmc_docsum.log + echo "Checking response results, make sure the output is reasonable. " + local status=false + if [[ -f $LOG_PATH/gmc_docsum.log ]] && \ + [[ $(grep -c "[DONE]" $LOG_PATH/gmc_docsum.log) != 0 ]]; then + status=true + fi + if [ $status == false ]; then + if [[ -f $LOG_PATH/gmc_docsum.log ]]; then + cat $LOG_PATH/gmc_docsum.log + fi + echo "Response check failed, please check the logs in artifacts!" + exit 1 + else + echo "Response check succeed!" + fi +} + +function wait_until_pod_ready() { + echo "Waiting for the $1 to be ready..." + max_retries=30 + 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" + get_gmc_controller_logs + exit 1 + fi + echo "$1 is not ready yet. Retrying in 10 seconds..." + sleep 10 + output=$(kubectl get pods -n $2) + echo $output + 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 +} + +function get_gmc_controller_logs() { + # Fetch the name of the pod with the app-name gmc-controller in the specified namespace + pod_name=$(kubectl get pods -n $SYSTEM_NAMESPACE -l control-plane=gmc-controller -o jsonpath='{.items[0].metadata.name}') + + # Check if the pod name was found + if [ -z "$pod_name" ]; then + echo "No pod found with app-name gmc-controller in namespace $SYSTEM_NAMESPACE" + return 1 + fi + + # Get the logs of the found pod + echo "Fetching logs for pod $pod_name in namespace $SYSTEM_NAMESPACE..." + kubectl logs $pod_name -n $SYSTEM_NAMESPACE +} + +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +case "$1" in + init_DocSum) + pushd ChatQnA/kubernetes + init_docsum + popd + ;; + install_DocSum) + pushd ChatQnA/kubernetes + install_docsum + popd + ;; + validate_DocSum) + pushd DocSum/kubernetes + validate_docsum + popd + ;; + *) + echo "Unknown function: $1" + ;; +esac