Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Conversation

mafredri
Copy link
Member

No description provided.

Comment on lines 312 to 324
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
})
Copy link
Member

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?

Copy link
Member Author

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 })
Copy link
Member

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 breaking or returning?

Copy link
Member Author

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)
Copy link
Member

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

Copy link
Member Author

@mafredri mafredri Aug 28, 2023

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):

  1. Fetch all logs in the first call to GetWorkspaceAgentLogsAfter (before websocket upgrade)
  2. Websocket & write logs
  3. Subscribe to db
  4. Enter loop for buffered logs
  5. keepGoing turns to false (non-latest build)
  6. Check GetWorkspaceAgentLogsAfter one last time -> empty
  7. Return

@mafredri mafredri enabled auto-merge (squash) August 28, 2023 18:05
@mafredri mafredri merged commit 487bdc2 into main Aug 28, 2023
@mafredri mafredri deleted the mafredri/fix-coderd-allow-workspace-agent-logs-to-return-on-non-latest-build branch August 28, 2023 19:46
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants