Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions frontend/src/pages/Events/List/hooks/useColumnDefinitions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ export const useColumnsDefinitions = () => {
</div>
);

case 'secret':
return (
<div>
Secret{' '}
{target.project_name && (
<NavigateLink href={ROUTES.PROJECT.DETAILS.FORMAT(target.project_name)}>
{target.project_name}
</NavigateLink>
)}
/{target.name}
</div>
);

default:
return '---';
}
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/pages/Events/List/hooks/useFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type RequestParamsKeys = keyof Pick<
| 'target_jobs'
| 'target_volumes'
| 'target_gateways'
| 'target_secrets'
| 'within_projects'
| 'within_fleets'
| 'within_runs'
Expand All @@ -35,6 +36,7 @@ const filterKeys: Record<string, RequestParamsKeys> = {
TARGET_JOBS: 'target_jobs',
TARGET_VOLUMES: 'target_volumes',
TARGET_GATEWAYS: 'target_gateways',
TARGET_SECRETS: 'target_secrets',
WITHIN_PROJECTS: 'within_projects',
WITHIN_FLEETS: 'within_fleets',
WITHIN_RUNS: 'within_runs',
Expand All @@ -53,6 +55,7 @@ const multipleChoiseKeys: RequestParamsKeys[] = [
'target_jobs',
'target_volumes',
'target_gateways',
'target_secrets',
'within_projects',
'within_fleets',
'within_runs',
Expand All @@ -69,6 +72,7 @@ const targetTypes = [
{ label: 'Job', value: 'job' },
{ label: 'Volume', value: 'volume' },
{ label: 'Gateway', value: 'gateway' },
{ label: 'Secret', value: 'secret' },
];

export const useFilters = () => {
Expand Down Expand Up @@ -171,6 +175,11 @@ export const useFilters = () => {
operators: ['='],
propertyLabel: 'Target gateways',
},
{
key: filterKeys.TARGET_SECRETS,
operators: ['='],
propertyLabel: 'Target secrets',
},

{
key: filterKeys.WITHIN_PROJECTS,
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/types/event.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare type TEventTargetType = 'project' | 'user' | 'fleet' | 'instance' | 'run' | 'job' | 'volume' | 'gateway';
declare type TEventTargetType = 'project' | 'user' | 'fleet' | 'instance' | 'run' | 'job' | 'volume' | 'gateway' | 'secret';

declare type TEventListRequestParams = Omit<TBaseRequestListParams, 'prev_created_at'> & {
prev_recorded_at?: string;
Expand All @@ -10,6 +10,7 @@ declare type TEventListRequestParams = Omit<TBaseRequestListParams, 'prev_create
target_jobs?: string[];
target_volumes?: string[];
target_gateways?: string[];
target_secrets?: string[];
within_projects?: string[];
within_fleets?: string[];
within_runs?: string[];
Expand All @@ -18,7 +19,7 @@ declare type TEventListRequestParams = Omit<TBaseRequestListParams, 'prev_create
};

declare interface IEventTarget {
type: 'project' | 'user' | 'fleet' | 'instance' | 'run' | 'job' | 'volume' | 'gateway';
type: 'project' | 'user' | 'fleet' | 'instance' | 'run' | 'job' | 'volume' | 'gateway' | 'secret';
project_id?: string;
project_name?: string;
id: string;
Expand Down
11 changes: 11 additions & 0 deletions src/dstack/_internal/cli/commands/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def _register(self):
dest="target_gateways",
help="Only show events that target the specified gateways",
)
target_filters_group.add_argument(
"--target-secret",
action="append",
metavar="NAME",
dest="target_secrets",
help="Only show events that target the specified secrets",
)
within_filters_group = parser.add_mutually_exclusive_group()
within_filters_group.add_argument(
"--within-fleet",
Expand Down Expand Up @@ -139,6 +146,10 @@ def _build_filters(args: argparse.Namespace, api: Client) -> EventListFilters:
" Update the server to 0.20.7 or higher or remove --target-gateway."
)
filters.target_gateways.append(id)
elif args.target_secrets:
filters.target_secrets = [
api.client.secrets.get(api.project, name=name).id for name in args.target_secrets
]

if args.within_fleets:
filters.within_fleets = [
Expand Down
1 change: 1 addition & 0 deletions src/dstack/_internal/cli/services/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EventListFilters:
target_runs: Optional[list[uuid.UUID]] = None
target_volumes: Optional[list[uuid.UUID]] = None
target_gateways: Optional[list[uuid.UUID]] = None
target_secrets: Optional[list[uuid.UUID]] = None
within_projects: Optional[list[uuid.UUID]] = None
within_fleets: Optional[list[uuid.UUID]] = None
within_runs: Optional[list[uuid.UUID]] = None
Expand Down
1 change: 1 addition & 0 deletions src/dstack/_internal/core/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EventTargetType(str, Enum):
JOB = "job"
VOLUME = "volume"
GATEWAY = "gateway"
SECRET = "secret"


class EventTarget(CoreModel):
Expand Down
1 change: 1 addition & 0 deletions src/dstack/_internal/server/routers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def list_events(
target_jobs=body.target_jobs,
target_volumes=body.target_volumes,
target_gateways=body.target_gateways,
target_secrets=body.target_secrets,
within_projects=body.within_projects,
within_fleets=body.within_fleets,
within_runs=body.within_runs,
Expand Down
11 changes: 11 additions & 0 deletions src/dstack/_internal/server/schemas/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ class ListEventsRequest(CoreModel):
max_items=MAX_FILTER_ITEMS,
),
] = None
target_secrets: Annotated[
Optional[list[uuid.UUID]],
Field(
description=(
"List of secret IDs."
" The response will only include events that target the specified secrets"
),
min_items=MIN_FILTER_ITEMS,
max_items=MAX_FILTER_ITEMS,
),
] = None
within_projects: Annotated[
Optional[list[uuid.UUID]],
Field(
Expand Down
17 changes: 17 additions & 0 deletions src/dstack/_internal/server/services/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
MemberModel,
ProjectModel,
RunModel,
SecretModel,
UserModel,
VolumeModel,
)
Expand Down Expand Up @@ -93,6 +94,7 @@ def from_model(
JobModel,
ProjectModel,
RunModel,
SecretModel,
UserModel,
VolumeModel,
],
Expand Down Expand Up @@ -139,6 +141,13 @@ def from_model(
id=model.id,
name=model.run_name,
)
if isinstance(model, SecretModel):
return Target(
type=EventTargetType.SECRET,
project_id=model.project_id or model.project.id,
id=model.id,
name=model.name,
)
if isinstance(model, UserModel):
return Target(
type=EventTargetType.USER,
Expand Down Expand Up @@ -232,6 +241,7 @@ async def list_events(
target_jobs: Optional[list[uuid.UUID]],
target_volumes: Optional[list[uuid.UUID]],
target_gateways: Optional[list[uuid.UUID]],
target_secrets: Optional[list[uuid.UUID]],
within_projects: Optional[list[uuid.UUID]],
within_fleets: Optional[list[uuid.UUID]],
within_runs: Optional[list[uuid.UUID]],
Expand Down Expand Up @@ -315,6 +325,13 @@ async def list_events(
EventTargetModel.entity_id.in_(target_gateways),
)
)
if target_secrets is not None:
target_filters.append(
and_(
EventTargetModel.entity_type == EventTargetType.SECRET,
EventTargetModel.entity_id.in_(target_secrets),
)
)
if within_projects is not None:
target_filters.append(EventTargetModel.entity_project_id.in_(within_projects))
if within_fleets is not None:
Expand Down
2 changes: 2 additions & 0 deletions src/dstack/api/server/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def list(
# NOTE: New parameters go here. Avoid positional parameters, they can break compatibility.
target_volumes: Optional[list[UUID]] = None,
target_gateways: Optional[list[UUID]] = None,
target_secrets: Optional[list[UUID]] = None,
) -> list[Event]:
if prev_recorded_at is not None:
# Time zones other than UTC are misinterpreted by the server:
Expand All @@ -45,6 +46,7 @@ def list(
target_jobs=target_jobs,
target_volumes=target_volumes,
target_gateways=target_gateways,
target_secrets=target_secrets,
within_projects=within_projects,
within_fleets=within_fleets,
within_runs=within_runs,
Expand Down