MCPcopy Create free account
hub / github.com/coder/coder / watchWorkspaceUpdates

Method watchWorkspaceUpdates

scaletest/taskstatus/run.go:158–209  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

156}
157
158func (r *Runner) watchWorkspaceUpdates(ctx context.Context) error {
159 shouldMarkConnectedDone := true
160 defer func() {
161 if shouldMarkConnectedDone {
162 r.cfg.ConnectedWaitGroup.Done()
163 }
164 }()
165 updates, err := r.client.watchWorkspace(ctx, r.workspaceID)
166 if err != nil {
167 return xerrors.Errorf("watch workspace: %w", err)
168 }
169 shouldMarkConnectedDone = false
170 r.cfg.ConnectedWaitGroup.Done()
171 defer func() {
172 r.mu.Lock()
173 defer r.mu.Unlock()
174 r.cfg.Metrics.MissingStatusUpdatesTotal.
175 WithLabelValues(r.cfg.MetricLabelValues...).
176 Add(float64(len(r.reportTimes)))
177 }()
178 for {
179 select {
180 case <-ctx.Done():
181 return ctx.Err()
182 case workspace := <-updates:
183 if workspace.LatestAppStatus == nil {
184 continue
185 }
186 msgNo, ok := parseStatusMessage(workspace.LatestAppStatus.Message)
187 if !ok {
188 continue
189 }
190
191 r.mu.Lock()
192 reportTime, ok := r.reportTimes[msgNo]
193 delete(r.reportTimes, msgNo)
194 allDone := r.doneReporting && len(r.reportTimes) == 0
195 r.mu.Unlock()
196
197 if !ok {
198 return xerrors.Errorf("report time not found for message %d", msgNo)
199 }
200 latency := r.clock.Since(reportTime, "watchWorkspaceUpdates")
201 r.cfg.Metrics.TaskStatusToWorkspaceUpdateLatencySeconds.
202 WithLabelValues(r.cfg.MetricLabelValues...).
203 Observe(latency.Seconds())
204 if allDone {
205 return nil
206 }
207 }
208 }
209}
210
211func (r *Runner) reportTaskStatus(ctx context.Context) error {
212 defer func() {

Callers 1

RunMethod · 0.95

Calls 9

parseStatusMessageFunction · 0.85
WithLabelValuesMethod · 0.80
ErrMethod · 0.80
watchWorkspaceMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.45
ErrorfMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected