mirror of
https://github.com/katanemo/plano.git
synced 2026-05-04 21:32:43 +02:00
add listener routes for internal service proxying (#793)
This commit is contained in:
parent
198c912202
commit
c2480639b2
13 changed files with 219 additions and 2 deletions
|
|
@ -145,6 +145,41 @@ def validate_and_render_schema():
|
|||
inferred_clusters[name]["port"],
|
||||
) = get_endpoint_and_port(endpoint, protocol)
|
||||
|
||||
# Process routes in listeners and generate clusters for upstream services
|
||||
for listener in listeners:
|
||||
for route in listener.get("routes", []):
|
||||
path_prefix = route.get("path_prefix", "")
|
||||
upstream = route.get("upstream", "")
|
||||
if not path_prefix or not upstream:
|
||||
continue
|
||||
|
||||
urlparse_result = urlparse(upstream)
|
||||
if not urlparse_result.scheme or not urlparse_result.hostname:
|
||||
raise Exception(
|
||||
f"Invalid upstream URL '{upstream}' in route for listener '{listener.get('name')}'. "
|
||||
f"Must be a valid URL with scheme (http/https) and hostname."
|
||||
)
|
||||
|
||||
protocol = urlparse_result.scheme
|
||||
port = urlparse_result.port
|
||||
if port is None:
|
||||
port = 80 if protocol == "http" else 443
|
||||
|
||||
sanitized_prefix = (
|
||||
path_prefix.strip("/").replace("/", "_").replace("-", "_")
|
||||
)
|
||||
listener_name = listener.get("name", "unknown").replace(" ", "_")
|
||||
cluster_name = f"route_{listener_name}_{sanitized_prefix}"
|
||||
|
||||
route["cluster_name"] = cluster_name
|
||||
|
||||
if cluster_name not in inferred_clusters:
|
||||
inferred_clusters[cluster_name] = {
|
||||
"endpoint": urlparse_result.hostname,
|
||||
"port": port,
|
||||
"protocol": protocol,
|
||||
}
|
||||
|
||||
print("defined clusters from plano_config.yaml: ", json.dumps(inferred_clusters))
|
||||
|
||||
if "prompt_targets" in config_yaml:
|
||||
|
|
|
|||
|
|
@ -289,6 +289,63 @@ llm_providers:
|
|||
tracing:
|
||||
random_sampling: 100
|
||||
|
||||
""",
|
||||
},
|
||||
{
|
||||
"id": "routes_with_agents",
|
||||
"expected_error": None,
|
||||
"plano_config": """
|
||||
version: v0.3.0
|
||||
|
||||
agents:
|
||||
- id: test_agent
|
||||
url: http://localhost:10500
|
||||
|
||||
listeners:
|
||||
- type: agent
|
||||
name: agent_1
|
||||
port: 8001
|
||||
routes:
|
||||
- path_prefix: /traces
|
||||
upstream: http://localhost:16686
|
||||
agents:
|
||||
- id: test_agent
|
||||
description: a test agent
|
||||
|
||||
- type: model
|
||||
name: model_listener
|
||||
port: 12000
|
||||
|
||||
model_providers:
|
||||
- model: openai/gpt-4o
|
||||
access_key: $OPENAI_API_KEY
|
||||
|
||||
""",
|
||||
},
|
||||
{
|
||||
"id": "routes_only_listener",
|
||||
"expected_error": None,
|
||||
"plano_config": """
|
||||
version: v0.3.0
|
||||
|
||||
listeners:
|
||||
- type: agent
|
||||
name: observability
|
||||
port: 8002
|
||||
routes:
|
||||
- path_prefix: /traces
|
||||
upstream: http://localhost:16686
|
||||
- path_prefix: /metrics
|
||||
upstream: http://localhost:9090
|
||||
|
||||
- type: model
|
||||
name: model_listener
|
||||
port: 12000
|
||||
|
||||
model_providers:
|
||||
- model: openai/gpt-4o
|
||||
access_key: $OPENAI_API_KEY
|
||||
|
||||
""",
|
||||
},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue