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
16 changes: 13 additions & 3 deletions app/src/ActiveServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export const ActiveServices = () => {
{" / "}
{svc.state === "RUNNING" ? (
<a
href={`/services/${encodeURIComponent(experimentId)}/${encodeURIComponent(id)}/`}
href={`/services/${encodeURIComponent(
experimentId,
)}/${encodeURIComponent(id)}/${
svc.runId ? `?runId=${encodeURIComponent(svc.runId)}` : ""
}`}
target="_blank"
rel="noreferrer"
title={svc.description || "Open the service"}
Expand All @@ -69,7 +73,13 @@ export const ActiveServices = () => {
className="p-0 ms-2"
title="Logs"
onClick={() =>
setLogTarget({ kind: "service", experimentId, serviceId: id, title: id })
setLogTarget({
kind: "service",
experimentId,
serviceId: id,
runId: svc.runId,
title: id,
})
}
>
<i className="fas fa-file-lines" />
Expand All @@ -79,7 +89,7 @@ export const ActiveServices = () => {
variant="link"
className="p-0 ms-2 text-danger"
title="Stop"
onClick={() => client.service_stop(experimentId, id)}
onClick={() => client.service_stop(experimentId, id, svc.runId)}
>
<i className="fas fa-stop" />
</Button>
Expand Down
4 changes: 3 additions & 1 deletion app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ export default () => {
{/* The run below the experiment, so that both have room */}
<div className="d-flex flex-column gap-1 ms-3">
{isScoped(view) && <ExperimentSelector />}
{(view === "tasks" || view === "graph") && <RunSelector />}
{(view === "tasks" || view === "graph" || view === "services") && (
<RunSelector />
)}
</div>
<Button
variant="outline-light"
Expand Down
48 changes: 28 additions & 20 deletions app/src/Experiments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMessages } from "./ui/messages";
import { clearOnEscape, useShortcuts } from "./shortcuts";
import { KeyHints, SortHeader, sortedMessage } from "./ui/sorting";
import { ExperimentTags } from "./ui/tags";
import { CollapseExpandIcon } from "./ui/icons";

// Status computed by the server, shared with the TUI (status_category)
const STATUS_INFO: { [key: string]: { icon: string; color: string } } = {
Expand Down Expand Up @@ -242,6 +243,18 @@ export default ({ onOpen }: { onOpen: (id: string) => void }) => {
[shown, grouping],
);

const allCollapsed =
groups !== null && groups.length > 0 && groups.every((g) => collapsed.has(g.name));

function toggleAllGroups() {
if (groups === null) return;
if (allCollapsed) {
setCollapsed(new Set());
} else {
setCollapsed(new Set(groups.map((g) => g.name)));
}
}

if (experiments.ids.length === 0) {
return (
<p className="text-muted mt-3">
Expand Down Expand Up @@ -343,6 +356,21 @@ export default ({ onOpen }: { onOpen: (id: string) => void }) => {
<h5 className="mb-3">Experiments</h5>

<div className="d-flex align-items-center flex-wrap gap-2 mb-1">
{groups !== null && (
<Button
variant="outline-secondary"
title={allCollapsed ? "Expand all groups" : "Collapse all groups"}
aria-label={allCollapsed ? "Expand all groups" : "Collapse all groups"}
onClick={toggleAllGroups}
style={{
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
}}
>
<CollapseExpandIcon collapsed={allCollapsed} />
</Button>
)}
<Form.Control
id="searchexperiments"
ref={searchInput}
Expand Down Expand Up @@ -392,26 +420,6 @@ export default ({ onOpen }: { onOpen: (id: string) => void }) => {
</option>
))}
</Form.Select>
{groups !== null && (
<>
<Button
size="sm"
variant="outline-secondary"
title="Expand all groups"
onClick={() => setCollapsed(new Set())}
>
<i className="fas fa-angles-down" />
</Button>
<Button
size="sm"
variant="outline-secondary"
title="Collapse all groups"
onClick={() => setCollapsed(new Set(groups.map((g) => g.name)))}
>
<i className="fas fa-angles-up" />
</Button>
</>
)}
</div>
<KeyHints
hints={[
Expand Down
15 changes: 11 additions & 4 deletions app/src/LogViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ type Stream = "stdout" | "stderr";

export type LogTarget =
| { kind: "job"; taskId: string; jobId: string; title?: string }
| { kind: "service"; experimentId: string; serviceId: string; title?: string }
| {
kind: "service";
experimentId: string;
serviceId: string;
runId?: string | null;
title?: string;
}
| { kind: "experimaestro"; title?: string };

function baseUrl(target: LogTarget, stream: Stream): string {
Expand All @@ -23,9 +29,10 @@ function baseUrl(target: LogTarget, stream: Stream): string {
if (target.kind === "experimaestro") {
return `/api/logs/experimaestro`;
}
return `/api/services/${encodeURIComponent(target.experimentId)}/${encodeURIComponent(
target.serviceId,
)}/logs/${stream}`;
const base = `/api/services/${encodeURIComponent(
target.experimentId,
)}/${encodeURIComponent(target.serviceId)}/logs/${stream}`;
return target.runId ? `${base}?runId=${encodeURIComponent(target.runId)}` : base;
}

const POLL_MS = 1500;
Expand Down
7 changes: 5 additions & 2 deletions app/src/RunSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ export const RunSelector: React.FC = () => {
const navigate = useNavigate();
const route = useAppSelector((s) => s.db.route);
const currentExperiment = useAppSelector((s) => s.db.currentExperiment);
const currentRunId = useAppSelector((s) =>
currentExperiment ? s.db.experiments.byId[currentExperiment]?.current_run_id : null
);
const currentRun = useAppSelector((s) => s.db.currentRun);
const runs = useAppSelector((s) => s.db.runs);

// Fetch the run history whenever the selected experiment changes
// Fetch the run history whenever the selected experiment or its current run changes
useEffect(() => {
if (currentExperiment) {
client.request_runs(currentExperiment);
}
}, [currentExperiment]);
}, [currentExperiment, currentRunId]);

if (!currentExperiment || runs.length <= 1) {
return null;
Expand Down
30 changes: 21 additions & 9 deletions app/src/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ const STATE_COLOR: { [key: string]: string } = {
const Services = () => {
const services = useAppSelector((state) => state.db.services);
const currentExperiment = useAppSelector((state) => state.db.currentExperiment);
const currentRun = useAppSelector((state) => state.db.currentRun);
const exp = useAppSelector((state) =>
currentExperiment ? state.db.experiments.byId[currentExperiment] : null
);
const currentRunId = exp?.current_run_id;
const effectiveRunId = currentRun || currentRunId || null;
const connectionStatus = useAppSelector((state) => state.db.connectionStatus);
const [logTarget, setLogTarget] = useState<LogTarget>();

// Only the services of the selected experiment are requested
// Only the services of the selected experiment and run are requested
useEffect(() => {
if (connectionStatus === "connected" && currentExperiment !== null)
client.request_services(currentExperiment);
}, [connectionStatus, currentExperiment]);
client.request_services(currentExperiment, currentRun);
}, [connectionStatus, currentExperiment, currentRun, currentRunId]);

const keys = services.ids.filter(
(key) => services.byId[key].experimentId === currentExperiment,
);
const keys = services.ids.filter((key) => {
const svc = services.byId[key];
if (svc.experimentId !== currentExperiment) return false;
if (effectiveRunId && svc.runId && svc.runId !== effectiveRunId) return false;
return true;
});

return (
<div className="mt-3">
Expand Down Expand Up @@ -81,7 +90,9 @@ const Services = () => {
className="me-1"
href={`/services/${encodeURIComponent(
experimentId,
)}/${encodeURIComponent(id)}/`}
)}/${encodeURIComponent(id)}/${
svc.runId ? `?runId=${encodeURIComponent(svc.runId)}` : ""
}`}
target="_blank"
>
Open
Expand All @@ -91,7 +102,7 @@ const Services = () => {
size="sm"
variant="outline-danger"
className="me-1"
onClick={() => client.service_stop(experimentId, id)}
onClick={() => client.service_stop(experimentId, id, svc.runId)}
>
Stop
</Button>
Expand All @@ -101,7 +112,7 @@ const Services = () => {
size="sm"
variant="outline-success"
className="me-1"
onClick={() => client.service_start(experimentId, id)}
onClick={() => client.service_start(experimentId, id, svc.runId)}
>
Start
</Button>
Expand All @@ -114,6 +125,7 @@ const Services = () => {
kind: "service",
experimentId,
serviceId: id,
runId: svc.runId,
title: id,
})
}
Expand Down
48 changes: 28 additions & 20 deletions app/src/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useAppSelector, useNavigate } from "./store";
import { useShortcuts } from "./shortcuts";
import FilterInput from "./FilterInput";
import { KeyHints, SortHeader, SortLabel, sortedMessage } from "./ui/sorting";
import { CollapseExpandIcon } from "./ui/icons";

type SortKey = "status" | "task" | "date" | "name";

Expand Down Expand Up @@ -332,6 +333,18 @@ export default () => {
setCollapsed(new Set());
}

const allCollapsed =
groups !== null && groups.length > 0 && groups.every((g) => collapsed.has(g.key));

function toggleAllGroups() {
if (groups === null) return;
if (allCollapsed) {
setCollapsed(new Set());
} else {
setCollapsed(new Set(groups.map((g) => g.key)));
}
}

// --- Job actions

function cancelConfirm() {
Expand Down Expand Up @@ -374,6 +387,21 @@ export default () => {
flexWrap: "wrap",
}}
>
{groups !== null && (
<Button
variant="outline-secondary"
title={allCollapsed ? "Expand all groups" : "Collapse all groups"}
aria-label={allCollapsed ? "Expand all groups" : "Collapse all groups"}
onClick={toggleAllGroups}
style={{
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
}}
>
<CollapseExpandIcon collapsed={allCollapsed} />
</Button>
)}
<Form.Group style={{ flex: "1 1 24rem" }}>
<Form.Label htmlFor="searchjobs">Filter</Form.Label>
<FilterInput
Expand Down Expand Up @@ -477,26 +505,6 @@ export default () => {
</Form.Select>
</Form.Group>
)}
{groups !== null && (
<>
<Button
size="sm"
variant="outline-secondary"
title="Expand all groups"
onClick={() => setCollapsed(new Set())}
>
<i className="fas fa-angles-down" />
</Button>
<Button
size="sm"
variant="outline-secondary"
title="Collapse all groups"
onClick={() => setCollapsed(new Set(groups.map((g) => g.key)))}
>
<i className="fas fa-angles-up" />
</Button>
</>
)}
</div>
{trimmedQuery && filterResult.error !== null ? (
<div className="small text-danger mt-1">{filterResult.error}</div>
Expand Down
18 changes: 12 additions & 6 deletions app/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ class Client {
}

// Services of an experiment (shown by the services page)
request_services(experimentId: string): void {
this.send("services", { experimentId });
request_services(experimentId: string, runId?: string | null): void {
const payload: any = { experimentId };
if (runId) payload.runId = runId;
this.send("services", payload);
}

request_runs(experimentId: string): void {
Expand Down Expand Up @@ -415,12 +417,16 @@ class Client {
this.send("orphans.delete");
}

service_start(experimentId: string, id: string): void {
this.send("service.start", { experimentId, id });
service_start(experimentId: string, id: string, runId?: string | null): void {
const payload: any = { experimentId, id };
if (runId) payload.runId = runId;
this.send("service.start", payload);
}

service_stop(experimentId: string, id: string): void {
this.send("service.stop", { experimentId, id });
service_stop(experimentId: string, id: string, runId?: string | null): void {
const payload: any = { experimentId, id };
if (runId) payload.runId = runId;
this.send("service.stop", payload);
}

quit(): void {
Expand Down
Loading
Loading