fix: avoid missed logs when streaming startup logs (#8029)

* feat(coderd,agent): send startup log eof at the end

* fix(coderd): fix edge case in startup log pubsub

* fix(coderd): ensure startup logs are closed on lifecycle state change (fallback)

* fix(codersdk): fix startup log channel shared memory bug

* fix(site): remove the EOF log line
This commit is contained in:
Mathias Fredriksson
2023-06-16 17:14:22 +03:00
committed by GitHub
parent 247f8a973f
commit 0c5077464b
28 changed files with 660 additions and 133 deletions

View File

@ -27,6 +27,7 @@ import (
"github.com/coder/coder/coderd/util/ptr"
"github.com/coder/coder/coderd/wsbuilder"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/codersdk/agentsdk"
)
var (
@ -1178,3 +1179,14 @@ func (api *API) publishWorkspaceUpdate(ctx context.Context, workspaceID uuid.UUI
slog.F("workspace_id", workspaceID), slog.Error(err))
}
}
func (api *API) publishWorkspaceAgentStartupLogsUpdate(ctx context.Context, workspaceAgentID uuid.UUID, m agentsdk.StartupLogsNotifyMessage) {
b, err := json.Marshal(m)
if err != nil {
api.Logger.Warn(ctx, "failed to marshal startup logs notify message", slog.F("workspace_agent_id", workspaceAgentID), slog.Error(err))
}
err = api.Pubsub.Publish(agentsdk.StartupLogsNotifyChannel(workspaceAgentID), b)
if err != nil {
api.Logger.Warn(ctx, "failed to publish workspace agent startup logs update", slog.F("workspace_agent_id", workspaceAgentID), slog.Error(err))
}
}