feat: Dynamic socket-name URL routing (/{service}/{socket_name}/*) #16
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_proxy#16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
hero_proxy currently routes
/{service}/*and picks a socket viafind_socket_for()which prefersui.sockoverrpc.sock. There's no way to target a specific socket via URL.For multi-node hero_compute, the explorer needs to reach
rpc.sockandexplorer_rpc.sockon remote nodes — notui.sock.Solution: Dynamic filesystem lookup
No hardcoded socket types. Just check if the second URL segment matches a
.sockfile in the service directory.Given:
Routing:
The logic is one filesystem check:
URL Processing
/{service}/{socket_name}/{rest}$HERO_SOCKET_DIR/{service}/{socket_name}.sockexists/{service}/{socket_name}, forward/{rest}/{service}/*→find_socket_for())Prefix header:
X-Forwarded-Prefix: /{service}/{socket_name}Why Dynamic
explorer_rpc.sock) that don't fit predefined types.sockfile is automatically routableExamples
Related
feat: Add socket-type URL routing (/{service}/{socket_type}/*)to feat: Dynamic socket-name URL routing (/{service}/{socket_name}/*)Current Behavior vs Needed Behavior
Current
URL format:
/{service}/*hero_proxy extracts the first path segment as the service name and calls
find_socket_for(service)which searches in this priority order:ui.sock(human-facing dashboard)web_*.sock(first alphabetically)rest.sockrpc.sockThis means every request to a service always lands on
ui.sockif it exists, regardless of what the caller actually wants.Example — the problem:
There is no way for a remote node to reach
rpc.sockorexplorer_rpc.sockthrough hero_proxy.Needed
URL format:
/{service}/{socket_name}/*with fallback to/{service}/*hero_proxy extracts the first TWO path segments. If
$HERO_SOCKET_DIR/{service}/{socket_name}.sockexists on disk, route to it directly. Otherwise fall back to currentfind_socket_for()behavior.Example — the fix:
This is fully backward compatible — existing single-segment URLs still work. New two-segment URLs give callers explicit control over which socket to reach.
Implementation Summary
Changes Made
crates/hero_proxy_server/src/config.rsfind_socket_by_name(service, socket_name)— direct filesystem lookup for$HERO_SOCKET_DIR/{service}/{socket_name}.sockcrates/hero_proxy_server/src/proxy.rsextract_two_segment_prefix()— parses/{service}/{socket_name}/{rest}from URL pathproxy_handler— tries two-segment routing first (checks if.sockfile exists on disk), falls back to existingfind_socket_for()single-segment routingcrates/hero_proxy_tests/src/lib.rscreate_mock_backend()to use per-service directory layout ({service}/rpc.sock) instead of flat legacy layout ({service}.sock)Test Results
-D warnings)PR
#17
Implementation committed:
4918fc3