feat: log long-lived connections acceptance (#17219)

Closes #16904
This commit is contained in:
Michael Suchacz
2025-04-08 08:30:05 +00:00
committed by GitHub
parent abe3ad68f5
commit ce22de8d15
9 changed files with 351 additions and 24 deletions
+9
View File
@@ -555,6 +555,9 @@ func (api *API) workspaceAgentLogs(rw http.ResponseWriter, r *http.Request) {
t := time.NewTicker(recheckInterval)
defer t.Stop()
// Log the request immediately instead of after it completes.
httpmw.RequestLoggerFromContext(ctx).WriteLog(ctx, http.StatusAccepted)
go func() {
defer func() {
logger.Debug(ctx, "end log streaming loop")
@@ -928,6 +931,9 @@ func (api *API) derpMapUpdates(rw http.ResponseWriter, r *http.Request) {
encoder := wsjson.NewEncoder[*tailcfg.DERPMap](ws, websocket.MessageBinary)
defer encoder.Close(websocket.StatusGoingAway)
// Log the request immediately instead of after it completes.
httpmw.RequestLoggerFromContext(ctx).WriteLog(ctx, http.StatusAccepted)
go func(ctx context.Context) {
// TODO(mafredri): Is this too frequent? Use separate ping disconnect timeout?
t := time.NewTicker(api.AgentConnectionUpdateFrequency)
@@ -1315,6 +1321,9 @@ func (api *API) watchWorkspaceAgentMetadata(
sendTicker := time.NewTicker(sendInterval)
defer sendTicker.Stop()
// Log the request immediately instead of after it completes.
httpmw.RequestLoggerFromContext(ctx).WriteLog(ctx, http.StatusAccepted)
// Send initial metadata.
sendMetadata()