Skip to content

Commit

Permalink
[containerapp] az containerapp logs/exec: Fix "KeyError" Bug (#5527)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrawnSC authored Nov 8, 2022
1 parent 102f3b7 commit 2ce21e8
Show file tree
Hide file tree
Showing 8 changed files with 1,698 additions and 3,543 deletions.
4 changes: 4 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.3.14
++++++
* 'az containerapp logs show'/'az containerapp exec': Fix "KeyError" bug

0.3.13
++++++
* 'az containerapp compose create': Migrated from containerapp-compose extension
Expand Down
15 changes: 13 additions & 2 deletions src/containerapp/azext_containerapp/_ssh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import websocket

from knack.log import get_logger
from azure.cli.core.azclierror import CLIInternalError
from azure.cli.core.azclierror import CLIInternalError, ValidationError
from azure.cli.core.commands.client_factory import get_subscription_id

from ._clients import ContainerAppClient
Expand Down Expand Up @@ -53,7 +53,8 @@ class WebSocketConnection:
def __init__(self, cmd, resource_group_name, name, revision, replica, container, startup_command):
token_response = ContainerAppClient.get_auth_token(cmd, resource_group_name, name)
self._token = token_response["properties"]["token"]
self._logstream_endpoint = token_response["properties"]["logStreamEndpoint"]
self._logstream_endpoint = self._get_logstream_endpoint(cmd, resource_group_name, name,
revision, replica, container)
self._url = self._get_url(cmd=cmd, resource_group_name=resource_group_name, name=name, revision=revision,
replica=replica, container=container, startup_command=startup_command)
self._socket = websocket.WebSocket(enable_multithread=True)
Expand All @@ -67,6 +68,16 @@ def __init__(self, cmd, resource_group_name, name, revision, replica, container,
self._windows_conout_mode = _get_conout_mode()
self._windows_conin_mode = _get_conin_mode()

@classmethod
def _get_logstream_endpoint(cls, cmd, resource_group_name, name, revision, replica, container):
containers = ContainerAppClient.get_replica(cmd,
resource_group_name,
name, revision, replica)["properties"]["containers"]
container_info = [c for c in containers if c["name"] == container]
if not container_info:
raise ValidationError(f"No such container: {container}")
return container_info[0]["logStreamEndpoint"]

def _get_url(self, cmd, resource_group_name, name, revision, replica, container, startup_command):
sub = get_subscription_id(cmd.cli_ctx)
base_url = self._logstream_endpoint
Expand Down
5 changes: 3 additions & 2 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2475,8 +2475,9 @@ def stream_containerapp_logs(cmd, resource_group_name, name, container=None, rev
sub = get_subscription_id(cmd.cli_ctx)
token_response = ContainerAppClient.get_auth_token(cmd, resource_group_name, name)
token = token_response["properties"]["token"]
logstream_endpoint = token_response["properties"]["logStreamEndpoint"]
base_url = logstream_endpoint[:logstream_endpoint.index("/subscriptions/")]

base_url = ContainerAppClient.show(cmd, resource_group_name, name)["properties"]["eventStreamEndpoint"]
base_url = base_url[:base_url.index("/subscriptions/")]

if kind == LOG_TYPE_CONSOLE:
url = (f"{base_url}/subscriptions/{sub}/resourceGroups/{resource_group_name}/containerApps/{name}"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_containerapp_env_e2e(self, resource_group):
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="australiaeast")
@StorageAccountPreparer(location="australiaeast")
@live_only() # fails the CI but passes locally
def test_containerapp_env_logs_e2e(self, resource_group, storage_account):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.

VERSION = '0.3.13'
VERSION = '0.3.14'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down

0 comments on commit 2ce21e8

Please sign in to comment.