Skip to content

fix: let workspace pages download partial logs for unhealthy workspaces #13761

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

Merged
merged 19 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix: allow partial downloading of logs
  • Loading branch information
Parkreiner committed Jul 2, 2024
commit 87f57aa970b1ae3e993982f4274f7943407fca8b
6 changes: 3 additions & 3 deletions site/src/api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ export const getValidationErrorMessage = (error: unknown): string => {
return validationErrors.map((error) => error.detail).join("\n");
};

export const getErrorDetail = (error: unknown): string | undefined | null => {
export const getErrorDetail = (error: unknown): string | null => {
if (error instanceof Error) {
return "Please check the developer console for more details.";
}
if (isApiError(error)) {
return error.response.data.detail;
return error.response.data.detail ?? null;
}
if (isApiErrorResponse(error)) {
return error.detail;
return error.detail ?? null;
}
return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "components/Dialogs/ConfirmDialog/ConfirmDialog";
import { displayError } from "components/GlobalSnackbar/utils";
import { Stack } from "components/Stack/Stack";
import { ErrorAlert } from "components/Alert/ErrorAlert";

const BLOB_SIZE_UNITS = ["B", "KB", "MB", "GB", "TB"] as const;

Expand Down Expand Up @@ -76,9 +77,7 @@ export const DownloadLogsDialog: FC<DownloadLogsDialogProps> = ({
return files;
}, [agentLogResults, agents, buildLogsQuery.data, workspace.name]);
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a problem with the previous logic: because agents was getting redefined every render, we were also invalidating the useMemo dependency array every render


const isLoadingFiles = downloadableFiles.some((f) => f.blob === undefined);
const [isDownloading, setIsDownloading] = useState(false);

const timeoutIdRef = useRef<number | undefined>(undefined);
useEffect(() => {
const clearTimeoutOnUnmount = () => {
Expand All @@ -88,24 +87,37 @@ export const DownloadLogsDialog: FC<DownloadLogsDialogProps> = ({
return clearTimeoutOnUnmount;
}, []);

const isWorkspaceHealthy = workspace.health.healthy;
const isLoadingFiles = downloadableFiles.some((f) => f.blob === undefined);

return (
<ConfirmDialog
{...dialogProps}
hideCancel={false}
title="Download logs"
confirmText="Download"
disabled={isLoadingFiles}
confirmLoading={isDownloading}
confirmText={
<>
Download
{!isWorkspaceHealthy && <> {isLoadingFiles ? "partial" : "all"}</>}
</>
}
disabled={
isDownloading ||
// If a workspace isn't healthy, let the user download as many logs as
// they can
(isWorkspaceHealthy && isLoadingFiles)
}
onConfirm={async () => {
try {
setIsDownloading(true);
const zip = new JSZip();
downloadableFiles.forEach((f) => {
if (f.blob) {
zip.file(f.name, f.blob);
}
});
setIsDownloading(true);
const zip = new JSZip();
downloadableFiles.forEach((f) => {
if (f.blob) {
zip.file(f.name, f.blob);
}
});

try {
const content = await zip.generateAsync({ type: "blob" });
download(content, `${workspace.name}-logs.zip`);
dialogProps.onClose();
Expand All @@ -125,6 +137,16 @@ export const DownloadLogsDialog: FC<DownloadLogsDialogProps> = ({
Downloading logs will create a zip file containing all logs from all
jobs in this workspace. This may take a while.
</p>

{!isWorkspaceHealthy && isLoadingFiles && (
<>
<ErrorAlert
error="Your workspace is not healthy. Some logs may not be available, but
you can still download any that are."
/>
</>
)}

<ul css={styles.list}>
{downloadableFiles.map((f) => (
<li key={f.name} css={styles.listItem}>
Expand Down