MCPcopy Index your code
hub / github.com/coder/coder / WatchContainers

Method WatchContainers

codersdk/workspacesdk/agentconn.go:520–552  ·  view source on GitHub ↗
(ctx context.Context, logger slog.Logger)

Source from the content-addressed store, hash-verified

518}
519
520func (c *agentConn) WatchContainers(ctx context.Context, logger slog.Logger) (<-chan codersdk.WorkspaceAgentListContainersResponse, io.Closer, error) {
521 ctx, span := tracing.StartSpan(ctx)
522 defer span.End()
523
524 host := net.JoinHostPort(c.agentAddress().String(), strconv.Itoa(AgentHTTPAPIServerPort))
525 url := fmt.Sprintf("http://%s%s", host, "/api/v0/containers/watch")
526
527 conn, res, err := websocket.Dial(ctx, url, &websocket.DialOptions{
528 HTTPClient: c.apiClient(),
529
530 // We want `NoContextTakeover` compression to balance improving
531 // bandwidth cost/latency with minimal memory usage overhead.
532 CompressionMode: websocket.CompressionNoContextTakeover,
533 })
534 if err != nil {
535 if res == nil {
536 return nil, nil, err
537 }
538 return nil, nil, codersdk.ReadBodyAsError(res)
539 }
540 if res != nil && res.Body != nil {
541 defer res.Body.Close()
542 }
543
544 // When a workspace has a few devcontainers running, or a single devcontainer
545 // has a large amount of apps, then each payload can easily exceed 32KiB.
546 // We up the limit to 4MiB to give us plenty of headroom for workspaces that
547 // have lots of dev containers with lots of apps.
548 conn.SetReadLimit(1 << 22) // 4MiB
549
550 d := wsjson.NewDecoder[codersdk.WorkspaceAgentListContainersResponse](conn, websocket.MessageText, logger)
551 return d.Chan(), d, nil
552}
553
554// WatchGit opens a bidirectional WebSocket to the agent's git watch
555// endpoint and returns a stream for sending subscribe/refresh messages

Callers

nothing calls this directly

Calls 9

agentAddressMethod · 0.95
apiClientMethod · 0.95
StartSpanFunction · 0.92
ReadBodyAsErrorFunction · 0.92
NewDecoderFunction · 0.92
DialMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
ChanMethod · 0.45

Tested by

no test coverage detected