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

feat: use data-service sessions endpoint #3296

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
renku-notebooks: ${{ steps.deploy-comment.outputs.renku-notebooks}}
renku-data-services: ${{ steps.deploy-comment.outputs.renku-data-services}}
amalthea: ${{ steps.deploy-comment.outputs.amalthea}}
amalthea-sessions: ${{ steps.deploy-comment.outputs.amalthea-sessions}}
test-enabled: ${{ steps.deploy-comment.outputs.test-enabled}}
extra-values: ${{ steps.deploy-comment.outputs.extra-values}}
steps:
Expand Down Expand Up @@ -90,6 +91,7 @@ jobs:
renku_notebooks: "${{ needs.check-deploy.outputs.renku-notebooks }}"
renku_data_services: "${{ needs.check-deploy.outputs.renku-data-services }}"
amalthea: "${{ needs.check-deploy.outputs.amalthea }}"
amalthea_sessions: "${{ needs.check-deploy.outputs.amalthea-sessions }}"
extra_values: "${{ needs.check-deploy.outputs.extra-values }}"

selenium-acceptance-tests:
Expand Down
51 changes: 25 additions & 26 deletions client/src/components/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

import React, { useEffect } from "react";
import React, { ReactNode, useEffect } from "react";
import {
Button,
Modal,
Expand All @@ -42,9 +42,9 @@ import {
} from "../utils/helpers/HelperFunctions";
import { Loader } from "./Loader";

import "./Logs.css";
import { ArrowRepeat, FileEarmarkArrowDown } from "react-bootstrap-icons";
import cx from "classnames";
import { ArrowRepeat, FileEarmarkArrowDown } from "react-bootstrap-icons";
import "./Logs.css";

export interface ILogs {
data: Record<string, string>;
Expand Down Expand Up @@ -335,13 +335,27 @@ const EnvironmentLogs = ({ name, annotations }: EnvironmentLogsProps) => {
);
};

const cleanAnnotations = NotebooksHelper.cleanAnnotations(
annotations
) as NotebookAnnotations;

const modalTitle = !cleanAnnotations.renkuVersion && (
<div className="fs-5 fw-normal">
<small>
{cleanAnnotations["namespace"]}/{cleanAnnotations["projectName"]} [
{cleanAnnotations["branch"]}@
{cleanAnnotations["commit-sha"].substring(0, 8)}]
</small>
</div>
);

return (
<EnvironmentLogsPresent
fetchLogs={fetchLogs}
toggleLogs={toggleLogs}
logs={logs}
name={name}
annotations={annotations}
title={modalTitle}
/>
);
};
Expand All @@ -353,38 +367,24 @@ const EnvironmentLogs = ({ name, annotations }: EnvironmentLogsProps) => {
* @param {function} toggleLogs - toggle logs visibility and fetch logs on show
* @param {object} logs - log object from redux store enhanced with `show` property
* @param {string} name - server name
* @param {object} annotations - list of annotations
* @param {ReactNode | string} title - modal title
*/
interface EnvironmentLogsPresentProps {
annotations: Record<string, unknown>;
title: ReactNode | string;
fetchLogs: IFetchableLogs["fetchLogs"];
logs?: ILogs;
name: string;
toggleLogs: (name: string) => unknown;
}
const EnvironmentLogsPresent = ({
function EnvironmentLogsPresent({
logs,
name,
toggleLogs,
fetchLogs,
annotations,
}: EnvironmentLogsPresentProps) => {
title,
}: EnvironmentLogsPresentProps) {
if (!logs?.show || logs?.show !== name || !logs) return null;

const cleanAnnotations = NotebooksHelper.cleanAnnotations(
annotations
) as NotebookAnnotations;

const modalTitle = !cleanAnnotations.renkuVersion && (
<div className="fs-5 fw-normal">
<small>
{cleanAnnotations["namespace"]}/{cleanAnnotations["projectName"]} [
{cleanAnnotations["branch"]}@
{cleanAnnotations["commit-sha"].substring(0, 8)}]
</small>
</div>
);

return (
<Modal
isOpen={!!logs.show}
Expand All @@ -400,8 +400,7 @@ const EnvironmentLogsPresent = ({
toggleLogs(name);
}}
>
<div>Logs</div>
{modalTitle}
{title}
</ModalHeader>
<ModalBody>
<div className="mx-2">
Expand All @@ -410,6 +409,6 @@ const EnvironmentLogsPresent = ({
</ModalBody>
</Modal>
);
};
}

export { EnvironmentLogs, EnvironmentLogsPresent, SessionLogs };
57 changes: 57 additions & 0 deletions client/src/components/LogsV2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*!
* Copyright 2024 - Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { displaySlice } from "../features/display";
import useAppDispatch from "../utils/customHooks/useAppDispatch.hook";
import useAppSelector from "../utils/customHooks/useAppSelector.hook";
import { useGetSessionLogsV2 } from "../utils/customHooks/UseGetSessionLogs";
import { EnvironmentLogsPresent } from "./Logs";

/**
* Sessions logs container integrating state and actions V2
*
* @param {string} name - server name
*/
interface EnvironmentLogsPropsV2 {
name: string;
}
export default function EnvironmentLogsV2({ name }: EnvironmentLogsPropsV2) {
const displayModal = useAppSelector(
({ display }) => display.modals.sessionLogs
);
const { logs, fetchLogs } = useGetSessionLogsV2(
displayModal.targetServer,
displayModal.show
);
const dispatch = useAppDispatch();
const toggleLogs = function (target: string) {
dispatch(
displaySlice.actions.toggleSessionLogsModal({ targetServer: target })
);
};

return (
<EnvironmentLogsPresent
fetchLogs={fetchLogs}
toggleLogs={toggleLogs}
logs={logs}
name={name}
title="Logs"
/>
);
}
12 changes: 4 additions & 8 deletions client/src/features/admin/AddSessionEnvironmentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ function AddSessionEnvironmentModal({
addSessionEnvironment({
container_image: data.container_image,
name: data.name,
default_url: data.default_url.trim() ? data.default_url : undefined,
description: data.description.trim() ? data.description : undefined,
default_url: data.default_url?.trim() || undefined,
description: data.description?.trim() || undefined,
port: data.port ?? undefined,
working_directory: data.working_directory.trim()
? data.working_directory
: undefined,
mount_directory: data.mount_directory.trim()
? data.mount_directory
: undefined,
working_directory: data.working_directory?.trim() || undefined,
mount_directory: data.mount_directory?.trim() || undefined,
uid: data.uid ?? undefined,
gid: data.gid ?? undefined,
command: commandParsed.data,
Expand Down
12 changes: 4 additions & 8 deletions client/src/features/admin/UpdateSessionEnvironmentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,11 @@ function UpdateSessionEnvironmentModal({
environmentId: environment.id,
container_image: data.container_image,
name: data.name,
default_url: data.default_url.trim() ? data.default_url : "",
description: data.description.trim() ? data.description : "",
default_url: data.default_url?.trim() ? data.default_url : "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the comment on AddSessionEnvironmentButton:

function trimmedOrEmpty(value: string | undefined) {
    return value?.trim() ? value.trim() : "";
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this can be done here as well:

Suggested change
default_url: data.default_url?.trim() ? data.default_url : "",
default_url: data.default_url?.trim() || "",

description: data.description?.trim() ? data.description : "",
port: data.port ?? undefined,
working_directory: data.working_directory.trim()
? data.working_directory
: undefined,
mount_directory: data.mount_directory.trim()
? data.mount_directory
: undefined,
working_directory: data.working_directory?.trim() || undefined,
mount_directory: data.mount_directory?.trim() || undefined,
uid: data.uid ?? undefined,
gid: data.gid ?? undefined,
command: commandParsed.data,
Expand Down
8 changes: 2 additions & 6 deletions client/src/features/admin/adminSessions.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ export function getSessionEnvironmentValues(environment: SessionEnvironment) {
description: environment.description,
name: environment.name,
port: environment.port ?? undefined,
working_directory: environment.working_directory?.trim()
? environment.working_directory
: undefined,
mount_directory: environment.mount_directory?.trim()
? environment.mount_directory
: undefined,
working_directory: environment.working_directory?.trim() || undefined,
mount_directory: environment.mount_directory?.trim() || undefined,
uid: environment.uid ?? undefined,
gid: environment.gid ?? undefined,
command: getJSONStringArray(environment.command),
Expand Down
92 changes: 48 additions & 44 deletions client/src/features/dashboardV2/DashboardV2Sessions.tsx
Original file line number Diff line number Diff line change
@@ -1,84 +1,91 @@
import { skipToken } from "@reduxjs/toolkit/query";
import { SerializedError } from "@reduxjs/toolkit";
import { FetchBaseQueryError, skipToken } from "@reduxjs/toolkit/query";
import cx from "classnames";
import { useMemo } from "react";
import { Link, generatePath } from "react-router-dom-v5-compat";
import { Col, ListGroup, Row } from "reactstrap";

import { Loader } from "../../components/Loader";
import { EnvironmentLogs } from "../../components/Logs";
import EnvironmentLogsV2 from "../../components/LogsV2";
import { RtkErrorAlert } from "../../components/errors/RtkErrorAlert";
import { NotebooksHelper } from "../../notebooks";
import { NotebookAnnotations } from "../../notebooks/components/session.types";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../../features/sessionsV2/sessionsV2.api";
import "../../notebooks/Notebooks.css";
import { ABSOLUTE_ROUTES } from "../../routing/routes.constants";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the CSS imports as the last ones? They semantically different from the other ones, so we should make them stand out. Also keep the associated comment.

import useAppSelector from "../../utils/customHooks/useAppSelector.hook";
import { useGetProjectsByProjectIdQuery } from "../projectsV2/api/projectV2.enhanced-api";
import { useGetSessionsQuery } from "../session/sessions.api";
import { Session } from "../session/sessions.types";
import { filterSessionsWithCleanedAnnotations } from "../session/sessions.utils";
import ActiveSessionButton from "../sessionsV2/components/SessionButton/ActiveSessionButton";
import {
SessionStatusV2Description,
SessionStatusV2Label,
} from "../sessionsV2/components/SessionStatus/SessionStatus";

// Required for logs formatting
import "../../notebooks/Notebooks.css";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this comment here? Otherwise there is no indication that removing the .css import would break something.

import { SessionList, SessionV2 } from "../sessionsV2/sessionsV2.types";

export default function DashboardV2Sessions() {
const { data: sessions, error, isLoading } = useGetSessionsQuery();
const { data: sessions, error, isLoading } = useGetSessionsQueryV2();

const v2Sessions = useMemo(
() =>
sessions != null
? filterSessionsWithCleanedAnnotations<NotebookAnnotations>(
sessions,
({ annotations }) => annotations["renkuVersion"] === "2.0"
)
: {},
[sessions]
);
if (isLoading) {
return <LoadingState />;
}

if (error) {
return <ErrorState error={error} />;
}

if (!sessions || sessions.length === 0) {
return <NoSessionsState />;
}

return <SessionDashboardList sessions={sessions} />;
}

const noSessions = isLoading ? (
function LoadingState() {
return (
<div className={cx("d-flex", "flex-column", "mx-auto")}>
<Loader />
<p className={cx("mx-auto", "my-3")}>Retrieving sessions...</p>
</div>
) : error ? (
);
}

function ErrorState({
error,
}: {
error: FetchBaseQueryError | SerializedError | undefined;
}) {
return (
<div>
<p>Cannot show sessions.</p>
<RtkErrorAlert error={error} />
</div>
) : !sessions ||
(Object.keys(sessions).length == 0 &&
Object.keys(v2Sessions).length == 0) ? (
<div>No running sessions.</div>
) : null;
);
}

if (noSessions) return <div>{noSessions}</div>;
function NoSessionsState() {
return <div>No running sessions.</div>;
}

function SessionDashboardList({
sessions,
}: {
sessions: SessionList | undefined;
}) {
return (
<ListGroup flush data-cy="dashboard-session-list">
{Object.entries(v2Sessions).map(([key, session]) => (
<DashboardSession key={key} session={session} />
{sessions?.map((session) => (
<DashboardSession key={session.name} session={session} />
))}
</ListGroup>
);
}

interface DashboardSessionProps {
session: Session;
session: SessionV2;
}
function DashboardSession({ session }: DashboardSessionProps) {
const displayModal = useAppSelector(
({ display }) => display.modals.sessionLogs
);
const { image } = session;
const annotations = NotebooksHelper.cleanAnnotations(
session.annotations
) as NotebookAnnotations;
const projectId = annotations.projectId;
const { image, project_id: projectId } = session;
const { data: project } = useGetProjectsByProjectIdQuery(
projectId ? { projectId: projectId } : skipToken
projectId ? { projectId } : skipToken
);

const projectUrl = project
Expand Down Expand Up @@ -147,10 +154,7 @@ function DashboardSession({ session }: DashboardSessionProps) {
</Row>
</Col>
</Row>
<EnvironmentLogs
name={displayModal.targetServer}
annotations={annotations}
/>
<EnvironmentLogsV2 name={displayModal.targetServer} />
</Link>
);
}
2 changes: 1 addition & 1 deletion client/src/features/session/components/SessionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ function ModifySessionModalContent({
<Col>
{message}
<p>
<span className="fw-bold me-3">Current resources:</span>
<span className={cx("fw-bold", "me-3")}>Current resources:</span>
<span>
<SessionRowResourceRequests
resourceRequests={resources.requests}
Expand Down
Loading
Loading