-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add E2E Endpoint Checks #864
Open
ishaansehgal99
wants to merge
22
commits into
main
Choose a base branch
from
Ishaan/e2e-probe-v1-completion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
24f1662
feat: Add e2e endpoint checks
ishaansehgal99 3398157
fix: format
ishaansehgal99 d335df9
fix: dep
ishaansehgal99 29f1bf6
fix: Get Preset Name
ishaansehgal99 505991f
fix: dep
ishaansehgal99 2487fb1
fix: use model name
ishaansehgal99 a75c9da
fix: Add retry logic
ishaansehgal99 9d42d77
fix: Add eventually and exec into pod
ishaansehgal99 8eac250
fix: Add eventually and exec into pod
ishaansehgal99 0bf8dcb
fix: cleanup
ishaansehgal99 96e4ff8
fix: nit fix
ishaansehgal99 e404543
fix: Get clientset
ishaansehgal99 8969e90
fix: exec curl in pod
ishaansehgal99 ac6aeb7
fix: dep
ishaansehgal99 7adc0b3
fix: dep
ishaansehgal99 49c9797
fix: dep
ishaansehgal99 dac3616
fix: Use correct utils, format, update
ishaansehgal99 10837bb
fix: dep
ishaansehgal99 b8f8b42
fix: Remove unused func
ishaansehgal99 fe96cbf
fix: lint
ishaansehgal99 d4ff9c5
Merge branch 'main' of https://github.com/kaito-project/kaito into Is…
ishaansehgal99 7de06ad
fix: dep
ishaansehgal99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,14 +4,10 @@ | |||||
package e2e | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
"fmt" | ||||||
"log" | ||||||
"math/rand" | ||||||
"os" | ||||||
"strconv" | ||||||
"strings" | ||||||
"time" | ||||||
|
||||||
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1" | ||||||
"github.com/kaito-project/kaito/test/e2e/utils" | ||||||
. "github.com/onsi/ginkgo/v2" | ||||||
. "github.com/onsi/gomega" | ||||||
"github.com/samber/lo" | ||||||
|
@@ -20,10 +16,13 @@ | |||||
v1 "k8s.io/api/core/v1" | ||||||
"k8s.io/apimachinery/pkg/api/errors" | ||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
"log" | ||||||
"math/rand" | ||||||
"os" | ||||||
"sigs.k8s.io/controller-runtime/pkg/client" | ||||||
|
||||||
kaitov1alpha1 "github.com/kaito-project/kaito/api/v1alpha1" | ||||||
"github.com/kaito-project/kaito/test/e2e/utils" | ||||||
"strconv" | ||||||
"strings" | ||||||
"time" | ||||||
) | ||||||
|
||||||
const ( | ||||||
|
@@ -42,6 +41,8 @@ | |||||
WorkspaceRevisionAnnotation = "workspace.kaito.io/revision" | ||||||
) | ||||||
|
||||||
const curlPodName = "curl-debug-pod" | ||||||
|
||||||
var ( | ||||||
datasetImageName1 = "e2e-dataset" | ||||||
fullDatasetImageName1 = utils.GetEnv("E2E_ACR_REGISTRY") + "/" + datasetImageName1 + ":0.0.1" | ||||||
|
@@ -608,6 +609,141 @@ | |||||
}) | ||||||
} | ||||||
|
||||||
// Create a temporary debug pod with curl if it doesn't already exist | ||||||
func createCurlDebugPod(namespace string) error { | ||||||
By("Creating a temporary curl debug pod") | ||||||
|
||||||
existingPod := &v1.Pod{} | ||||||
err := utils.TestingCluster.KubeClient.Get(context.TODO(), client.ObjectKey{ | ||||||
Namespace: namespace, | ||||||
Name: curlPodName, | ||||||
}, existingPod) | ||||||
|
||||||
if err == nil { | ||||||
By(fmt.Sprintf("Debug pod %s already exists", curlPodName)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return nil | ||||||
} else if !errors.IsNotFound(err) { | ||||||
return fmt.Errorf("failed to check existing pod: %v", err) | ||||||
} | ||||||
|
||||||
pod := &v1.Pod{ | ||||||
ObjectMeta: metav1.ObjectMeta{ | ||||||
Name: curlPodName, | ||||||
Namespace: namespace, | ||||||
}, | ||||||
Spec: v1.PodSpec{ | ||||||
Containers: []v1.Container{ | ||||||
{ | ||||||
Name: "curl-container", | ||||||
Image: "curlimages/curl", | ||||||
Command: []string{ | ||||||
"sleep", "3600", // Keeps the pod running for long enough | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sleep "infinity" |
||||||
}, | ||||||
}, | ||||||
}, | ||||||
RestartPolicy: v1.RestartPolicyNever, | ||||||
}, | ||||||
} | ||||||
|
||||||
// Create the pod | ||||||
err = utils.TestingCluster.KubeClient.Create(context.TODO(), pod) | ||||||
if err != nil { | ||||||
return fmt.Errorf("failed to create curl debug pod: %v", err) | ||||||
} | ||||||
|
||||||
// Wait for the pod to be Running | ||||||
Eventually(func() bool { | ||||||
fetchedPod := &v1.Pod{} | ||||||
err := utils.TestingCluster.KubeClient.Get(context.TODO(), client.ObjectKey{ | ||||||
Namespace: namespace, | ||||||
Name: curlPodName, | ||||||
}, fetchedPod) | ||||||
if err != nil { | ||||||
return false | ||||||
} | ||||||
return fetchedPod.Status.Phase == v1.PodRunning | ||||||
}, 60*time.Second, 2*time.Second).Should(BeTrue(), "Curl debug pod did not reach Running state") | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
// Execute a curl command inside the debug pod | ||||||
func execCurlInPod(namespace string, cmd []string) (string, error) { | ||||||
ishaansehgal99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
By(fmt.Sprintf("Executing curl command in %s", curlPodName)) | ||||||
|
||||||
// Get Kubernetes clientset and config | ||||||
coreClient, err := utils.GetK8sClientset() | ||||||
if err != nil { | ||||||
return "", fmt.Errorf("failed to get k8s clientset: %v", err) | ||||||
} | ||||||
|
||||||
// Get REST config for creating the SPDYExecutor | ||||||
k8sConfig, err := utils.GetK8sConfig() | ||||||
if err != nil { | ||||||
return "", fmt.Errorf("failed to get k8s config: %v", err) | ||||||
} | ||||||
|
||||||
// Use the existing ExecSync function | ||||||
output, err := utils.ExecSync(context.TODO(), k8sConfig, coreClient, namespace, curlPodName, v1.PodExecOptions{ | ||||||
Container: "curl-container", | ||||||
Command: cmd, | ||||||
Stdout: true, | ||||||
Stderr: true, | ||||||
TTY: false, | ||||||
}) | ||||||
|
||||||
if err != nil { | ||||||
return "", fmt.Errorf("failed to execute curl command: %w", err) | ||||||
} | ||||||
|
||||||
return output, nil | ||||||
} | ||||||
|
||||||
func validateModelsEndpoint(workspaceObj *kaitov1alpha1.Workspace) { | ||||||
By("Validating the /v1/models endpoint using a curl debug pod") | ||||||
|
||||||
namespace := workspaceObj.Namespace | ||||||
serviceURL := fmt.Sprintf("http://%s.%s.svc.cluster.local:80/v1/models", | ||||||
workspaceObj.Name, namespace) | ||||||
|
||||||
curlCmd := []string{"curl", "-s", "-X", "GET", serviceURL} | ||||||
|
||||||
response, err := execCurlInPod(namespace, curlCmd) | ||||||
Expect(err).ToNot(HaveOccurred(), "Failed to execute curl GET in debug pod") | ||||||
|
||||||
fmt.Printf("Response from /v1/models: %s\n", response) | ||||||
|
||||||
modelName := workspaceObj.Inference.Preset.Name | ||||||
expectedModelID := fmt.Sprintf(`"id":"%s"`, modelName) | ||||||
Expect(response).To(ContainSubstring(expectedModelID), "Expected model ID '%s' not found in response", modelName) | ||||||
} | ||||||
|
||||||
func validateCompletionsEndpoint(workspaceObj *kaitov1alpha1.Workspace) { | ||||||
By("Validating the /v1/completions endpoint using a curl debug pod") | ||||||
|
||||||
namespace := workspaceObj.Namespace | ||||||
serviceURL := fmt.Sprintf("http://%s.%s.svc.cluster.local:80/v1/completions", | ||||||
workspaceObj.Name, namespace) | ||||||
|
||||||
modelName := workspaceObj.Inference.Preset.Name | ||||||
requestBody := fmt.Sprintf(`{ | ||||||
"model": "%s", | ||||||
"prompt": "What is Kubernetes?", | ||||||
"max_tokens": 7, | ||||||
"temperature": 0 | ||||||
}`, modelName) | ||||||
|
||||||
// Explicitly pass the curl command for POST request | ||||||
curlCmd := []string{"curl", "-s", "-X", "POST", "-H", "Content-Type: application/json", "-d", requestBody, serviceURL} | ||||||
|
||||||
response, err := execCurlInPod(namespace, curlCmd) | ||||||
Expect(err).ToNot(HaveOccurred(), "Failed to execute curl POST in debug pod") | ||||||
|
||||||
fmt.Printf("Response from /v1/completions: %s\n", response) | ||||||
|
||||||
Expect(response).To(ContainSubstring(`"object":"text_completion"`), "Expected 'text_completion' object not found in response") | ||||||
} | ||||||
|
||||||
func cleanupResources(workspaceObj *kaitov1alpha1.Workspace) { | ||||||
By("Cleaning up resources", func() { | ||||||
if !CurrentSpecReport().Failed() { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use namespaceName this one.😀