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

Method connectRPCVersion

codersdk/agentsdk/agentsdk.go:356–398  ·  view source on GitHub ↗
(ctx context.Context, version *apiversion.APIVersion, role string)

Source from the content-addressed store, hash-verified

354}
355
356func (c *Client) connectRPCVersion(ctx context.Context, version *apiversion.APIVersion, role string) (drpc.Conn, error) {
357 rpcURL, err := c.SDK.URL.Parse("/api/v2/workspaceagents/me/rpc")
358 if err != nil {
359 return nil, xerrors.Errorf("parse url: %w", err)
360 }
361 q := rpcURL.Query()
362 q.Add("version", version.String())
363 if role != "" {
364 q.Add("role", role)
365 }
366 rpcURL.RawQuery = q.Encode()
367
368 httpClient := &http.Client{
369 Transport: c.SDK.HTTPClient.Transport,
370 }
371 // nolint:bodyclose
372 conn, res, err := websocket.Dial(ctx, rpcURL.String(), &websocket.DialOptions{
373 HTTPClient: httpClient,
374 HTTPHeader: http.Header{
375 codersdk.SessionTokenHeader: []string{c.SDK.SessionToken()},
376 },
377 })
378 if err != nil {
379 if res == nil {
380 return nil, err
381 }
382 return nil, codersdk.ReadBodyAsError(res)
383 }
384
385 // Set the read limit to 4 MiB -- about the limit for protobufs. This needs to be larger than
386 // the default because some of our protocols can include large messages like startup scripts.
387 conn.SetReadLimit(1 << 22)
388 netConn := websocket.NetConn(ctx, conn, websocket.MessageBinary)
389
390 config := yamux.DefaultConfig()
391 config.LogOutput = nil
392 config.Logger = slog.Stdlib(ctx, c.SDK.Logger(), slog.LevelInfo)
393 session, err := yamux.Client(netConn, config)
394 if err != nil {
395 return nil, xerrors.Errorf("multiplex client: %w", err)
396 }
397 return drpcsdk.MultiplexedConn(session), nil
398}
399
400type PostAppHealthsRequest struct {
401 // Healths is a map of the workspace app name and the health of the app.

Callers 15

ConnectRPC20Method · 0.95
ConnectRPC21Method · 0.95
ConnectRPC22Method · 0.95
ConnectRPC23Method · 0.95
ConnectRPC24Method · 0.95
ConnectRPC25Method · 0.95
ConnectRPC26Method · 0.95
ConnectRPC27Method · 0.95
ConnectRPC28Method · 0.95
ConnectRPC28WithRoleMethod · 0.95

Calls 11

ReadBodyAsErrorFunction · 0.92
MultiplexedConnFunction · 0.92
EncodeMethod · 0.80
ClientMethod · 0.80
ParseMethod · 0.65
AddMethod · 0.65
DialMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45
SessionTokenMethod · 0.45
LoggerMethod · 0.45

Tested by

no test coverage detected