Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.

Commit 463c8fc

Browse files
authored
fix: Remove unnecessary protocol arg in the "app" command (#156)
* The "preopen" behavior is implemented by the manager and the client should not specify it. * "tcppproxy" and "httpproxy" are the only API endpoints available. * It is safe to assume the default protocol is "tcp" because internally both "tcp" and "http" proxies have the same implementation that transparently sends/recevies the TCP stream packets via the tunnel.
1 parent b9ebd78 commit 463c8fc

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

changes/156.fix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the legacy `-p/--protocol` option from the `app` command sicne it now works as the TCP protocol always

src/ai/backend/client/cli/app.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class WSProxy:
2424
__slots__ = (
2525
'api_session', 'session_name',
26-
'app_name', 'protocol',
26+
'app_name',
2727
'args', 'envs',
2828
'reader', 'writer',
2929
)
@@ -33,7 +33,6 @@ def __init__(
3333
api_session: AsyncSession,
3434
session_name: str,
3535
app_name: str,
36-
protocol: str,
3736
args: MutableMapping[str, Union[None, str, List[str]]],
3837
envs: MutableMapping[str, str],
3938
reader: asyncio.StreamReader,
@@ -42,15 +41,14 @@ def __init__(
4241
self.api_session = api_session
4342
self.session_name = session_name
4443
self.app_name = app_name
45-
self.protocol = protocol
4644
self.args = args
4745
self.envs = envs
4846
self.reader = reader
4947
self.writer = writer
5048

5149
async def run(self) -> None:
5250
prefix = get_naming(self.api_session.api_version, 'path')
53-
path = f"/stream/{prefix}/{self.session_name}/{self.protocol}proxy"
51+
path = f"/stream/{prefix}/{self.session_name}/tcpproxy"
5452
params = {'app': self.app_name}
5553

5654
if len(self.args.keys()) > 0:
@@ -145,7 +143,7 @@ def __init__(
145143
session_name: str,
146144
app_name: str,
147145
*,
148-
protocol: str = 'http',
146+
protocol: str = 'tcp',
149147
args: Sequence[str] = None,
150148
envs: Sequence[str] = None,
151149
) -> None:
@@ -192,10 +190,15 @@ async def handle_connection(
192190
writer: asyncio.StreamWriter,
193191
) -> None:
194192
assert self.api_session is not None
195-
p = WSProxy(self.api_session, self.session_name,
196-
self.app_name, self.protocol,
197-
self.args, self.envs,
198-
reader, writer)
193+
p = WSProxy(
194+
self.api_session,
195+
self.session_name,
196+
self.app_name,
197+
self.args,
198+
self.envs,
199+
reader,
200+
writer,
201+
)
199202
try:
200203
await p.run()
201204
except asyncio.CancelledError:
@@ -258,15 +261,13 @@ async def __aexit__(self, *exc_info) -> None:
258261
@main.command()
259262
@click.argument('session_name', type=str, metavar='NAME')
260263
@click.argument('app', type=str)
261-
@click.option('-p', '--protocol', type=click.Choice(['http', 'tcp', 'preopen']), default='http',
262-
help='The application-level protocol to use.')
263264
@click.option('-b', '--bind', type=str, default='127.0.0.1:8080', metavar='[HOST:]PORT',
264265
help='The IP/host address and the port number to bind this proxy.')
265266
@click.option('--arg', type=str, multiple=True, metavar='"--option <value>"',
266267
help='Add additional argument when starting service.')
267268
@click.option('-e', '--env', type=str, multiple=True, metavar='"ENVNAME=envvalue"',
268269
help='Add additional environment variable when starting service.')
269-
def app(session_name, app, protocol, bind, arg, env):
270+
def app(session_name, app, bind, arg, env):
270271
"""
271272
Run a local proxy to a service provided by Backend.AI compute sessions.
272273
@@ -287,7 +288,7 @@ def app(session_name, app, protocol, bind, arg, env):
287288
proxy_ctx = ProxyRunnerContext(
288289
host, port,
289290
session_name, app,
290-
protocol=protocol,
291+
protocol='tcp',
291292
args=arg,
292293
envs=env,
293294
)

0 commit comments

Comments
 (0)