-
Notifications
You must be signed in to change notification settings - Fork 927
fix(coderd): allow workspaceAgentLogs
follow to return on non-latest-build
#9382
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
fix(coderd): allow workspaceAgentLogs
follow to return on non-latest-build
#9382
Conversation
coderd/workspaceagents_test.go
Outdated
version2, err := client.CreateTemplateVersion(ctx, user.OrganizationID, codersdk.CreateTemplateVersionRequest{ | ||
TemplateID: template.ID, | ||
Name: "version2", | ||
StorageMethod: codersdk.ProvisionerStorageMethodFile, | ||
FileID: version.Job.FileID, | ||
Provisioner: codersdk.ProvisionerTypeEcho, | ||
}) | ||
require.NoError(t, err) | ||
coderdtest.AwaitTemplateVersionJob(t, client, version2.ID) | ||
|
||
_ = coderdtest.CreateWorkspaceBuild(t, client, workspace, database.WorkspaceTransitionStart, func(req *codersdk.CreateWorkspaceBuildRequest) { | ||
req.TemplateVersionID = version2.ID | ||
}) |
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.
Shouldn't need to change the template version for this test, a new build should suffice right?
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.
True! I was missing the patch log to trigger the recheck before, which is why I added it (but not needed).
} | ||
// If the agent is no longer in the latest build, we can stop after | ||
// checking once. | ||
keepGoing = slices.ContainsFunc(agents, func(agent database.WorkspaceAgent) bool { return agent.ID == workspaceAgent.ID }) |
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.
Why use a bool instead of just break
ing or return
ing?
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.
So that we do one last fetch of the logs, in case something arrived between last check and new build.
@@ -565,6 +576,18 @@ func (api *API) workspaceAgentLogs(rw http.ResponseWriter, r *http.Request) { | |||
t.Reset(recheckInterval) | |||
} | |||
|
|||
agents, err := api.Database.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, workspace.ID) |
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.
What happens if the user wants to view logs for an old agent intentionally? I don't think we have any mechanism in the UI for this right now so it's probably fine to leave it like this
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.
It should just work, in this scenario essentially we (assuming ?follow=true
):
- Fetch all logs in the first call to
GetWorkspaceAgentLogsAfter
(before websocket upgrade) - Websocket & write logs
- Subscribe to db
- Enter loop for buffered logs
- keepGoing turns to false (non-latest build)
- Check
GetWorkspaceAgentLogsAfter
one last time -> empty - Return
No description provided.