- Notifications
You must be signed in to change notification settings - Fork1k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Very handy!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good so far! I feel like there might be some ways to tighten upuseAgentLogs
, but I'll come back to this tomorrow morning, when I'm not so tired
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
site/src/pages/WorkspacePage/WorkspaceActions/DownloadLogsDialog.tsx OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Parkreiner commentedJun 6, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@BrunoQuaresma What do you think of this? typeUseAgentLogsOptions=Readonly<{workspaceId:string;agentId:string;agentLifeCycleState:WorkspaceAgentLifecycle;enabled?:boolean;}>;exportfunctionuseAgentLogs(options:UseAgentLogsOptions,):readonlyWorkspaceAgentLog[]|undefined{const{ workspaceId, agentId, agentLifeCycleState, enabled=true}=options;constqueryClient=useQueryClient();constqueryOptions=agentLogs(workspaceId,agentId);const{ data}=useQuery({ ...queryOptions, enabled,select:(logs)=>{return{ logs,lastLogId:logs.at(-1)?.id??0,};},});constsocketRef=useRef<WebSocket|null>(null);constlastInitializedAgentIdRef=useRef<string|null>(null);constaddLogs=useEffectEvent((newLogs:WorkspaceAgentLog[])=>{queryClient.setQueryData(queryOptions.queryKey,(oldLogs:WorkspaceAgentLog[]=[])=>[...oldLogs, ...newLogs],);});useEffect(()=>{constisSameAgentId=agentId===lastInitializedAgentIdRef.current;if(!isSameAgentId){socketRef.current?.close();}constcannotCreateSocket=agentLifeCycleState!=="starting"||data===undefined;if(cannotCreateSocket){return;}constsocket=watchWorkspaceAgentLogs(agentId,{after:data.lastLogId,onMessage:(newLogs)=>{// Prevent new logs getting added when a connection is not openif(socket.readyState===WebSocket.OPEN){addLogs(newLogs);;}},onError:(error)=>{// Might be able to put more precise error handling here?console.error(error);},});socketRef.current=socket;lastInitializedAgentIdRef.current=agentId;},[addLogs,agentId,agentLifeCycleState,data]);// The above effect is likely going to run a lot because we don't know when or// how agentLifeCycleState will change over time (it's a union of nine// values). The only way to ensure that we only close when we unmount is by// putting the logic into a separate effect with an empty dependency arrayuseEffect(()=>{constcloseSocketOnUnmount=()=>socketRef.current?.close();returncloseSocketOnUnmount;},[]);returndata?.logs;} |
Parkreiner commentedJun 6, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@BrunoQuaresma Realized one other thing: if the query for the agent logs hook is only able to run once, is it a problem if the query doesn't come back in the starting state at first? I don't know enough about lifecycle states, and I don't know if there's a flow chart for how the states can transition into each other anywhere |
Do you have a use case that could contextualize this better? |
Parkreiner commentedJun 6, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Looking at the type definition for My main worry was, if a workspace is already in the |
@Parkreiner I think I maybe answered this question here#13466 (comment) |
@Parkreiner I had to roll back to the previous |
@BrunoQuaresma Ah, right – forgot that we are mutating the cache, so the data is potentially going to be changing a lot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good! And glad you caught that infinite loop issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good to me!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Close#12485
Screen.Recording.2024-06-03.at.15.31.41.mov