Skip to content

Commit f7a8a51

Browse files
authored
Show targets with project prefix in dstack event (#3680)
Add the `<project>/` prefix to targets when they are not owned by the current project. Currently only relevant for imported fleets and their instances. Example: ``` [2026-03-19 14:40:38] [job my-job-1-0-0, instance main/shared-0] Job assigned to instance ```
1 parent 92e0993 commit f7a8a51

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/dstack/_internal/cli/commands/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _list(self, args: argparse.Namespace):
129129
events = reversed(self.api.client.events.list(ascending=False, **asdict(filters)))
130130
try:
131131
for event in events:
132-
print_event(event)
132+
print_event(current_project=self.api.project, event=event)
133133
except KeyboardInterrupt:
134134
pass
135135

src/dstack/_internal/cli/services/events.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from rich.text import Text
99

1010
from dstack._internal.cli.utils.common import LIVE_TABLE_PROVISION_INTERVAL_SECS, console
11-
from dstack._internal.core.models.events import Event, EventTargetType
11+
from dstack._internal.core.models.events import Event, EventTarget, EventTargetType
1212
from dstack._internal.server.schemas.events import LIST_EVENTS_DEFAULT_LIMIT
1313
from dstack.api.server._events import EventsAPIClient
1414

@@ -127,9 +127,9 @@ class _SeenEvent:
127127
recorded_at: datetime
128128

129129

130-
def print_event(event: Event) -> None:
130+
def print_event(current_project: str, event: Event) -> None:
131131
recorded_at = event.recorded_at.astimezone().strftime("%Y-%m-%d %H:%M:%S")
132-
targets = ", ".join(f"{target.type} {target.name}" for target in event.targets)
132+
targets = ", ".join(_format_target(current_project, target) for target in event.targets)
133133
message = [
134134
Text(f"[{recorded_at}]", style="log.time"),
135135
]
@@ -143,3 +143,14 @@ def print_event(event: Event) -> None:
143143
*message,
144144
soft_wrap=True, # Strictly one line per event. Allows for grepping
145145
)
146+
147+
148+
def _format_target(current_project: str, target: EventTarget) -> str:
149+
name = target.name
150+
if (
151+
target.project_name is not None
152+
and target.type != EventTargetType.PROJECT
153+
and target.project_name != current_project
154+
):
155+
name = f"{target.project_name}/{name}"
156+
return f"{target.type} {name}"

0 commit comments

Comments
 (0)