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

Split AppList into client and internal web RPCs #2073

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion modal/app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from .object import _get_environment_name


async def _list_apps(env: Optional[str] = None, client: Optional[_Client] = None) -> List[api_pb2.AppStats]:
async def _list_apps(
env: Optional[str] = None, client: Optional[_Client] = None
) -> List[api_pb2.AppListResponse.AppListItem]:
"""List apps in a given Modal environment."""
if client is None:
client = await _Client.from_env()
Expand Down
18 changes: 1 addition & 17 deletions modal/cli/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright Modal Labs 2022
import time
from typing import List, Optional, Union

import typer
Expand Down Expand Up @@ -44,23 +43,8 @@ async def list(env: Optional[str] = ENV_OPTION, json: bool = False):
"Stopped at",
]
rows: List[List[Union[Text, str]]] = []
apps: List[api_pb2.AppStats] = await _list_apps(env)
now = time.time()
apps: List[api_pb2.AppListResponse.AppListItem] = await _list_apps(env)
for app_stats in apps:
if (
# Previously, all deployed objects (Dicts, Volumes, etc.) created an entry in the App table.
# We are waiting to roll off support for old clients before we can clean up the database.
# Until then, we filter deployed "single-object apps" from this output based on the object entity.
(app_stats.object_entity and app_stats.object_entity != "ap")
# AppList always returns up to the 250 most-recently stopped apps, which is a lot for the CLI
# (it is also used in the web interface, where apps are organized by tabs and paginated).
# So we semi-arbitrarily limit the stopped apps to those stopped within the past 2 hours.
or (
app_stats.state in {api_pb2.AppState.APP_STATE_STOPPED} and (now - app_stats.stopped_at) > (2 * 60 * 60)
)
):
continue

state = APP_STATE_TO_MESSAGE.get(app_stats.state, Text("unknown", style="gray"))
rows.append(
[
Expand Down
23 changes: 10 additions & 13 deletions modal_proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,16 @@ message AppListRequest {
}

message AppListResponse {
repeated AppStats apps = 1;
message AppListItem {
string app_id = 1;
string description = 3;
AppState state = 4;
double created_at = 5;
double stopped_at = 6;
int32 n_running_tasks = 8;
string name = 10;
}
repeated AppListItem apps = 1;
}

message AppLookupObjectRequest {
Expand Down Expand Up @@ -342,18 +351,6 @@ message AppSetObjectsRequest {
string single_object_id = 6;
}

message AppStats {
string app_id = 1;
string description = 3;
AppState state = 4;
double created_at = 5;
double stopped_at = 6;
int32 n_running_tasks = 8;
string object_entity = 9;
string name = 10;
double deployed_at = 11;
}

message AppStopRequest {
string app_id = 1 [ (modal.options.audit_target_attr) = true ];
AppStopSource source = 2;
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async def AppList(self, stream):
apps = []
for app_name, app_id in self.deployed_apps.items():
apps.append(
api_pb2.AppStats(
api_pb2.AppListResponse.AppListItem(
name=app_name,
description=app_name,
app_id=app_id,
Expand Down
Loading