Skip to content

Commit 960cf38

Browse files
authored
Add codegen e2e test of genaiexample (#337)
Signed-off-by: zhlsunshine <[email protected]>
1 parent afcb3a3 commit 960cf38

File tree

4 files changed

+400
-0
lines changed

4 files changed

+400
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: gmc.opea.io/v1alpha3
5+
kind: GMConnector
6+
metadata:
7+
labels:
8+
app.kubernetes.io/name: gmconnector
9+
app.kubernetes.io/managed-by: kustomize
10+
gmc/platform: gaudi
11+
name: codegen
12+
namespace: codegen
13+
spec:
14+
routerConfig:
15+
name: router
16+
serviceName: router-service
17+
nodes:
18+
root:
19+
routerType: Sequence
20+
steps:
21+
- name: Llm
22+
data: $response
23+
internalService:
24+
serviceName: llm-service
25+
config:
26+
endpoint: /v1/chat/completions
27+
- name: TgiGaudi
28+
internalService:
29+
serviceName: tgi-gaudi-svc
30+
config:
31+
LLM_MODEL_ID: ise-uiuc/Magicoder-S-DS-6.7B
32+
endpoint: /generate
33+
isDownstreamService: true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: gmc.opea.io/v1alpha3
5+
kind: GMConnector
6+
metadata:
7+
labels:
8+
app.kubernetes.io/name: gmconnector
9+
app.kubernetes.io/managed-by: kustomize
10+
gmc/platform: xeon
11+
name: codegen
12+
namespace: codegen
13+
spec:
14+
routerConfig:
15+
name: router
16+
serviceName: router-service
17+
nodes:
18+
root:
19+
routerType: Sequence
20+
steps:
21+
- name: Llm
22+
data: $response
23+
internalService:
24+
serviceName: llm-service
25+
config:
26+
endpoint: /v1/chat/completions
27+
- name: Tgi
28+
internalService:
29+
serviceName: tgi-service
30+
config:
31+
LLM_MODEL_ID: ise-uiuc/Magicoder-S-DS-6.7B
32+
endpoint: /generate
33+
isDownstreamService: true

CodeGen/tests/test_gmc_on_gaudi.sh

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024 Intel Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set -xe
6+
USER_ID=$(whoami)
7+
LOG_PATH=/home/$(whoami)/logs
8+
MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub
9+
IMAGE_REPO=${IMAGE_REPO:-}
10+
11+
function init_codegen() {
12+
wget https://github.com/opea-project/GenAIInfra/main/microservices-connector/config/crd/bases/gmc.opea.io_gmconnectors.yaml
13+
wget https://github.com/opea-project/GenAIInfra/main/microservices-connector/config/rbac/gmc-manager-rbac.yaml
14+
wget https://github.com/opea-project/GenAIInfra/main/microservices-connector/config/manager/gmc-manager.yaml
15+
wget -O manifests/gmc-router.yaml https://github.com/opea-project/GenAIInfra/main/microservices-connector/config/gmcrouter/gmc-router.yaml
16+
17+
# replace namespace for gmc-router and gmc-manager
18+
sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager.yaml
19+
sed -i "s|namespace: system|namespace: $SYSTEM_NAMESPACE|g" ./gmc-manager-rbac.yaml
20+
sed -i "s|name: system|name: $SYSTEM_NAMESPACE|g" ./gmc-manager-rbac.yaml
21+
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
22+
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \;
23+
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
24+
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: ${IMAGE_REPO}opea/#g" {} \;
25+
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: ${IMAGE_REPO}opea\"/#g" {} \;
26+
# set huggingface token
27+
find . -name '*.yaml' -type f -exec sed -i "s#\${HUGGINGFACEHUB_API_TOKEN}#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
28+
# replace namespace "default" with real namespace
29+
find . -name '*.yaml' -type f -exec sed -i "s#default.svc#$APP_NAMESPACE.svc#g" {} \;
30+
}
31+
32+
function install_codegen() {
33+
# Make sure you have to use image tag $VERSION for microservice-connector installation
34+
echo "install microservice-connector, using repo $DOCKER_REGISTRY and tag $VERSION"
35+
echo "using namespace $SYSTEM_NAMESPACE and $APP_NAMESPACE"
36+
37+
kubectl apply -f ./gmc.opea.io_gmconnectors.yaml
38+
kubectl apply -f ./gmc-manager-rbac.yaml
39+
kubectl create configmap gmcyaml -n $SYSTEM_NAMESPACE --from-file $(pwd)/../kubernetes/manifests
40+
kubectl apply -f ./gmc-manager.yaml
41+
42+
# Wait until the gmc controller pod is ready
43+
wait_until_pod_ready "gmc-controller" $SYSTEM_NAMESPACE "gmc-controller"
44+
kubectl get pods -n $SYSTEM_NAMESPACE
45+
rm -f ./gmc.opea.io_gmconnectors.yaml ./gmc-manager-rbac.yaml ./gmc-manager.yaml manifests/gmc-router.yaml
46+
}
47+
48+
function validate_codegen() {
49+
kubectl create ns $APP_NAMESPACE
50+
sed -i "s|namespace: codegen|namespace: $APP_NAMESPACE|g" ./codegen_gaudi.yaml
51+
kubectl apply -f ./codegen_gaudi.yaml
52+
53+
# Wait until the router service is ready
54+
echo "Waiting for the codegen router service to be ready..."
55+
wait_until_pod_ready "codegen router" $APP_NAMESPACE "router-service"
56+
output=$(kubectl get pods -n $APP_NAMESPACE)
57+
echo $output
58+
59+
# deploy client pod for testing
60+
kubectl create deployment client-test -n $APP_NAMESPACE --image=python:3.8.13 -- sleep infinity
61+
62+
# wait for client pod ready
63+
wait_until_pod_ready "client-test" $APP_NAMESPACE "client-test"
64+
# giving time to populating data
65+
sleep 60
66+
67+
kubectl get pods -n $APP_NAMESPACE
68+
# send request to codegen
69+
export CLIENT_POD=$(kubectl get pod -n $APP_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name})
70+
echo "$CLIENT_POD"
71+
accessUrl=$(kubectl get gmc -n $APP_NAMESPACE -o jsonpath="{.items[?(@.metadata.name=='codegen')].status.accessUrl}")
72+
kubectl exec "$CLIENT_POD" -n $APP_NAMESPACE -- curl $accessUrl -X POST -d '{"query": "def print_hello_world():"}' -H 'Content-Type: application/json' > $LOG_PATH/gmc_codegen.log
73+
exit_code=$?
74+
if [ $exit_code -ne 0 ]; then
75+
echo "chatqna failed, please check the logs in ${LOG_PATH}!"
76+
exit 1
77+
fi
78+
79+
echo "Checking response results, make sure the output is reasonable. "
80+
local status=false
81+
if [[ -f $LOG_PATH/gmc_codegen.log ]] && \
82+
[[ $(grep -c "print" $LOG_PATH/gmc_codegen.log) != 0 ]]; then
83+
status=true
84+
fi
85+
if [ $status == false ]; then
86+
if [[ -f $LOG_PATH/gmc_codegen.log ]]; then
87+
cat $LOG_PATH/gmc_codegen.log
88+
fi
89+
echo "Response check failed, please check the logs in artifacts!"
90+
cat $LOG_PATH/gmc_codegen.log
91+
exit 1
92+
else
93+
echo "Response check succeed!"
94+
fi
95+
}
96+
97+
function wait_until_pod_ready() {
98+
echo "Waiting for the $1 to be ready..."
99+
max_retries=30
100+
retry_count=0
101+
while ! is_pod_ready $2 $3; do
102+
if [ $retry_count -ge $max_retries ]; then
103+
echo "$1 is not ready after waiting for a significant amount of time"
104+
get_gmc_controller_logs
105+
exit 1
106+
fi
107+
echo "$1 is not ready yet. Retrying in 10 seconds..."
108+
sleep 10
109+
output=$(kubectl get pods -n $2)
110+
echo $output
111+
retry_count=$((retry_count + 1))
112+
done
113+
}
114+
115+
function is_pod_ready() {
116+
if [ "$2" == "gmc-controller" ]; then
117+
pod_status=$(kubectl get pods -n $1 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}')
118+
else
119+
pod_status=$(kubectl get pods -n $1 -l app=$2 -o jsonpath='{.items[].status.conditions[?(@.type=="Ready")].status}')
120+
fi
121+
if [ "$pod_status" == "True" ]; then
122+
return 0
123+
else
124+
return 1
125+
fi
126+
}
127+
128+
function get_gmc_controller_logs() {
129+
# Fetch the name of the pod with the app-name gmc-controller in the specified namespace
130+
pod_name=$(kubectl get pods -n $SYSTEM_NAMESPACE -l control-plane=gmc-controller -o jsonpath='{.items[0].metadata.name}')
131+
132+
# Check if the pod name was found
133+
if [ -z "$pod_name" ]; then
134+
echo "No pod found with app-name gmc-controller in namespace $SYSTEM_NAMESPACE"
135+
return 1
136+
fi
137+
138+
# Get the logs of the found pod
139+
echo "Fetching logs for pod $pod_name in namespace $SYSTEM_NAMESPACE..."
140+
kubectl logs $pod_name -n $SYSTEM_NAMESPACE
141+
}
142+
143+
if [ $# -eq 0 ]; then
144+
echo "Usage: $0 <function_name>"
145+
exit 1
146+
fi
147+
148+
case "$1" in
149+
init_CodeGen)
150+
pushd ChatQnA/kubernetes
151+
init_codegen
152+
popd
153+
;;
154+
install_CodeGen)
155+
pushd ChatQnA/kubernetes
156+
install_codegen
157+
popd
158+
;;
159+
validate_CodeGen)
160+
pushd CodeGen/kubernetes
161+
validate_codegen
162+
popd
163+
;;
164+
*)
165+
echo "Unknown function: $1"
166+
;;
167+
esac

0 commit comments

Comments
 (0)