-
Notifications
You must be signed in to change notification settings - Fork 18
(tests) Add test coverage for IaaS with Envoy, includes unit, e2e, and performance tests #291
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5eae06
add tests for ExternalProcessorService in iaas/ext_processor.py which…
s-akhtar-baig 79da152
add e2e and performance tests for iaas + envoy
s-akhtar-baig 0a72171
Merge branch 'main' into test_with_gateway
s-akhtar-baig 738deae
Handle review comments
s-akhtar-baig c57d170
Handle review comments
s-akhtar-baig 0d62d06
Use algorithm ainfer to establish baseline
s-akhtar-baig a3a54c2
Handle review comments
s-akhtar-baig f8d96db
Use dedicated thread pool in orchestrator
s-akhtar-baig 5731be3
Handle review comments
s-akhtar-baig c6d3b8e
Handle review comments
s-akhtar-baig 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,300 @@ | ||
| """ | ||
| End-to-end test for IaaS + Envoy integration. | ||
|
|
||
| Tests the full stack: Client -> Envoy -> ext_proc router -> IaaS -> LLM | ||
|
|
||
| Starts the IaaS service, ext_proc router, and (optionally) Envoy, then | ||
| runs requests through the stack and verifies correct routing and responses. | ||
|
|
||
| Usage: | ||
| # With real LLM endpoint: | ||
| python tests/e2e/test_iaas_envoy_e2e.py \\ | ||
| --endpoint http://localhost:8100/v1 \\ | ||
| --model_name Qwen/Qwen2.5-Math-7B-Instruct | ||
|
|
||
| # With built-in mock LLM (no external dependencies except Envoy): | ||
| python tests/e2e/test_iaas_envoy_e2e.py --mock-llm | ||
|
|
||
| # Skip Envoy (test IaaS service only): | ||
| python tests/e2e/test_iaas_envoy_e2e.py --mock-llm --skip-envoy | ||
| """ | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| import argparse | ||
| import shutil | ||
| import sys | ||
|
|
||
| from tests.e2e.utils.iaas_helpers import ( | ||
| configure_iaas, | ||
| find_free_port, | ||
| http_get, | ||
| http_post, | ||
| start_envoy, | ||
| start_iaas_stack, | ||
| start_mock_llm, | ||
| stop_processes, | ||
| ) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Result tracker | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class _Result: | ||
| def __init__(self): | ||
| self.passed = 0 | ||
| self.failed = 0 | ||
| self.skipped = 0 | ||
| self.details = [] | ||
|
|
||
| def ok(self, name): | ||
| self.passed += 1 | ||
| self.details.append(f" PASS {name}") | ||
| print(f" PASS {name}") | ||
|
|
||
| def fail(self, name, reason): | ||
| self.failed += 1 | ||
| self.details.append(f" FAIL {name}: {reason}") | ||
| print(f" FAIL {name}: {reason}") | ||
|
|
||
| def skip(self, name, reason): | ||
| self.skipped += 1 | ||
| self.details.append(f" SKIP {name}: {reason}") | ||
| print(f" SKIP {name}: {reason}") | ||
|
|
||
| def summary(self): | ||
| total = self.passed + self.failed + self.skipped | ||
| print(f"\n{'='*60}") | ||
| print(f"Results: {self.passed}/{total} passed, {self.failed} failed, {self.skipped} skipped") | ||
| if self.failed: | ||
| print("\nFailed tests:") | ||
| for d in self.details: | ||
| if "FAIL" in d: | ||
| print(d) | ||
| print(f"{'='*60}") | ||
| return self.failed == 0 | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Tests: IaaS direct | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def check_iaas_direct(iaas_url, llm_endpoint, model_name, api_key, result): | ||
| """Test IaaS service directly (without Envoy).""" | ||
| print("\n--- IaaS Direct Tests ---") | ||
|
|
||
| # Configure | ||
| try: | ||
| configure_iaas(iaas_url, llm_endpoint, model_name, api_key) | ||
| result.ok("iaas_configure") | ||
| except RuntimeError as e: | ||
| result.fail("iaas_configure", str(e)) | ||
| return | ||
|
|
||
| # Models endpoint | ||
| status, body = http_get(f"{iaas_url}/v1/models") | ||
| if status == 200 and body.get("data") and body["data"][0]["id"] == model_name: | ||
| result.ok("iaas_models") | ||
| else: | ||
| result.fail("iaas_models", f"unexpected: {body}") | ||
|
|
||
| # Chat completion via body budget | ||
| status, body = http_post(f"{iaas_url}/v1/chat/completions", { | ||
| "model": model_name, | ||
| "messages": [{"role": "user", "content": "What is 2+2?"}], | ||
| "budget": 3, | ||
| }) | ||
| if status == 200 and body.get("choices"): | ||
| content = body["choices"][0]["message"]["content"] | ||
| if content: | ||
| result.ok("iaas_chat_completion_body_budget") | ||
| else: | ||
| result.fail("iaas_chat_completion_body_budget", "empty content") | ||
| else: | ||
| result.fail("iaas_chat_completion_body_budget", f"status {status}: {body}") | ||
|
|
||
| # Chat completion via header budget | ||
| status, body = http_post( | ||
| f"{iaas_url}/v1/chat/completions", | ||
| { | ||
| "model": model_name, | ||
| "messages": [{"role": "user", "content": "What is 3+3?"}], | ||
| }, | ||
| headers={"X-ITS-Budget": "2"}, | ||
| ) | ||
| if status == 200 and body.get("choices"): | ||
| result.ok("iaas_chat_completion_header_budget") | ||
| else: | ||
| result.fail("iaas_chat_completion_header_budget", f"status {status}: {body}") | ||
|
|
||
| # Chat completion with header overrides | ||
| status, body = http_post( | ||
| f"{iaas_url}/v1/chat/completions", | ||
| { | ||
| "model": model_name, | ||
| "messages": [{"role": "user", "content": "What is 5+5?"}], | ||
| }, | ||
| headers={ | ||
| "X-ITS-Budget": "2", | ||
| "X-ITS-Endpoint": llm_endpoint, | ||
| "X-ITS-API-Key": api_key, | ||
| }, | ||
| ) | ||
| if status == 200 and body.get("choices"): | ||
| result.ok("iaas_header_overrides") | ||
| else: | ||
| result.fail("iaas_header_overrides", f"status {status}: {body}") | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Tests: Envoy-routed | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def check_envoy_routed(envoy_url, iaas_url, llm_endpoint, model_name, api_key, result): | ||
| """Test requests routed through Envoy.""" | ||
| print("\n--- Envoy-Routed Tests ---") | ||
|
|
||
| # Configure IaaS first | ||
| try: | ||
| configure_iaas(iaas_url, llm_endpoint, model_name, api_key) | ||
| except RuntimeError: | ||
| result.fail("envoy_precondition", "could not configure IaaS") | ||
| return | ||
|
|
||
| # ITS request through Envoy (should route to IaaS) | ||
| status, body = http_post( | ||
| f"{envoy_url}/v1/chat/completions", | ||
| { | ||
| "model": model_name, | ||
| "messages": [{"role": "user", "content": "What is 7+7?"}], | ||
| }, | ||
| headers={ | ||
| "X-ITS-Budget": "2", | ||
| "X-ITS-Endpoint": llm_endpoint, | ||
| "X-ITS-API-Key": api_key, | ||
| }, | ||
| ) | ||
| if status == 200 and body.get("choices"): | ||
| result.ok("envoy_its_request") | ||
| else: | ||
| result.fail("envoy_its_request", f"status {status}: {body}") | ||
|
|
||
| # Non-ITS request through Envoy (should pass through to LLM) | ||
| status, body = http_post( | ||
| f"{envoy_url}/v1/chat/completions", | ||
| { | ||
| "model": model_name, | ||
| "messages": [{"role": "user", "content": "Direct pass-through"}], | ||
| }, | ||
| ) | ||
| if status == 200 and body.get("choices"): | ||
| result.ok("envoy_passthrough") | ||
| else: | ||
| result.fail("envoy_passthrough", f"status {status}: {body}") | ||
|
|
||
| # Verify ITS headers are stripped on pass-through | ||
| status, body = http_post( | ||
| f"{envoy_url}/v1/chat/completions", | ||
| { | ||
| "model": model_name, | ||
| "messages": [{"role": "user", "content": "Stray header test"}], | ||
| }, | ||
| headers={"X-ITS-Endpoint": "http://should-be-stripped/v1"}, | ||
| ) | ||
| if status == 200: | ||
| if "its_headers_received" not in body: | ||
| result.skip( | ||
| "envoy_stray_header_stripped", | ||
| "upstream does not report received headers (use --mock-llm)", | ||
| ) | ||
| elif body["its_headers_received"]: | ||
| result.fail("envoy_stray_header_stripped", f"ITS headers reached LLM: {body['its_headers_received']}") | ||
| else: | ||
| result.ok("envoy_stray_header_stripped") | ||
| else: | ||
| result.fail("envoy_stray_header_stripped", f"status {status}") | ||
|
s-akhtar-baig marked this conversation as resolved.
|
||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Main | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def parse_args(): | ||
| p = argparse.ArgumentParser( | ||
| description="E2E tests for IaaS + Envoy integration", | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| ) | ||
| p.add_argument("--endpoint", help="LLM endpoint URL (e.g., http://localhost:8100/v1)") | ||
| p.add_argument("--model_name", default="mock-model", help="Model name at the endpoint") | ||
| p.add_argument("--api_key", default="NO_API_KEY", help="API key for the LLM endpoint") | ||
| p.add_argument("--mock-llm", action="store_true", help="Start a built-in mock LLM server") | ||
| p.add_argument("--skip-envoy", action="store_true", help="Skip Envoy tests (test IaaS only)") | ||
| return p.parse_args() | ||
|
|
||
|
|
||
| def main(): | ||
| args = parse_args() | ||
| result = _Result() | ||
| processes = [] | ||
| servers = [] | ||
| envoy_tmpdir = None | ||
|
|
||
| try: | ||
| # --- Resolve LLM endpoint --- | ||
| if args.mock_llm: | ||
| llm_port = find_free_port() | ||
| servers.append(start_mock_llm(llm_port)) | ||
| llm_endpoint = f"http://127.0.0.1:{llm_port}/v1" | ||
| model_name = "mock-model" | ||
| print(f"Mock LLM started on port {llm_port}") | ||
| elif args.endpoint: | ||
| llm_endpoint = args.endpoint | ||
| model_name = args.model_name | ||
| from urllib.parse import urlparse | ||
| llm_port = urlparse(llm_endpoint).port or 80 | ||
| else: | ||
| print("Error: provide --endpoint or --mock-llm") | ||
| sys.exit(1) | ||
|
|
||
| api_key = args.api_key | ||
|
|
||
| # --- Start IaaS stack --- | ||
| stack_procs, iaas_url, ext_proc_port = start_iaas_stack(llm_port) | ||
| processes.extend(stack_procs) | ||
|
|
||
| # --- Run IaaS direct tests --- | ||
| check_iaas_direct(iaas_url, llm_endpoint, model_name, api_key, result) | ||
|
|
||
| # --- Envoy tests --- | ||
| if args.skip_envoy: | ||
| result.skip("envoy_tests", "skipped via --skip-envoy") | ||
| elif not shutil.which("envoy"): | ||
| result.skip("envoy_tests", "envoy binary not found in PATH") | ||
| else: | ||
| from urllib.parse import urlparse | ||
| iaas_port = urlparse(iaas_url).port | ||
| envoy_result = start_envoy(ext_proc_port, iaas_port, llm_port) | ||
| if envoy_result is None: | ||
| result.fail("envoy_tests", "Envoy or ext_proc failed to start") | ||
| else: | ||
| envoy_proc, envoy_url, envoy_tmpdir, _ = envoy_result | ||
| processes.append(("envoy", envoy_proc)) | ||
| check_envoy_routed(envoy_url, iaas_url, llm_endpoint, model_name, api_key, result) | ||
|
|
||
| finally: | ||
| print("\nShutting down services...") | ||
| stop_processes(processes) | ||
| for server in servers: | ||
| server.shutdown() | ||
| if envoy_tmpdir: | ||
| import shutil as _shutil | ||
| _shutil.rmtree(envoy_tmpdir, ignore_errors=True) | ||
|
|
||
| success = result.summary() | ||
| sys.exit(0 if success else 1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.