(ctx context.Context, logger slog.Logger)
| 518 | } |
| 519 | |
| 520 | func (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 |
nothing calls this directly
no test coverage detected