Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(site): add download logs option#13466

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 27 commits intomainfrombq/download-logs
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
27 commits
Select commitHold shift + click to select a range
051217a
Download agent logs
BrunoQuaresmaJun 3, 2024
c9af899
Download workspace logs
BrunoQuaresmaJun 3, 2024
e479cf2
Use Logs instead of Agent Logs
BrunoQuaresmaJun 3, 2024
9ccc9e1
Centralize items list
BrunoQuaresmaJun 3, 2024
128f938
Init files with build logs
BrunoQuaresmaJun 3, 2024
4d5c9cb
Add tests for the download logs dialog
BrunoQuaresmaJun 4, 2024
11b528a
Add test to verify if download dialog is opening
BrunoQuaresmaJun 4, 2024
efcee2b
Add tests to download agent logs
BrunoQuaresmaJun 4, 2024
895e942
Fix package.json
BrunoQuaresmaJun 4, 2024
9ee7fd4
Commit Asher suggestions
BrunoQuaresmaJun 4, 2024
a71529a
Fix open download logs story
BrunoQuaresmaJun 5, 2024
f82a4e4
Fix dropdown arrow on light theme
BrunoQuaresmaJun 5, 2024
967fc0b
Enable agent logs only when showing
BrunoQuaresmaJun 5, 2024
73af195
Use web socket decorator and remove specific props for storybook
BrunoQuaresmaJun 5, 2024
f145ead
Refactor useAgentLogs to optimize loading
BrunoQuaresmaJun 5, 2024
5baa052
Add prefetch back
BrunoQuaresmaJun 5, 2024
40d2a65
Only fetch logs when clicking on download
BrunoQuaresmaJun 5, 2024
35368ee
Add useAgentLogs test
BrunoQuaresmaJun 5, 2024
10b4b71
Use Michael refactoring of useAgentLogs
BrunoQuaresmaJun 6, 2024
8da2d28
Improve naming
BrunoQuaresmaJun 6, 2024
b54c72c
Improve naming
BrunoQuaresmaJun 6, 2024
83f60dd
Fix hook usage
BrunoQuaresmaJun 6, 2024
6f85490
allow pkg
sreyaJun 6, 2024
270e04e
Rollback useAgentLogs implementation
BrunoQuaresmaJun 6, 2024
a6ab9fd
Add decorators to fix storybook
BrunoQuaresmaJun 6, 2024
c1f281c
Merge branch 'bq/download-logs' of https://github.com/coder/coder int…
BrunoQuaresmaJun 6, 2024
fab7d56
Apply Asher suggestions
BrunoQuaresmaJun 7, 2024
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: 1 addition & 1 deletion.github/workflows/ci.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -922,7 +922,7 @@ jobs:
uses: actions/dependency-review-action@v4.3.2
with:
allow-licenses: Apache-2.0, BSD-2-Clause, BSD-3-Clause, CC0-1.0, ISC, MIT, MIT-0, MPL-2.0
allow-dependencies-licenses: "pkg:golang/github.com/coder/wgtunnel@0.1.13-0.20240522110300-ade90dfb2da0"
allow-dependencies-licenses: "pkg:golang/github.com/coder/wgtunnel@0.1.13-0.20240522110300-ade90dfb2da0, pkg:npm/pako@1.0.11"
license-check: true
vulnerability-check: false
- name: "Report"
Expand Down
3 changes: 3 additions & 0 deletionssite/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,7 @@
"@mui/system": "5.14.0",
"@mui/utils": "5.14.11",
"@tanstack/react-query-devtools": "4.35.3",
"@types/file-saver": "2.0.7",
"ansi-to-html": "0.7.2",
"axios": "1.6.0",
"canvas": "2.11.0",
Expand All@@ -58,8 +59,10 @@
"date-fns": "2.30.0",
"dayjs": "1.11.4",
"emoji-mart": "5.4.0",
"file-saver": "2.0.5",
"formik": "2.4.1",
"front-matter": "4.0.2",
"jszip": "3.10.1",
"lodash": "4.17.21",
"monaco-editor": "0.44.0",
"pretty-bytes": "6.1.0",
Expand Down
50 changes: 44 additions & 6 deletionssite/pnpm-lock.yaml
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 1 addition & 2 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1142,10 +1142,9 @@ class ApiMethods {

getWorkspaceBuildLogs = async (
buildId: string,
before: Date,
): Promise<TypesGen.ProvisionerJobLog[]> => {
const response = await this.axios.get<TypesGen.ProvisionerJobLog[]>(
`/api/v2/workspacebuilds/${buildId}/logs?before=${before.getTime()}`,
`/api/v2/workspacebuilds/${buildId}/logs`,
);

return response.data;
Expand Down
4 changes: 2 additions & 2 deletionssite/src/api/queries/util.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { UseQueryOptions, QueryKey } from "react-query";
import type { MetadataState, MetadataValue } from "hooks/useEmbeddedMetadata";

constdisabledFetchOptions = {
exportconstdisabledRefetchOptions = {
cacheTime: Infinity,
staleTime: Infinity,
refetchOnMount: false,
Expand DownExpand Up@@ -62,7 +62,7 @@ export function cachedQuery<

// Make sure the disabled options are always serialized last, so that no
// one using this function can accidentally override the values
...(metadata.available ?disabledFetchOptions : {}),
...(metadata.available ?disabledRefetchOptions : {}),
};

return newOptions as FormattedQueryOptionsResult<
Expand Down
30 changes: 30 additions & 0 deletionssite/src/api/queries/workspaces.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ import type {
WorkspacesRequest,
WorkspacesResponse,
} from "api/typesGenerated";
import { disabledRefetchOptions } from "./util";
import { workspaceBuildsKey } from "./workspaceBuilds";

export const workspaceByOwnerAndNameKey = (owner: string, name: string) => [
Expand DownExpand Up@@ -283,3 +284,32 @@ export const toggleFavorite = (
},
};
};

export const buildLogsKey = (workspaceId: string) => [
"workspaces",
workspaceId,
"logs",
];

export const buildLogs = (workspace: Workspace) => {
return {
queryKey: buildLogsKey(workspace.id),
queryFn: () => API.getWorkspaceBuildLogs(workspace.latest_build.id),
};
};

export const agentLogsKey = (workspaceId: string, agentId: string) => [
"workspaces",
workspaceId,
"agents",
agentId,
"logs",
];

export const agentLogs = (workspaceId: string, agentId: string) => {
return {
queryKey: agentLogsKey(workspaceId, agentId),
queryFn: () => API.getWorkspaceAgentLogs(agentId),
...disabledRefetchOptions,
};
};
6 changes: 3 additions & 3 deletionssite/src/components/DropdownArrow/DropdownArrow.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,11 +26,11 @@ export const DropdownArrow: FC<ArrowProps> = ({
};

const styles = {
base:(theme) => ({
color:theme.palette.primary.contrastText,
base: {
color:"currentcolor",
width: 16,
height: 16,
}),
},

withMargin: {
marginLeft: 8,
Expand Down
67 changes: 1 addition & 66 deletionssite/src/modules/resources/AgentLogs/AgentLogs.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
import type { Interpolation, Theme } from "@emotion/react";
import Tooltip from "@mui/material/Tooltip";
import {
type ComponentProps,
forwardRef,
useEffect,
useMemo,
useState,
} from "react";
import { type ComponentProps, forwardRef, useMemo } from "react";
import { FixedSizeList as List } from "react-window";
import { watchWorkspaceAgentLogs } from "api/api";
import type { WorkspaceAgentLogSource } from "api/typesGenerated";
import {
AGENT_LOG_LINE_HEIGHT,
Expand DownExpand Up@@ -179,64 +172,6 @@ export const AgentLogs = forwardRef<List, AgentLogsProps>(
},
);

export const useAgentLogs = (
agentId: string,
options?: { enabled?: boolean; initialData?: LineWithID[] },
) => {
const initialData = options?.initialData;
const enabled = options?.enabled === undefined ? true : options.enabled;
const [logs, setLogs] = useState<LineWithID[] | undefined>(initialData);

useEffect(() => {
if (!enabled) {
setLogs([]);
return;
}

const socket = watchWorkspaceAgentLogs(agentId, {
// Get all logs
after: 0,
onMessage: (logs) => {
// Prevent new logs getting added when a connection is not open
if (socket.readyState !== WebSocket.OPEN) {
return;
}

setLogs((previousLogs) => {
const newLogs: LineWithID[] = logs.map((log) => ({
id: log.id,
level: log.level || "info",
output: log.output,
time: log.created_at,
sourceId: log.source_id,
}));

if (!previousLogs) {
return newLogs;
}

return [...previousLogs, ...newLogs];
});
},
onError: (error) => {
// For some reason Firefox and Safari throw an error when a websocket
// connection is close in the middle of a message and because of that we
// can't safely show to the users an error message since most of the
// time they are just internal stuff. This does not happen to Chrome at
// all and I tried to find better way to "soft close" a WS connection on
// those browsers without success.
console.error(error);
},
});

return () => {
socket.close();
};
}, [agentId, enabled]);

return logs;
};

// These colors were picked at random. Feel free
// to add more, adjust, or change! Users will not
// depend on these colors.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp