-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: Make topic explicit in message queue API (#358)
* Make topic explicit in message queue API * fix unit tests * more fixes * fix quotes in e2e code * better naming
- Loading branch information
Showing
39 changed files
with
470 additions
and
353 deletions.
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
103 changes: 103 additions & 0 deletions
103
e2e_tests/message_queues/message_queue_kafka/conftest.py
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import asyncio | ||
import multiprocessing | ||
import subprocess | ||
import time | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from llama_deploy import ( | ||
ControlPlaneConfig, | ||
WorkflowServiceConfig, | ||
deploy_core, | ||
deploy_workflow, | ||
) | ||
from llama_deploy.message_queues import KafkaMessageQueue, KafkaMessageQueueConfig | ||
|
||
from .workflow import BasicWorkflow | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def kafka_service(): | ||
compose_file = Path(__file__).resolve().parent / "docker-compose.yml" | ||
proc = subprocess.Popen( | ||
["docker", "compose", "-f", f"{compose_file}", "up", "-d", "--wait"] | ||
) | ||
proc.communicate() | ||
yield | ||
subprocess.Popen(["docker", "compose", "-f", f"{compose_file}", "down"]) | ||
|
||
|
||
@pytest.fixture | ||
def mq(kafka_service): | ||
return KafkaMessageQueue(KafkaMessageQueueConfig()) | ||
|
||
|
||
def run_workflow_one(): | ||
asyncio.run( | ||
deploy_workflow( | ||
BasicWorkflow(timeout=10, name="Workflow one"), | ||
WorkflowServiceConfig( | ||
host="127.0.0.1", | ||
port=8003, | ||
service_name="basic", | ||
), | ||
ControlPlaneConfig(topic_namespace="core_one", port=8001), | ||
) | ||
) | ||
|
||
|
||
def run_workflow_two(): | ||
asyncio.run( | ||
deploy_workflow( | ||
BasicWorkflow(timeout=10, name="Workflow two"), | ||
WorkflowServiceConfig( | ||
host="127.0.0.1", | ||
port=8004, | ||
service_name="basic", | ||
), | ||
ControlPlaneConfig(topic_namespace="core_two", port=8002), | ||
) | ||
) | ||
|
||
|
||
def run_core_one(): | ||
asyncio.run( | ||
deploy_core( | ||
ControlPlaneConfig(topic_namespace="core_one", port=8001), | ||
KafkaMessageQueueConfig(), | ||
) | ||
) | ||
|
||
|
||
def run_core_two(): | ||
asyncio.run( | ||
deploy_core( | ||
ControlPlaneConfig(topic_namespace="core_two", port=8002), | ||
KafkaMessageQueueConfig(), | ||
) | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def control_planes(kafka_service): | ||
p1 = multiprocessing.Process(target=run_core_one) | ||
p1.start() | ||
|
||
p2 = multiprocessing.Process(target=run_core_two) | ||
p2.start() | ||
|
||
time.sleep(3) | ||
|
||
p3 = multiprocessing.Process(target=run_workflow_one) | ||
p3.start() | ||
|
||
p4 = multiprocessing.Process(target=run_workflow_two) | ||
p4.start() | ||
|
||
yield | ||
|
||
p1.kill() | ||
p2.kill() | ||
p3.kill() | ||
p4.kill() |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from llama_index.core.workflow import Context, StartEvent, StopEvent, Workflow, step | ||
|
||
|
||
class BasicWorkflow(Workflow): | ||
def __init__(self, *args, **kwargs): | ||
self._name = kwargs.pop("name") | ||
super().__init__(*args, **kwargs) | ||
|
||
@step() | ||
async def run_step(self, ctx: Context, ev: StartEvent) -> StopEvent: | ||
received = ev.get("arg") | ||
return StopEvent(result=f"{self._name} received {received}") |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from llama_deploy.control_plane.base import BaseControlPlane | ||
from llama_deploy.control_plane.server import ControlPlaneServer, ControlPlaneConfig | ||
from .base import BaseControlPlane | ||
from .config import ControlPlaneConfig | ||
from .server import ControlPlaneServer | ||
|
||
__all__ = ["BaseControlPlane", "ControlPlaneServer", "ControlPlaneConfig"] |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import List | ||
|
||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class ControlPlaneConfig(BaseSettings): | ||
"""Control plane configuration.""" | ||
|
||
model_config = SettingsConfigDict( | ||
env_prefix="CONTROL_PLANE_", arbitrary_types_allowed=True | ||
) | ||
|
||
services_store_key: str = "services" | ||
tasks_store_key: str = "tasks" | ||
session_store_key: str = "sessions" | ||
step_interval: float = 0.1 | ||
host: str = "127.0.0.1" | ||
port: int = 8000 | ||
internal_host: str | None = None | ||
internal_port: int | None = None | ||
running: bool = True | ||
cors_origins: List[str] | None = None | ||
topic_namespace: str = "llama_deploy" | ||
|
||
@property | ||
def url(self) -> str: | ||
if self.port: | ||
return f"http://{self.host}:{self.port}" | ||
else: | ||
return f"http://{self.host}" |
Oops, something went wrong.