Skip to content
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 routing config schema for app proxy #3221

Open
wants to merge 1 commit into
base: topic/improve-app-proxy-load-balancing
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/ai/backend/wsproxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclasses import dataclass
from pathlib import Path
from pprint import pformat
from typing import Annotated, Any
from typing import Annotated, Any, Literal

import click
from pydantic import (
Expand Down Expand Up @@ -201,14 +201,14 @@ def __get_pydantic_json_schema__(
)


class LogDriver(str, enum.Enum):
class LogDriver(enum.StrEnum):
CONSOLE = "console"
LOGSTASH = "logstash"
FILE = "file"
GRAYLOG = "graylog"


class LogstashProtocol(str, enum.Enum):
class LogstashProtocol(enum.StrEnum):
ZMQ_PUSH = "zmq.push"
ZMQ_PUB = "zmq.pub"
TCP = "tcp"
Expand Down Expand Up @@ -333,6 +333,31 @@ class DebugConfig(BaseSchema):
log_events: Annotated[bool, Field(default=False)]


class RoutingAlgorithmType(enum.StrEnum):
UNIFORM_WEIGHTED = "weighted-uniform-random"
WRR_SHUFFLED = "suffled-weighted-round-robin"


class WeightedRoundRobinParams(BaseSchema):
multiplier: int = Field(default=10)
shuffle_period: int = Field(default=5)


class RoutingConfigForUniform(BaseSchema, extra="forbid"):
type: Literal[RoutingAlgorithmType.UNIFORM_WEIGHTED] = RoutingAlgorithmType.UNIFORM_WEIGHTED


class RoutingConfigForWRR(BaseSchema, extra="forbid"):
type: Literal[RoutingAlgorithmType.WRR_SHUFFLED] = RoutingAlgorithmType.WRR_SHUFFLED
options: WeightedRoundRobinParams = Field(default=WeightedRoundRobinParams())


RoutingConfig = Annotated[
RoutingConfigForUniform | RoutingConfigForWRR,
Field(discriminator="type"),
]


class WSProxyConfig(BaseSchema):
ipc_base_path: Annotated[
Path,
Expand Down Expand Up @@ -404,6 +429,9 @@ class WSProxyConfig(BaseSchema):
protocol: Annotated[
ProxyProtocol, Field(default=ProxyProtocol.HTTP, description="Proxy protocol")
]
default_routing_config: RoutingConfig = Field(
default=RoutingConfigForWRR(), description="The default routing configuration"
)

jwt_encrypt_key: Annotated[
str, Field(examples=["50M3G00DL00KING53CR3T"], description="JWT encryption key")
Expand Down
Loading