Skip to content

Commit

Permalink
add codegen e2e test (#107)
Browse files Browse the repository at this point in the history
* add codegen e2e test

---------

Signed-off-by: KfreeZ <[email protected]>
  • Loading branch information
KfreeZ authored Jun 20, 2024
1 parent 654ef63 commit 18f53c9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/scripts/e2e/gmc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ USER_ID=$(whoami)
LOG_PATH=/home/$(whoami)/logs
MOUNT_DIR=/home/$USER_ID/charts-mnt
IMAGE_REPO=${OPEA_IMAGE_REPO:-""}
CODEGEN_NAMESPACE="${APP_NAMESPACE}-codegen"

function install_gmc() {
# Make sure you have to use image tag $VERSION for microservice-connector installation
Expand All @@ -29,11 +30,16 @@ function validate_gmc() {
echo "validate chat-qna"
validate_chatqna

echo "validate codegen"
validate_codegen

get_gmc_controller_logs
}

function cleanup_gmc() {
echo "clean up microservice-connector"
kubectl delete ns $APP_NAMESPACE
kubectl delete ns $CODEGEN_NAMESPACE
kubectl delete ns $SYSTEM_NAMESPACE
kubectl delete crd gmconnectors.gmc.opea.io
# clean up the images
Expand Down Expand Up @@ -94,6 +100,54 @@ function validate_chatqna() {
fi
}

function validate_codegen() {

# todo select gaudi or xeon
kubectl create ns $CODEGEN_NAMESPACE
sed -i "s|namespace: codegen|namespace: $CODEGEN_NAMESPACE|g" $(pwd)/config/samples/codegen.yaml
kubectl apply -f $(pwd)/config/samples/codegen.yaml

# Wait until the router service is ready
echo "Waiting for the codegen router service to be ready..."
wait_until_pod_ready "codegen router" $CODEGEN_NAMESPACE "router-service"
output=$(kubectl get pods -n $CODEGEN_NAMESPACE)
echo $output


# deploy client pod for testing
kubectl create deployment client-test -n $CODEGEN_NAMESPACE --image=python:3.8.13 -- sleep infinity

# wait for client pod ready
wait_until_pod_ready "client-test" $CODEGEN_NAMESPACE "client-test"
# giving time to populating data
sleep 60

kubectl get pods -n $CODEGEN_NAMESPACE
# send request to codegen
export CLIENT_POD=$(kubectl get pod -n $CODEGEN_NAMESPACE -l app=client-test -o jsonpath={.items..metadata.name})
echo "$CLIENT_POD"
accessUrl=$(kubectl get gmc -n $CODEGEN_NAMESPACE -o jsonpath="{.items[?(@.metadata.name=='codegen')].status.accessUrl}")
kubectl exec "$CLIENT_POD" -n $CODEGEN_NAMESPACE -- curl $accessUrl -X POST -d '{"messages": "def print_hello_world():"}' -H 'Content-Type: application/json' > $LOG_PATH/gmc_codegen.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/gmc_codegen.log ]] && \
[[ $(grep -c "print" $LOG_PATH/gmc_codegen.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
Expand Down Expand Up @@ -128,6 +182,7 @@ function wait_until_pod_ready() {
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..."
Expand All @@ -151,6 +206,21 @@ function is_pod_ready() {
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 <function_name>"
exit 1
Expand Down
16 changes: 1 addition & 15 deletions microservices-connector/config/samples/codegen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ spec:
routerConfig:
name: router
serviceName: router-service
config:
no_proxy: ".codegen.svc.cluster.local"
http_proxy: "insert-your-http-proxy-here"
https_proxy: "insert-your-https-proxy-here"
nodes:
root:
routerType: Sequence
Expand All @@ -26,21 +22,11 @@ spec:
internalService:
serviceName: llm-service
config:
no_proxy: ".codegen.svc.cluster.local"
http_proxy: "insert-your-http-proxy-here"
https_proxy: "insert-your-https-proxy-here"
tgi_endpoint: http://tgi-service.codegen.svc.cluster.local:9009
gmcTokenSecret: gmc-tokens
endpoint: /v1/chat/completions
- name: Tgi
internalService:
serviceName: tgi-service
config:
no_proxy: ".codegen.svc.cluster.local"
http_proxy: "insert-your-http-proxy-here"
https_proxy: "insert-your-https-proxy-here"
gmcTokenSecret: gmc-tokens
hostPath: /root/GMC/data/tgi
modelId: ise-uiuc/Magicoder-S-DS-6.7B
LLM_MODEL_ID: ise-uiuc/Magicoder-S-DS-6.7B
endpoint: /generate
isDownstreamService: true
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ func reconcileResource(ctx context.Context, client client.Client, step string, n
newEnvVars...)
}
//overwrite the managed fields is needed, we write this deployment twice here
deployment.ManagedFields = nil

deployment.SetManagedFields(nil)
latest := &unstructured.Unstructured{}
latest.SetGroupVersionKind(deployment.GroupVersionKind())
deployment.SetResourceVersion(latest.GetResourceVersion())
// Update the deployment using client.Client
if err := client.Update(ctx, deployment); err != nil {
return fmt.Errorf("Failed to update deployment: %v\n", err)
Expand Down

0 comments on commit 18f53c9

Please sign in to comment.